Freeciv-3.3: /fast/freeciv/nightly/main/server/plrhand.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
plrhand.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdarg.h>
19
20/* utility */
21#include "bitvector.h"
22#include "fcintl.h"
23#include "log.h"
24#include "mem.h"
25#include "rand.h"
26#include "shared.h"
27#include "support.h"
28
29/* common */
30#include "citizens.h"
31#include "culture.h"
32#include "diptreaty.h"
33#include "government.h"
34#include "map.h"
35#include "movement.h"
36#include "multipliers.h"
37#include "nation.h"
38#include "packets.h"
39#include "player.h"
40#include "research.h"
41#include "rgbcolor.h"
42#include "specialist.h"
43#include "tech.h"
44#include "unitlist.h"
45
46/* common/scriptcore */
47#include "luascript_types.h"
48
49/* server */
50#include "aiiface.h"
51#include "barbarian.h"
52#include "citytools.h"
53#include "cityturn.h"
54#include "connecthand.h"
55#include "diplhand.h"
56#include "gamehand.h"
57#include "maphand.h"
58#include "mood.h"
59#include "notify.h"
60#include "plrhand.h"
61#include "sernet.h"
62#include "srv_main.h"
63#include "stdinhand.h"
64#include "spaceship.h"
65#include "spacerace.h"
66#include "techtools.h"
67#include "unittools.h"
68#include "voting.h"
69
70/* server/advisors */
71#include "advdata.h"
72
73/* server/scripting */
74#include "script_server.h"
75
76/* ai */
77#include "aitraits.h"
78#include "difficulty.h"
79#include "handicaps.h"
80
81
82struct rgbcolor;
83
84static void package_player_common(struct player *plr,
85 struct packet_player_info *packet,
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 = nullptr;
129
130 pplayer->is_alive = FALSE;
131
132 /* Reset player status */
133 player_status_reset(pplayer);
134
135 /* Remove shared vision from dead player to friends. */
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(nullptr, nullptr, E_DESTROYED, ftc_server,
165 _("The %s are no more!"),
166 nation_plural_for_player(pplayer));
167 }
168
169 /* Transfer back all cities not originally owned by player to their
170 rightful owners, if they are still around */
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 != nullptr
175 && pcity->original->is_alive) {
176 /* Transfer city to original owner, kill all its units outside of
177 a radius of 3, give verbose messages of every unit transferred,
178 and raze buildings according to raze chance (also removes palace) */
179 if (transfer_city(pcity->original, pcity, 3, TRUE, TRUE, TRUE,
180 TRUE)) {
181 script_server_signal_emit("city_transferred", pcity, pplayer,
182 pcity->original, "death-back_to_original");
183 }
184 }
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, nullptr);
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, nullptr, nullptr, FALSE);
252 }
253 if (extra_owner(ptile) == pplayer) {
254 ptile->extras_owner = nullptr;
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, nullptr);
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, nullptr, E_BAD_COMMAND, ftc_server,
294 _("Cannot change rates before game start."));
295 return;
296 }
297
298 if (tax + luxury + science != 100) {
299 return;
300 }
301 if (tax < 0 || tax > 100 || luxury < 0 || luxury > 100 || science < 0
302 || science > 100) {
303 return;
304 }
305 maxrate = get_player_maxrate(pplayer);
306 if (tax > maxrate || luxury > maxrate || science > maxrate) {
307 const char *rtype;
308
309 if (tax > maxrate) {
310 rtype = _("Tax");
311 } else if (luxury > maxrate) {
312 rtype = _("Luxury");
313 } else {
314 rtype = _("Science");
315 }
316
317 notify_player(pplayer, nullptr, E_BAD_COMMAND, ftc_server,
318 _("%s rate exceeds the max rate for %s."),
319 rtype,
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 && nullptr != 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 = nullptr;
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, nullptr, 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, nullptr, E_REVOLT_DONE, ftc_server,
384 _("The tax rates for the %s are changed from "
385 "%3d%%/%3d%%/%3d%% (tax/luxury/science) to "
386 "%3d%%/%3d%%/%3d%%."),
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, nullptr);
401}
402
403/**********************************************************************/
410 void player_loot_player(struct player *pvictor, struct player *pvictim)
411{
412 int ransom = fc_rand(1 + pvictim->economic.gold);
413 int n = 1 + fc_rand(3);
414
415 /* Give map */
416 if (give_distorted_map(pvictim, pvictor, 50, TRUE)) {
417 notify_player(pvictor, nullptr, E_HUT_MAP,
418 ftc_server,
419 _("You looted parts of %s map!"),
420 nation_adjective_for_player(pvictim));
421 }
422
423 log_debug("victim has money: %d", pvictim->economic.gold);
424
425 if (ransom > 0) {
426 notify_player(pvictor, nullptr, E_HUT_GOLD,
427 ftc_server,
428 PL_("You loot %d gold!", "You loot %d gold!", ransom),
429 ransom);
430 }
431 pvictor->economic.gold += ransom;
432 pvictim->economic.gold -= ransom;
433
434 while (n > 0) {
435 Tech_type_id ttid;
436
437 /* steal_a_tech() handles also notifying of the player */
438 ttid = steal_a_tech(pvictor, pvictim, A_UNSET);
439
440 if (ttid == A_NONE) {
441 log_debug("Worthless enemy doesn't have more techs to steal.");
442 break;
443 } else {
444 log_debug("Pressed tech %s from captured enemy",
445 research_advance_rule_name(research_get(pvictor), ttid));
446 if (!fc_rand(3)) {
447 break; /* Out of luck */
448 }
449 n--;
450 }
451 }
452
453 {
454 /* Try to submit some cities */
455 int vcsize = city_list_size(pvictim->cities);
456 int evcsize = vcsize;
457 int conqsize;
458
459 if (evcsize < 3) {
460 evcsize = 0;
461 } else {
462 evcsize -=3;
463 }
464
465 /* About a quarter on average with high numbers less probable */
466 conqsize = fc_rand(fc_rand(evcsize));
467
468 log_debug("conqsize=%d", conqsize);
469
470 if (conqsize > 0) {
471 bool palace = game.server.savepalace;
472 bool submit = FALSE;
473
474 game.server.savepalace = FALSE; /* Moving it around is dumb */
475
476 city_list_iterate_safe(pvictim->cities, pcity) {
477 /* Kindly ask the citizens to submit */
478 if (fc_rand(vcsize) < conqsize) {
479 submit = TRUE;
480 }
481 vcsize--;
482 if (submit) {
483 conqsize--;
484 /* Transfer city to the victorious player
485 * kill all its units outside of a radius of 7,
486 * give verbose messages of every unit transferred,
487 * and raze buildings according to raze chance
488 * (also removes palace) */
489 notify_player(pvictor, city_tile(pcity), E_CITY_CONQUERED,
490 ftc_server,
491 /* TRANS: Getting a city as loot */
492 _("You conquer %s as loot!"),
493 city_link(pcity));
494
495 (void) transfer_city(pvictor, pcity, 7, TRUE, TRUE, TRUE,
496 !is_barbarian(pvictor));
497 submit = FALSE;
498 }
499 if (conqsize <= 0) {
500 break;
501 }
502 } city_list_iterate_safe_end;
503 game.server.savepalace = palace;
504 }
505 }
506}
507
508/**********************************************************************/
515 static int revolentype_length(enum revolen_type rltype,
516 struct government *gov)
517{
518 int max_turns;
519 int change_speed;
520
521 switch (rltype) {
522 case REVOLEN_FIXED:
523 return game.server.revolution_length;
524 case REVOLEN_RANDOM:
525 return fc_rand(game.server.revolution_length) + 1;
526 case REVOLEN_QUICKENING:
527 case REVOLEN_RANDQUICK:
528 /* If everyone changes to this government once, the last 50% of players doing so
529 * will get the minimum time (1 turn) */
530 change_speed = (player_count() / 2) / (game.server.revolution_length - 1);
531 /* It never takes zero players to make revlen shorter */
532 change_speed = MAX(change_speed, 1);
533 max_turns = game.server.revolution_length - gov->changed_to_times / change_speed;
534 max_turns = MAX(1, max_turns);
535 if (game.info.revolentype == REVOLEN_RANDQUICK) {
536 return fc_rand(max_turns) + 1;
537 }
538 return max_turns;
539 }
540
541 fc_assert(FALSE);
542
543 return GAME_DEFAULT_REVOLUTION_LENGTH;
544}
545
546/**********************************************************************/
549 int revolution_length(struct government *gov, struct player *plr)
550{
551 if (!untargeted_revolution_allowed()
552 && gov == game.government_during_revolution) {
553 /* Targetless revolution not acceptable */
554 notify_player(plr, nullptr, E_REVOLT_DONE, ftc_server,
555 _("You can't revolt without selecting target government."));
556 return -1;
557 }
558
559 return revolentype_length(game.info.revolentype, gov);
560}
561
562/**********************************************************************/
565 void handle_player_change_government(struct player *pplayer,
566 Government_type_id government)
567{
568 int turns;
569 struct government *gov = government_by_number(government);
570 bool anarchy;
571
572 if (!gov || !can_change_to_government(pplayer, gov)) {
573 return;
574 }
575
576 log_debug("Government changed for %s. Target government is %s; "
577 "old %s. Revofin %d, Turn %d.", player_name(pplayer),
578 government_rule_name(gov),
579 government_rule_name(government_of_player(pplayer)),
580 pplayer->revolution_finishes, game.info.turn);
581
582 anarchy = get_player_bonus(pplayer, EFT_NO_ANARCHY) <= 0;
583
584 /* Set revolution_finishes value. */
585 if (pplayer->revolution_finishes > 0) {
586 /* Player already has an active revolution. Note that the finish time
587 * may be in the future (we're waiting for it to finish), the current
588 * turn (it just finished - but isn't reset until the end of the turn)
589 * or even in the past (if the player is in anarchy and hasn't chosen
590 * a government). */
591 turns = pplayer->revolution_finishes - game.info.turn;
592 } else if ((is_ai(pplayer) && !has_handicap(pplayer, H_REVOLUTION))
593 || !anarchy) {
594 /* AI players without the H_REVOLUTION handicap can skip anarchy */
595 anarchy = FALSE;
596 turns = 0;
597 } else {
598 turns = revolution_length(gov, pplayer);
599 if (turns < 0) {
600 return;
601 }
602 }
603
604 if (anarchy && turns <= 0
605 && pplayer->government != game.government_during_revolution) {
606 /* Multiple changes attempted after single anarchy period */
607 if (game.info.revolentype == REVOLEN_QUICKENING
608 || game.info.revolentype == REVOLEN_RANDQUICK) {
609 notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_server,
610 _("You can't revolt the same turn you finished previous revolution."));
611 return;
612 }
613 }
614
615 pplayer->government = game.government_during_revolution;
616 pplayer->target_government = gov;
617 pplayer->revolution_finishes = game.info.turn + turns;
618
619 log_debug("Revolution started for %s. Target government is %s. "
620 "Revofin %d (%d).", player_name(pplayer),
621 government_rule_name(pplayer->target_government),
622 pplayer->revolution_finishes, game.info.turn);
623
624 CALL_PLR_AI_FUNC(revolution_start, pplayer, pplayer);
625
626 /* Now see if the revolution is instantaneous. */
627 if (turns <= 0
628 && pplayer->target_government != game.government_during_revolution) {
629 notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
630 /* TRANS: Switching to a new form of government */
631 _("The %s will switch to %s in the end of "
632 "the player phase."),
633 nation_plural_for_player(pplayer),
634 government_name_translation(pplayer->target_government));
635 return;
636 } else if (turns > 0) {
637 notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
638 /* TRANS: This is a message event so don't make it
639 * too long. */
640 PL_("The %s have incited a revolt! "
641 "%d turn of anarchy will ensue! "
642 "Target government is %s.",
643 "The %s have incited a revolt! "
644 "%d turns of anarchy will ensue! "
645 "Target government is %s.",
646 turns),
647 nation_plural_for_player(pplayer),
648 turns,
649 government_name_translation(pplayer->target_government));
650 } else {
651 fc_assert(pplayer->target_government == game.government_during_revolution);
652
653 notify_player(pplayer, nullptr, E_REVOLT_START, ftc_server,
654 _("Revolution: returning to anarchy."));
655 }
656
657 check_player_max_rates(pplayer);
658 city_refresh_for_player(pplayer);
659 send_player_info_c(pplayer, pplayer->connections);
660
661 log_debug("Government change complete for %s. Target government is %s; "
662 "now %s. Turn %d; revofin %d.", player_name(pplayer),
663 government_rule_name(pplayer->target_government),
664 government_rule_name(government_of_player(pplayer)),
665 game.info.turn, pplayer->revolution_finishes);
666}
667
668/**********************************************************************/
672 void update_revolution(struct player *pplayer)
673{
674 struct government *current_gov;
675
676 /* The player's revolution counter is stored in the revolution_finishes
677 * field. This value has the following meanings:
678 * - If negative (-1), then the player is not in a revolution. In this
679 * case the player should never be in anarchy.
680 * - If positive, the player is in the middle of a revolution. In this
681 * case the value indicates the turn in which the revolution finishes.
682 * * If this value is > than the current turn, then the revolution is
683 * in progress. In this case the player should always be in anarchy.
684 * * If the value is == to the current turn, then the revolution is
685 * finished. The player may now choose a government. However the
686 * value isn't reset until the end of the turn. If the player has
687 * chosen a government by the end of the turn, then the revolution is
688 * over and the value is reset to -1.
689 * * If the player doesn't pick a government then the revolution
690 * continues. At this point the value is <= to the current turn,
691 * and the player can leave the revolution at any time. The value
692 * is reset at the end of any turn when a non-anarchy government is
693 * chosen.
694 */
695 log_debug("Update revolution for %s. Current government %s, "
696 "target %s, revofin %d, turn %d.", player_name(pplayer),
697 government_rule_name(government_of_player(pplayer)),
698 pplayer->target_government
699 ? government_rule_name(pplayer->target_government) : "(none)",
700 pplayer->revolution_finishes, game.info.turn);
701
702 current_gov = government_of_player(pplayer);
703
704 if (current_gov == game.government_during_revolution
705 && pplayer->revolution_finishes <= game.info.turn) {
706 if (pplayer->target_government != game.government_during_revolution) {
707 /* If the revolution is over and a target government is set, go into
708 * the new government. */
709 log_debug("Update: finishing revolution for %s.", player_name(pplayer));
710 government_change(pplayer, pplayer->target_government, TRUE);
711 } else {
712 /* If the revolution is over but there's no target government set,
713 * alert the player. */
714 notify_player(pplayer, nullptr, E_REVOLT_DONE, ftc_any,
715 _("You should choose a new government from the "
716 "government menu."));
717 }
718 } else if (government_of_player(pplayer) != game.government_during_revolution
719 && pplayer->revolution_finishes < game.info.turn) {
720 /* Reset the revolution counter. If the player has another revolution
721 * they'll have to re-enter anarchy. */
722 log_debug("Update: resetting revofin for %s.", player_name(pplayer));
723 pplayer->revolution_finishes = -1;
724 send_player_info_c(pplayer, pplayer->connections);
725 }
726}
727
728/**********************************************************************/
731 void update_capital(struct player *pplayer)
732{
733 int max_value = 0;
734 struct city *primary_capital = nullptr;
735 int same_value_count = 0;
736
737 city_list_iterate(pplayer->cities, pcity) {
738 int value = get_city_bonus(pcity, EFT_CAPITAL_CITY);
739
740 if (value > max_value) {
741 max_value = value;
742 primary_capital = pcity;
743 same_value_count = 1;
744 /* Mark it at least some kind of capital, might turn to named capital
745 * after all have been processed. */
746 pcity->capital = CAPITAL_SECONDARY;
747 } else if (value > 0) {
748 /* Mark it at least some kind of capital. */
749 pcity->capital = CAPITAL_SECONDARY;
750 if (value == max_value) {
751 fc_assert(same_value_count >= 1);
752 same_value_count++;
753 if (fc_rand(same_value_count) == 1) {
754 primary_capital = pcity;
755 }
756 }
757 } else {
758 /* Not capital at all */
759 pcity->capital = CAPITAL_NOT;
760 }
761 } city_list_iterate_end;
762
763 if (primary_capital != nullptr) {
764 primary_capital->capital = CAPITAL_PRIMARY;
765 pplayer->primary_capital_id = primary_capital->id;
766 } else {
767 pplayer->primary_capital_id = 0;
768 }
769}
770
771/**********************************************************************/
776 void check_player_max_rates(struct player *pplayer)
777{
778 struct player_economic old_econ = pplayer->economic;
779
780 player_limit_to_max_rates(pplayer);
781 if (old_econ.tax > pplayer->economic.tax) {
782 notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
783 _("Tax rate exceeded the max rate; adjusted."));
784 }
785 if (old_econ.science > pplayer->economic.science) {
786 notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
787 _("Science rate exceeded the max rate; adjusted."));
788 }
789 if (old_econ.luxury > pplayer->economic.luxury) {
790 notify_player(pplayer, nullptr, E_NEW_GOVERNMENT, ftc_server,
791 _("Luxury rate exceeded the max rate; adjusted."));
792 }
793}
794
795/**********************************************************************/
804 void update_players_after_alliance_breakup(struct player *pplayer,
805 struct player *pplayer2,
806 const struct unit_list
807 *pplayer_seen_units,
808 const struct unit_list
809 *pplayer2_seen_units)
810{
811 /* The client needs updated diplomatic state, because it is used
812 * during calculation of new states of occupied flags in cities */
813 send_player_all_c(pplayer, nullptr);
814 send_player_all_c(pplayer2, nullptr);
815 remove_allied_visibility(pplayer, pplayer2, pplayer_seen_units);
816 remove_allied_visibility(pplayer2, pplayer, pplayer2_seen_units);
817 resolve_unit_stacks(pplayer, pplayer2, TRUE);
818}
819
820/**********************************************************************/
823 static void maybe_claim_base(struct tile *ptile, struct player *new_owner,
824 struct player *old_owner)
825{
826 bool claim = FALSE;
827
828 unit_list_iterate(ptile->units, punit) {
829 if (unit_owner(punit) == new_owner
830 && tile_has_claimable_base(ptile, unit_type_get(punit))) {
831 claim = TRUE;
832 break;
833 }
834 } unit_list_iterate_end;
835
836 if (claim) {
837 extra_type_by_cause_iterate(EC_BASE, pextra) {
838 map_claim_base(ptile, pextra, new_owner, old_owner);
839 } extra_type_by_cause_iterate_end;
840
841 ptile->extras_owner = new_owner;
842 }
843}
844
845/**********************************************************************/
848 void enter_war(struct player *pplayer, struct player *pplayer2)
849{
850 /* Claim bases where units are already standing */
851 whole_map_iterate(&(wld.map), ptile) {
852 struct player *old_owner = extra_owner(ptile);
853
854 if (old_owner == pplayer2) {
855 maybe_claim_base(ptile, pplayer, old_owner);
856 } else if (old_owner == pplayer) {
857 maybe_claim_base(ptile, pplayer2, old_owner);
858 }
859 } whole_map_iterate_end;
860}
861
862/**********************************************************************/
865 void player_update_last_war_action(struct player *pplayer)
866{
867 pplayer->last_war_action = game.info.turn;
868 send_player_info_c(pplayer, nullptr);
869}
870
871/**********************************************************************/
880 void handle_diplomacy_cancel_pact(struct player *pplayer,
881 int other_player_id,
882 enum clause_type clause)
883{
884 enum diplstate_type old_type;
885 enum diplstate_type new_type;
886 enum dipl_reason diplcheck;
887 bool repeat = FALSE;
888 struct player *pplayer2 = player_by_number(other_player_id);
889 struct player_diplstate *ds_plrplr2, *ds_plr2plr;
890 struct unit_list *pplayer_seen_units, *pplayer2_seen_units;
891
892 if (nullptr == pplayer2 || players_on_same_team(pplayer, pplayer2)) {
893 return;
894 }
895
896 old_type = player_diplstate_get(pplayer, pplayer2)->type;
897
898 if (clause == CLAUSE_VISION) {
899 if (!gives_shared_vision(pplayer, pplayer2)) {
900 return;
901 }
902 remove_shared_vision(pplayer, pplayer2);
903 notify_player(pplayer2, nullptr, E_TREATY_BROKEN, ftc_server,
904 _("%s no longer gives us shared vision!"),
905 player_name(pplayer));
906 return;
907 }
908
909 if (clause == CLAUSE_SHARED_TILES) {
910 if (!gives_shared_tiles(pplayer, pplayer2)) {
911 return;
912 }
913 BV_CLR(pplayer->gives_shared_tiles, player_index(pplayer2));
914 whole_map_iterate(&(wld.map), ptile) {
915 if (tile_owner(ptile) == pplayer && ptile->worked != nullptr
916 && city_owner(ptile->worked) == pplayer2) {
917 struct city *pcity = ptile->worked;
918
919 city_map_update_empty(pcity, ptile);
920 pcity->specialists[DEFAULT_SPECIALIST]++;
921 }
922 } whole_map_iterate_end;
923 notify_player(pplayer2, nullptr, E_TREATY_BROKEN, ftc_server,
924 _("%s no longer shares tiles with us!"),
925 player_name(pplayer));
926 return;
927 }
928
929 diplcheck = pplayer_can_cancel_treaty(pplayer, pplayer2);
930
931 /* The senate may not allow you to break the treaty. In this case you
932 * must first dissolve the senate then you can break it. */
933 if (diplcheck == DIPL_SENATE_BLOCKING) {
934 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
935 _("The senate will not allow you to break treaty "
936 "with the %s. You must either dissolve the senate "
937 "or wait until a more timely moment."),
938 nation_plural_for_player(pplayer2));
939 return;
940 }
941
942 if (diplcheck != DIPL_OK) {
943 return;
944 }
945
946 reject_all_treaties(pplayer);
947 reject_all_treaties(pplayer2);
948 /* Else, breaking a treaty */
949
950 /* Check what the new status will be */
951 new_type = cancel_pact_result(old_type);
952
953 if (new_type == old_type) {
954 /* No change */
955 return;
956 }
957
958 ds_plrplr2 = player_diplstate_get(pplayer, pplayer2);
959 ds_plr2plr = player_diplstate_get(pplayer2, pplayer);
960
961 if (old_type == DS_ALLIANCE) {
962 pplayer_seen_units = get_units_seen_via_ally(pplayer, pplayer2);
963 pplayer2_seen_units = get_units_seen_via_ally(pplayer2, pplayer);
964 } else {
965 pplayer_seen_units = nullptr;
966 pplayer2_seen_units = nullptr;
967 }
968
969 /* Do the change */
970 ds_plrplr2->type = ds_plr2plr->type = new_type;
971 ds_plrplr2->turns_left = ds_plr2plr->turns_left = 16;
972
973 if (new_type == DS_WAR) {
974 player_update_last_war_action(pplayer);
975 player_update_last_war_action(pplayer2);
976 }
977
978 /* If the old state was alliance, the players' units can share tiles
979 illegally, and we need to call resolve_unit_stacks() */
980 if (old_type == DS_ALLIANCE) {
981
982 fc_assert(pplayer_seen_units != nullptr);
983 fc_assert(pplayer2_seen_units != nullptr);
984
985 update_players_after_alliance_breakup(pplayer, pplayer2,
986 pplayer_seen_units,
987 pplayer2_seen_units);
988 unit_list_destroy(pplayer_seen_units);
989 unit_list_destroy(pplayer2_seen_units);
990 }
991
992 /* If there's a reason to cancel the pact, do it without penalty */
993 /* FIXME: in the current implementation if you break more than one
994 * treaty simultaneously it may success partially: the first treaty-breaking
995 * will happen but the second one will fail. */
996 if (get_player_bonus(pplayer, EFT_HAS_SENATE) > 0 && !repeat) {
997 if (ds_plrplr2->has_reason_to_cancel > 0) {
998 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
999 _("The senate passes your bill because of the "
1000 "constant provocations of the %s."),
1001 nation_plural_for_player(pplayer2));
1002 } else if (new_type == DS_WAR) {
1003 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
1004 _("The senate refuses to break treaty with the %s, "
1005 "but you have no trouble finding a new senate."),
1006 nation_plural_for_player(pplayer2));
1007 }
1008 }
1009 if (new_type == DS_WAR) {
1010 call_incident(INCIDENT_WAR, CBR_VICTIM_ONLY, nullptr, pplayer, pplayer2);
1011
1012 enter_war(pplayer, pplayer2);
1013 }
1014 ds_plrplr2->has_reason_to_cancel = 0;
1015
1016 send_player_all_c(pplayer, nullptr);
1017 send_player_all_c(pplayer2, nullptr);
1018
1019 /*
1020 * Refresh all cities which have a unit of the other side within
1021 * city range.
1022 */
1023 city_map_update_all_cities_for_player(pplayer);
1024 city_map_update_all_cities_for_player(pplayer2);
1025 sync_cities();
1026
1027 notify_player(pplayer, nullptr, E_TREATY_BROKEN, ftc_server,
1028 _("The diplomatic state between the %s "
1029 "and the %s is now %s."),
1030 nation_plural_for_player(pplayer),
1031 nation_plural_for_player(pplayer2),
1032 diplstate_type_translated_name(new_type));
1033 notify_player(pplayer2, nullptr, E_TREATY_BROKEN, ftc_server,
1034 _(" %s canceled the diplomatic agreement! "
1035 "The diplomatic state between the %s and the %s "
1036 "is now %s."),
1037 player_name(pplayer),
1038 nation_plural_for_player(pplayer2),
1039 nation_plural_for_player(pplayer),
1040 diplstate_type_translated_name(new_type));
1041
1042 /* Check fall-out of a war declaration. */
1043 players_iterate_alive(other) {
1044 if (other != pplayer && other != pplayer2
1045 && new_type == DS_WAR && pplayers_allied(pplayer2, other)
1046 && pplayers_allied(pplayer, other)) {
1047 if (!players_on_same_team(pplayer, other)) {
1048 /* If an ally declares war on another ally, break off your alliance
1049 * to the aggressor. This prevents in-alliance wars, which are not
1050 * permitted. */
1051 notify_player(other, nullptr, E_TREATY_BROKEN, ftc_server,
1052 _("%s has attacked your ally %s! "
1053 "You cancel your alliance to the aggressor."),
1054 player_name(pplayer),
1055 player_name(pplayer2));
1056 player_diplstate_get(other, pplayer)->has_reason_to_cancel = 1;
1057 player_update_last_war_action(other);
1058 handle_diplomacy_cancel_pact(other, player_number(pplayer),
1059 CLAUSE_ALLIANCE);
1060 } else {
1061 /* We are in the same team as the agressor; we cannot break
1062 * alliance with them. We trust our team mate and break alliance
1063 * with the attacked player */
1064 notify_player(other, nullptr, E_TREATY_BROKEN, ftc_server,
1065 _("Your team mate %s declared war on %s. "
1066 "You are obligated to cancel alliance with %s."),
1067 player_name(pplayer),
1068 nation_plural_for_player(pplayer2),
1069 player_name(pplayer2));
1070 handle_diplomacy_cancel_pact(other, player_number(pplayer2), CLAUSE_ALLIANCE);
1071 }
1072 }
1073 } players_iterate_alive_end;
1074}
1075
1076/**********************************************************************/
1079 static void send_player_remove_info_c(const struct player_slot *pslot,
1080 struct conn_list *dest)
1081{
1082 if (!dest) {
1083 dest = game.est_connections;
1084 }
1085
1086 fc_assert_ret(!player_slot_is_used(pslot));
1087
1088 conn_list_iterate(dest, pconn) {
1089 dsend_packet_player_remove(pconn, player_slot_index(pslot));
1090 } conn_list_iterate_end;
1091}
1092
1093/**********************************************************************/
1099 void player_info_freeze(void)
1100{
1101 player_info_frozen_level++;
1102}
1103
1104/**********************************************************************/
1108 void player_info_thaw(void)
1109{
1110 if (0 == --player_info_frozen_level) {
1111 send_nation_availability_real(game.est_connections, FALSE);
1112 send_player_info_c(nullptr, nullptr);
1113 }
1114
1115 fc_assert(0 <= player_info_frozen_level);
1116}
1117
1118/**********************************************************************/
1129 void send_player_all_c(struct player *src, struct conn_list *dest)
1130{
1131 send_player_info_c(src, dest);
1132 send_player_diplstate_c(src, dest);
1133}
1134
1135/**********************************************************************/
1146 void send_player_info_c(struct player *src, struct conn_list *dest)
1147{
1148 if (0 < player_info_frozen_level) {
1149 return; /* Discard, see comment for player_info_freeze(). */
1150 }
1151
1152 if (src != nullptr) {
1153 send_player_info_c_real(src, dest);
1154 return;
1155 }
1156
1157 players_iterate(pplayer) {
1158 send_player_info_c_real(pplayer, dest);
1159 } players_iterate_end;
1160}
1161
1162/**********************************************************************/
1166 static void send_player_info_c_real(struct player *src,
1167 struct conn_list *dest)
1168{
1169 struct packet_player_info info;
1170 struct packet_web_player_info_addition web_info;
1171 struct packet_web_player_info_addition *webp_ptr;
1172
1173 fc_assert_ret(src != nullptr);
1174
1175 if (!dest) {
1176 dest = game.est_connections;
1177 }
1178
1179 if (any_web_conns()) {
1180 webp_ptr = &web_info;
1181 } else {
1182 webp_ptr = nullptr;
1183 }
1184
1185 package_player_common(src, &info, webp_ptr);
1186
1187 conn_list_iterate(dest, pconn) {
1188 if (nullptr == pconn->playing && pconn->observer) {
1189 /* Global observer. */
1190 package_player_info(src, &info, webp_ptr, pconn->playing, INFO_FULL);
1191 } else if (nullptr != pconn->playing) {
1192 /* Players (including regular observers) */
1193 package_player_info(src, &info, webp_ptr,
1194 pconn->playing, INFO_MINIMUM);
1195 } else {
1196 package_player_info(src, &info, webp_ptr, nullptr, INFO_MINIMUM);
1197 }
1198 send_packet_player_info(pconn, &info);
1199 web_send_packet(player_info_addition, pconn, webp_ptr);
1200 } conn_list_iterate_end;
1201}
1202
1203/**********************************************************************/
1212 void send_player_diplstate_c(struct player *src, struct conn_list *dest)
1213{
1214 if (src != nullptr) {
1215 send_player_diplstate_c_real(src, dest);
1216 return;
1217 }
1218
1219 players_iterate(pplayer) {
1220 send_player_diplstate_c_real(pplayer, dest);
1221 } players_iterate_end;
1222}
1223
1224/**********************************************************************/
1228 static void send_player_diplstate_c_real(struct player *plr1,
1229 struct conn_list *dest)
1230{
1231 fc_assert_ret(plr1 != nullptr);
1232
1233 if (!dest) {
1234 dest = game.est_connections;
1235 }
1236
1237 conn_list_iterate(dest, pconn) {
1238 players_iterate(plr2) {
1239 struct packet_player_diplstate packet_ds;
1240
1241 if (nullptr == pconn->playing && pconn->observer) {
1242 /* Global observer. */
1243 package_player_diplstate(plr1, plr2, &packet_ds, pconn->playing,
1244 INFO_FULL);
1245 } else if (nullptr != pconn->playing) {
1246 /* Players (including regular observers) */
1247 package_player_diplstate(plr1, plr2, &packet_ds, pconn->playing,
1248 INFO_MINIMUM);
1249 } else {
1250 package_player_diplstate(plr1, plr2, &packet_ds, nullptr,
1251 INFO_MINIMUM);
1252 }
1253 send_packet_player_diplstate(pconn, &packet_ds);
1254 } players_iterate_end;
1255 } conn_list_iterate_end;
1256}
1257
1258/**********************************************************************/
1261 static void package_player_common(struct player *plr,
1262 struct packet_player_info *packet,
1263 struct packet_web_player_info_addition *
1264 web_packet)
1265{
1266 int i;
1267 struct music_style *music;
1268
1269 packet->playerno = player_number(plr);
1270 sz_strlcpy(packet->name, player_name(plr));
1271 sz_strlcpy(packet->username, plr->username);
1272 packet->unassigned_user = plr->unassigned_user;
1273 packet->nation = plr->nation ? nation_number(plr->nation) : NATION_NONE;
1274 packet->is_male = plr->is_male;
1275 packet->team = plr->team ? team_number(plr->team) : team_count();
1276 packet->is_ready = plr->is_ready;
1277 packet->was_created = plr->was_created;
1278 packet->style = plr->style ? style_number(plr->style) : 0;
1279
1280 /* I think we could safely move the music style selection to
1281 * client side to not have it burden server side. Client could
1282 * actually avoid it completely when music disabled from the client options.
1283 * Client has no use for music styles of other players, and there should
1284 * be no such information about the player themself needed to determine
1285 * the music style that client does not know. */
1286 music = player_music_style(plr);
1287 if (music != nullptr) {
1288 packet->music_style = music_style_number(music);
1289 } else {
1290 packet->music_style = -1; /* No music style available */
1291 }
1292
1293 packet->is_alive = plr->is_alive;
1294 packet->turns_alive = plr->turns_alive;
1295 packet->is_connected = plr->is_connected;
1296 packet->flags = plr->flags;
1297 packet->ai_skill_level = is_ai(plr)
1298 ? plr->ai_common.skill_level : 0;
1299 for (i = 0; i < player_slot_count(); i++) {
1300 packet->love[i] = plr->ai_common.love[i];
1301 }
1302 packet->barbarian_type = plr->ai_common.barbarian_type;
1303
1304 packet->phase_done = plr->phase_done;
1305 packet->nturns_idle = plr->nturns_idle;
1306 packet->science_cost = plr->ai_common.science_cost;
1307
1308#ifdef FREECIV_WEB
1309 if (web_packet != nullptr) {
1310 web_packet->playerno = player_number(plr);
1311 }
1312#endif /* FREECIV_WEB */
1313}
1314
1315/**********************************************************************/
1324 static void package_player_info(struct player *plr,
1325 struct packet_player_info *packet,
1326 struct packet_web_player_info_addition *
1327 web_packet,
1328 struct player *receiver,
1329 enum plr_info_level min_info_level)
1330{
1331 enum plr_info_level info_level;
1332 enum plr_info_level highest_team_level;
1333 struct government *pgov = nullptr;
1334 Impr_type_id imp;
1335
1336 if (receiver) {
1337 info_level = player_info_level(plr, receiver);
1338 info_level = MAX(min_info_level, info_level);
1339 } else {
1340 info_level = min_info_level;
1341 }
1342
1343 /* Multipliers */
1344 packet->multip_count = multiplier_count();
1345 if (info_level >= INFO_FULL) {
1346 multipliers_iterate(pmul) {
1347 int idx = multiplier_index(pmul);
1348
1349 packet->multiplier[idx] = plr->multipliers[idx].value;
1350 packet->multiplier_target[idx] = plr->multipliers[idx].target;
1351 packet->multiplier_changed[idx] = plr->multipliers[idx].changed;
1352 } multipliers_iterate_end;
1353 } else {
1354 multipliers_iterate(pmul) {
1355 int idx = multiplier_index(pmul);
1356
1357 packet->multiplier[idx] = 0;
1358 packet->multiplier_target[idx] = 0;
1359 packet->multiplier_changed[idx] = 0;
1360 } multipliers_iterate_end;
1361 }
1362
1363 /* We need to send all tech info for all players on the same
1364 * team, even if they are not in contact yet; otherwise we will
1365 * overwrite team research or confuse the client. */
1366 highest_team_level = info_level;
1367 players_iterate(aplayer) {
1368 if (players_on_same_team(plr, aplayer) && receiver) {
1369 highest_team_level = MAX(highest_team_level,
1370 player_info_level(aplayer, receiver));
1371 }
1372 } players_iterate_end;
1373
1374 if (plr->rgb != nullptr) {
1375 packet->color_valid = TRUE;
1376 packet->color_red = plr->rgb->r;
1377 packet->color_green = plr->rgb->g;
1378 packet->color_blue = plr->rgb->b;
1379 } else {
1380 /* In pregame, send the color we expect to use, for consistency with
1381 * '/list colors' etc. */
1382 const struct rgbcolor *preferred = player_preferred_color(plr);
1383
1384 if (preferred != nullptr) {
1385 packet->color_valid = TRUE;
1386 packet->color_red = preferred->r;
1387 packet->color_green = preferred->g;
1388 packet->color_blue = preferred->b;
1389 } else {
1390 fc_assert(game.info.turn < 1); /* Game has not yet started */
1391 packet->color_valid = FALSE;
1392 /* Client shouldn't use these dummy values */
1393 packet->color_red = 0;
1394 packet->color_green = 0;
1395 packet->color_blue = 0;
1396 }
1397 }
1398 packet->color_changeable = player_color_changeable(plr, nullptr);
1399
1400 /* Only send score if we have contact */
1401 if (info_level >= INFO_MEETING) {
1402 packet->score = plr->score.game;
1403 } else {
1404 packet->score = -1;
1405 }
1406
1407 packet->autoselect_weight = plr->autoselect_weight;
1408
1409 if (info_level >= INFO_MEETING) {
1410 packet->gold = plr->economic.gold;
1411 pgov = government_of_player(plr);
1412 } else {
1413 packet->gold = 0;
1414 pgov = game.government_during_revolution;
1415 }
1416 packet->government = pgov ? government_number(pgov) : government_count();
1417
1418 /* Send diplomatic status of the player to everyone they are in
1419 * contact with. */
1420 if (info_level >= INFO_EMBASSY
1421 || (receiver
1422 && player_diplstate_get(receiver, plr)->contact_turns_left > 0)) {
1423 packet->target_government = plr->target_government
1424 ? government_number(plr->target_government)
1425 : government_count();
1426 packet->real_embassy = plr->real_embassy;
1427 packet->gives_shared_vision = plr->gives_shared_vision;
1428 packet->gives_shared_tiles = plr->gives_shared_tiles;
1429 } else {
1430 packet->target_government = packet->government;
1431 BV_CLR_ALL(packet->real_embassy);
1432 BV_CLR_ALL(packet->gives_shared_vision);
1433 BV_CLR_ALL(packet->gives_shared_tiles);
1434
1435 if (receiver != nullptr) {
1436 int ridx = player_index(receiver);
1437
1438 if (player_has_real_embassy(plr, receiver)) {
1439 BV_SET(packet->real_embassy, ridx);
1440 }
1441
1442 if (gives_shared_vision(plr, receiver)) {
1443 BV_SET(packet->gives_shared_vision, ridx);
1444 }
1445
1446 if (gives_shared_tiles(plr, receiver)) {
1447 BV_SET(packet->gives_shared_tiles, ridx);
1448 }
1449 }
1450 }
1451
1452 /* Make absolutely sure - in case you lose your embassy! */
1453 if (info_level >= INFO_EMBASSY
1454 || (receiver
1455 && player_diplstate_get(plr, receiver)->type == DS_TEAM)) {
1456 packet->tech_upkeep = player_tech_upkeep(plr);
1457 } else {
1458 packet->tech_upkeep = 0;
1459 }
1460
1461 /* Send most civ info about the player only to players who have an
1462 * embassy. */
1463 if (highest_team_level >= INFO_EMBASSY) {
1464 packet->tax = plr->economic.tax;
1465 packet->science = plr->economic.science;
1466 packet->luxury = plr->economic.luxury;
1467 packet->revolution_finishes = plr->revolution_finishes;
1468 packet->culture = player_culture(plr);
1469 } else {
1470 packet->tax = 0;
1471 packet->science = 0;
1472 packet->luxury = 0;
1473 packet->revolution_finishes = -1;
1474 packet->culture = 0;
1475 }
1476
1477 if (info_level >= INFO_FULL
1478 || (receiver
1479 && player_diplstate_get(plr, receiver)->type == DS_TEAM)) {
1480 packet->mood = player_mood(plr);
1481 } else {
1482 packet->mood = MOOD_COUNT;
1483 }
1484
1485 if (info_level >= INFO_FULL) {
1486 packet->history = plr->history;
1487 packet->infrapoints = plr->economic.infra_points;
1488 } else {
1489 packet->history = 0;
1490 packet->infrapoints = 0;
1491 }
1492
1493 for (imp = 0; imp < B_LAST; imp++) {
1494 if (plr->wonders[imp] != WONDER_NOT_BUILT) {
1495 if (wonder_visible_to_player(improvement_by_number(imp),
1496 receiver, plr,
1497 info_level >= INFO_EMBASSY ? TRI_YES : TRI_NO)) {
1498 packet->wonders[imp] = plr->wonders[imp];
1499 } else {
1500 packet->wonders[imp] = WONDER_NOT_BUILT;
1501 }
1502 } else {
1503 packet->wonders[imp] = WONDER_NOT_BUILT;
1504 }
1505 }
1506
1507#ifdef FREECIV_WEB
1508 if (web_packet != nullptr) {
1509 if (info_level >= INFO_FULL) {
1510 web_packet->expected_income = player_get_expected_income(plr);
1511 } else {
1512 web_packet->expected_income = 0;
1513 }
1514 }
1515#endif /* FREECIV_WEB */
1516}
1517
1518/**********************************************************************/
1527 static void package_player_diplstate(struct player *plr1,
1528 struct player *plr2,
1529 struct packet_player_diplstate *packet_ds,
1530 struct player *receiver,
1531 enum plr_info_level min_info_level)
1532{
1533 enum plr_info_level info_level;
1534 struct player_diplstate *ds = player_diplstate_get(plr1, plr2);
1535
1536 if (receiver) {
1537 info_level = player_info_level(plr1, receiver);
1538 info_level = MAX(min_info_level, info_level);
1539 } else {
1540 info_level = min_info_level;
1541 }
1542
1543 packet_ds->plr1 = player_index(plr1);
1544 packet_ds->plr2 = player_index(plr2);
1545 /* A unique id for each combination is calculated here. */
1546 packet_ds->diplstate_id = packet_ds->plr1 * MAX_NUM_PLAYER_SLOTS
1547 + packet_ds->plr2;
1548
1549 /* Send diplomatic status of the player to everyone they are in
1550 * contact with (embassy, remaining contact turns, the receiver). */
1551 if (info_level >= INFO_EMBASSY
1552 || (receiver
1553 && player_diplstate_get(receiver, plr1)->contact_turns_left > 0)
1554 || (receiver && receiver == plr2)) {
1555 packet_ds->type = ds->type;
1556 packet_ds->turns_left = ds->turns_left;
1557 packet_ds->has_reason_to_cancel = ds->has_reason_to_cancel;
1558 packet_ds->contact_turns_left = ds->contact_turns_left;
1559 } else {
1560 packet_ds->type = DS_WAR;
1561 packet_ds->turns_left = 0;
1562 packet_ds->has_reason_to_cancel = 0;
1563 packet_ds->contact_turns_left = 0;
1564 }
1565}
1566
1567/**********************************************************************/
1570 static enum plr_info_level player_info_level(struct player *plr,
1571 struct player *receiver)
1572{
1573 if (S_S_RUNNING > server_state()) {
1574 return INFO_MINIMUM;
1575 }
1576 if (plr == receiver) {
1577 return INFO_FULL;
1578 }
1579 if (receiver && team_has_embassy(receiver->team, plr)) {
1580 return INFO_EMBASSY;
1581 }
1582 if (receiver && could_intel_with_player(receiver, plr)) {
1583 return INFO_MEETING;
1584 }
1585
1586 return INFO_MINIMUM;
1587}
1588
1589/**********************************************************************/
1593 struct conn_list *player_reply_dest(struct player *pplayer)
1594{
1595 return (pplayer->current_conn ?
1596 pplayer->current_conn->self :
1597 pplayer->connections);
1598}
1599
1600/**********************************************************************/
1603 static void call_first_contact(struct player *pplayer, struct player *aplayer)
1604{
1605 CALL_PLR_AI_FUNC(first_contact, pplayer, pplayer, aplayer);
1606}
1607
1608/**********************************************************************/
1618 void server_player_init(struct player *pplayer, bool initmap,
1619 bool needs_team)
1620{
1621 player_status_reset(pplayer);
1622
1623 BV_CLR(pplayer->flags, PLRF_FIRST_CITY);
1624 BV_CLR_ALL(pplayer->server.really_gives_vision);
1625 BV_CLR_ALL(pplayer->server.debug);
1626
1627 pplayer->server.border_vision = FALSE;
1628
1629 player_map_free(pplayer);
1630 pplayer->server.private_map = nullptr;
1631
1632 if (initmap) {
1633 player_map_init(pplayer);
1634 }
1635 if (needs_team) {
1636 team_add_player(pplayer, nullptr);
1637 fc_assert(pplayer->team != nullptr);
1638 }
1639
1640 /* This must be done after team information is initialised
1641 * as it might be needed to determine max rate effects.
1642 * Sometimes this server_player_init() gets called twice
1643 * with only latter one having needs_team set. We don't
1644 * want to call player_limit_to_max_rates() at first time
1645 * when team is not yet set. It's callers responsibility
1646 * to always have one server_player_init() call with
1647 * needs_team TRUE. */
1648 if (needs_team) {
1649 player_limit_to_max_rates(pplayer);
1650 }
1651
1652 adv_data_default(pplayer);
1653
1654 /* We don't push this in calc_civ_score(), or it will be reset
1655 * every turn. */
1656 pplayer->score.units_built = 0;
1657 pplayer->score.units_killed = 0;
1658 pplayer->score.units_lost = 0;
1659 pplayer->score.units_used = 0;
1660
1661 /* No delegation. */
1662 pplayer->server.delegate_to[0] = '\0';
1663 pplayer->server.orig_username[0] = '\0';
1664
1665 handicaps_init(pplayer);
1666}
1667
1668/**********************************************************************/
1673 const struct rgbcolor *player_preferred_color(struct player *pplayer)
1674{
1675 if (pplayer->rgb) {
1676 return pplayer->rgb;
1677 } else if (playercolor_count() == 0) {
1678 /* If a ruleset isn't loaded, there are no colors to choose from. */
1679 return nullptr;
1680 } else if (game.server.plrcolormode == PLRCOL_NATION_ORDER) {
1681 if (pplayer->nation != NO_NATION_SELECTED) {
1682 return nation_color(nation_of_player(pplayer)); /* May be nullptr */
1683 } else {
1684 return nullptr; /* Don't know nation, hence don't know color */
1685 }
1686 } else {
1687 /* Modes indexing into game-defined player colors */
1688 int colorid;
1689
1690 switch (game.server.plrcolormode) {
1691 case PLRCOL_PLR_SET: /* Player color (set) */
1692 case PLRCOL_PLR_RANDOM: /* Player color (random) */
1693 /* These depend on other players and will be assigned at game start. */
1694 return nullptr;
1695 default:
1696 log_error("Invalid value for 'game.server.plrcolormode' (%d)!",
1697 game.server.plrcolormode);
1698 fc__fallthrough; /* No break - using 'PLRCOL_PLR_ORDER' as fallback */
1699 case PLRCOL_PLR_ORDER: /* Player color (ordered) */
1700 colorid = player_number(pplayer) % playercolor_count();
1701 break;
1702 case PLRCOL_TEAM_ORDER: /* Team color (ordered) */
1703 colorid = team_number(pplayer->team) % playercolor_count();
1704 break;
1705 }
1706
1707 return playercolor_get(colorid);
1708 }
1709}
1710
1711/**********************************************************************/
1716 bool player_color_changeable(const struct player *pplayer, const char **reason)
1717{
1718 if (!game_was_started() && game.server.plrcolormode != PLRCOL_PLR_SET) {
1719 if (reason) {
1720 *reason = _("Can only set player color prior to game start if "
1721 "'plrcolormode' is PLR_SET.");
1722 }
1723 return FALSE;
1724 }
1725
1726 return TRUE;
1727}
1728
1729/**********************************************************************/
1734 void assign_player_colors(void)
1735{
1736 struct rgbcolor_list *spare_colors
1737 = rgbcolor_list_copy(game.server.plr_colors);
1738 int needed = player_count();
1739
1740 players_iterate(pplayer) {
1741 const struct rgbcolor *autocolor;
1742 /* Assign the deterministic colors. */
1743 if (!pplayer->rgb
1744 && (autocolor = player_preferred_color(pplayer))) {
1745 player_set_color(pplayer, autocolor);
1746 }
1747 if (pplayer->rgb) {
1748 /* One fewer random color needed. */
1749 needed--;
1750 /* Try to avoid clashes between explicit and random colors. */
1751 rgbcolor_list_iterate(spare_colors, prgbcolor) {
1752 if (rgbcolors_are_equal(pplayer->rgb, prgbcolor)) {
1753 rgbcolor_list_remove(spare_colors, prgbcolor);
1754 }
1755 } rgbcolor_list_iterate_end;
1756 }
1757 } players_iterate_end;
1758
1759 if (needed == 0) {
1760 /* No random colors needed */
1761 rgbcolor_list_destroy(spare_colors);
1762 return;
1763 }
1764
1765 if (game.server.plrcolormode == PLRCOL_NATION_ORDER) {
1766 /* Additionally, try to avoid color clashes with certain nations not
1767 * yet in play (barbarians). */
1768 allowed_nations_iterate(pnation) {
1769 const struct rgbcolor *ncol = nation_color(pnation);
1770 if (ncol && nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
1771 /* Don't use this color. */
1772 rgbcolor_list_iterate(spare_colors, prgbcolor) {
1773 if (rgbcolors_are_equal(ncol, prgbcolor)) {
1774 rgbcolor_list_remove(spare_colors, ncol);
1775 }
1776 } rgbcolor_list_iterate_end;
1777 }
1778 } allowed_nations_iterate_end;
1779 }
1780
1781 fc_assert(game.server.plrcolormode == PLRCOL_PLR_RANDOM
1782 || game.server.plrcolormode == PLRCOL_PLR_SET
1783 || game.server.plrcolormode == PLRCOL_NATION_ORDER);
1784
1785 if (needed > rgbcolor_list_size(spare_colors)) {
1786 log_verbose("Not enough unique colors for all players; there will be "
1787 "duplicates");
1788 /* Fallback: start again from full set of ruleset colors.
1789 * No longer attempt to avoid clashes with explicitly assigned colors. */
1790 rgbcolor_list_destroy(spare_colors);
1791 spare_colors = rgbcolor_list_copy(game.server.plr_colors);
1792 }
1793 /* We may still not have enough, if there are more players than
1794 * ruleset-defined colors. If so, top up with duplicates. */
1795 if (needed > rgbcolor_list_size(spare_colors)) {
1796 int i, origsize = rgbcolor_list_size(spare_colors);
1797 /* Shuffle so that duplicates aren't biased to start of list */
1798 rgbcolor_list_shuffle(spare_colors);
1799 /* Duplication process avoids one color being hit lots of times */
1800 for (i = origsize; i < needed; i++) {
1801 rgbcolor_list_append(spare_colors,
1802 rgbcolor_list_get(spare_colors, i - origsize));
1803 }
1804 }
1805 /* Shuffle (including mixing any duplicates up) */
1806 rgbcolor_list_shuffle(spare_colors);
1807
1808 /* Finally, assign shuffled colors to players. */
1809 players_iterate(pplayer) {
1810 if (!pplayer->rgb) {
1811 player_set_color(pplayer, rgbcolor_list_front(spare_colors));
1812 rgbcolor_list_pop_front(spare_colors);
1813 }
1814 } players_iterate_end;
1815
1816 rgbcolor_list_destroy(spare_colors);
1817}
1818
1819/**********************************************************************/
1823 void server_player_set_color(struct player *pplayer,
1824 const struct rgbcolor *prgbcolor)
1825{
1826 if (prgbcolor != nullptr) {
1827 player_set_color(pplayer, prgbcolor);
1828 } else {
1829 /* This can legitimately be nullptr in pregame. */
1830 fc_assert_ret(!game_was_started());
1831 rgbcolor_destroy(pplayer->rgb);
1832 pplayer->rgb = nullptr;
1833 }
1834 /* Update clients */
1835 send_player_info_c(pplayer, nullptr);
1836}
1837
1838/**********************************************************************/
1843 const char *player_color_ftstr(struct player *pplayer)
1844{
1845 static char buf[64];
1846 char hex[16];
1847 const struct rgbcolor *prgbcolor;
1848
1849 fc_assert_ret_val(pplayer != nullptr, nullptr);
1850
1851 buf[0] = '\0';
1852 prgbcolor = player_preferred_color(pplayer);
1853 if (prgbcolor != nullptr
1854 && rgbcolor_to_hex(prgbcolor, hex, sizeof(hex))) {
1855 struct ft_color plrcolor = FT_COLOR("#000000", hex);
1856
1857 featured_text_apply_tag(hex, buf, sizeof(buf), TTT_COLOR, 0,
1858 FT_OFFSET_UNSET, plrcolor);
1859 } else {
1860 cat_snprintf(buf, sizeof(buf), _("no color"));
1861 }
1862
1863 return buf;
1864}
1865
1866/**********************************************************************/
1870 void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
1871{
1872 int sucount = strlen(game.server.start_units);
1873 int i;
1874
1875 for (i = 0; i < sucount; i++) {
1876 if (game.server.start_units[i] == 'k') {
1877 /* Every player should have king */
1878 struct unit_type *utype = crole_to_unit_type('k', pplayer);
1879
1880 if (utype != nullptr) {
1881 create_unit(pplayer, ptile, utype, 0, 0, -1);
1882 }
1883 }
1884 }
1885}
1886
1887/**********************************************************************/
1894 struct player *server_create_player(int player_id, const char *ai_tname,
1895 struct rgbcolor *prgbcolor,
1896 bool allow_ai_type_fallbacking)
1897{
1898 struct player_slot *pslot;
1899 struct player *pplayer;
1900
1901 pslot = player_slot_by_number(player_id);
1902 fc_assert(nullptr == pslot || !player_slot_is_used(pslot));
1903
1904 pplayer = player_new(pslot);
1905 if (nullptr == pplayer) {
1906 return nullptr;
1907 }
1908
1909 if (allow_ai_type_fallbacking) {
1910 pplayer->savegame_ai_type_name = fc_strdup(ai_tname);
1911 ai_tname = ai_type_name_or_fallback(ai_tname);
1912 }
1913
1914 pplayer->ai = ai_type_by_name(ai_tname);
1915
1916 if (pplayer->ai == nullptr) {
1917 player_destroy(pplayer);
1918 return nullptr;
1919 }
1920
1921 adv_data_init(pplayer);
1922
1923 CALL_FUNC_EACH_AI(player_alloc, pplayer);
1924
1925 /* TODO: Do we really need this server_player_init() here? All our callers
1926 * will later make another server_player_init() call anyway, with boolean
1927 * parameters set to what they really need. */
1928 server_player_init(pplayer, FALSE, FALSE);
1929
1930 if (prgbcolor) {
1931 player_set_color(pplayer, prgbcolor);
1932 } /* Else caller must ensure a color is assigned if game has started */
1933
1934 return pplayer;
1935}
1936
1937/**********************************************************************/
1943 void server_remove_player(struct player *pplayer)
1944{
1945 const struct player_slot *pslot;
1946
1947 fc_assert_ret(nullptr != pplayer);
1948
1949 /* Save player slot */
1950 pslot = pplayer->slot;
1951
1952 log_normal(_("Removing player %s."), player_name(pplayer));
1953
1954 notify_conn(pplayer->connections, nullptr, E_CONNECTION, ftc_server,
1955 _("You've been removed from the game!"));
1956
1957 notify_conn(game.est_connections, nullptr, E_CONNECTION, ftc_server,
1958 _("%s has been removed from the game."),
1959 player_name(pplayer));
1960
1961 if (is_barbarian(pplayer)) {
1962 server.nbarbarians--;
1963 }
1964
1965 /* Don't use conn_list_iterate here because connection_detach() can be
1966 * recursive and free the next connection pointer. */
1967 while (conn_list_size(pplayer->connections) > 0) {
1968 connection_detach(conn_list_get(pplayer->connections, 0), FALSE);
1969 }
1970
1971 script_server_remove_exported_object(pplayer);
1972 /* Clear data saved in the other player structs. */
1973 players_iterate(aplayer) {
1974 BV_CLR(aplayer->real_embassy, player_index(pplayer));
1975 if (gives_shared_vision(aplayer, pplayer)) {
1976 remove_shared_vision(aplayer, pplayer);
1977 }
1978 /* Also remove vision provided for the other players */
1979 if (gives_shared_vision(pplayer, aplayer)) {
1980 remove_shared_vision(pplayer, aplayer);
1981 }
1982 } players_iterate_end;
1983
1984 /* Remove citizens of this player from the cities of all other players. */
1985 /* FIXME: add a special case if the server quits - no need to run this for
1986 * each player in that case. */
1987 if (game.info.citizen_nationality) {
1988 cities_iterate(pcity) {
1989 if (city_owner(pcity) != pplayer) {
1990 citizens nationality = citizens_nation_get(pcity, pplayer->slot);
1991
1992 if (nationality != 0) {
1993 /* Change nationality of the citizens to the nationality of the
1994 * city owner. */
1995 citizens_nation_move(pcity, pplayer->slot, city_owner(pcity)->slot,
1996 nationality);
1997 city_refresh_queue_add(pcity);
1998 }
1999 }
2000 } cities_iterate_end
2001
2002 city_refresh_queue_processing();
2003 }
2004
2005 /* AI type lost control of this player */
2006 if (is_ai(pplayer)) {
2007 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
2008 }
2009
2010 /* Clear all trade routes. This is needed for the other end not
2011 * to point to a city removed by player_clear() */
2012 city_list_iterate(pplayer->cities, pcity) {
2013 trade_routes_iterate_safe(pcity, proute) {
2014 struct trade_route *pback = remove_trade_route(pcity, proute,
2015 TRUE, TRUE);
2016
2017 FC_FREE(proute);
2018 FC_FREE(pback);
2019 } trade_routes_iterate_safe_end;
2020 } city_list_iterate_end;
2021
2022 /* We have to clear all player data before the ai memory is freed because
2023 * some function may depend on it. */
2024 player_clear(pplayer, TRUE);
2025
2026 if (!map_is_empty()) {
2027 remove_player_from_maps(pplayer);
2028 }
2029 player_map_free(pplayer);
2030
2031 /* Destroy advisor and ai data. */
2032 CALL_FUNC_EACH_AI(player_free, pplayer);
2033
2034 handicaps_close(pplayer);
2035 ai_traits_close(pplayer);
2036 adv_data_close(pplayer);
2037 player_destroy(pplayer);
2038
2039 send_updated_vote_totals(nullptr);
2040 /* Must be called after the player was destroyed */
2041 send_player_remove_info_c(pslot, nullptr);
2042
2043 /* Recalculate borders. */
2044 map_calculate_borders();
2045}
2046
2047/**********************************************************************/
2057 void player_limit_to_max_rates(struct player *pplayer)
2058{
2059 int maxrate, surplus;
2060 struct player_economic *economic;
2061
2062 /* AI players allowed to cheat */
2063 if (is_ai(pplayer) && !has_handicap(pplayer, H_RATES)) {
2064 return;
2065 }
2066
2067 economic = &(pplayer->economic);
2068
2069 maxrate = get_player_maxrate(pplayer);
2070
2071 surplus = 0;
2072 if (economic->luxury > maxrate) {
2073 surplus += economic->luxury - maxrate;
2074 economic->luxury = maxrate;
2075 }
2076 if (economic->tax > maxrate) {
2077 surplus += economic->tax - maxrate;
2078 economic->tax = maxrate;
2079 }
2080 if (economic->science > maxrate) {
2081 surplus += economic->science - maxrate;
2082 economic->science = maxrate;
2083 }
2084
2085 fc_assert(surplus % 10 == 0);
2086
2087 while (surplus > 0) {
2088 if (economic->science < maxrate) {
2089 economic->science += 10;
2090 } else if (economic->tax < maxrate) {
2091 economic->tax += 10;
2092 } else if (economic->luxury < maxrate) {
2093 economic->luxury += 10;
2094 } else {
2095 fc_assert_msg(FALSE, "Failed to distribute the surplus. "
2096 "maxrate = %d.", maxrate);
2097 }
2098 surplus -= 10;
2099 }
2100}
2101
2102/**********************************************************************/
2106 static bool server_player_name_is_allowed(const struct connection *caller,
2107 const struct player *pplayer,
2108 const struct nation_type *pnation,
2109 const char *name, char *error_buf,
2110 size_t error_buf_len)
2111{
2112 /* An empty name is surely not allowed. */
2113 if (0 == strlen(name)) {
2114 fc_strlcpy(error_buf, _("Please choose a non-blank name."),
2115 error_buf_len);
2116 return FALSE;
2117 }
2118
2119 /* Any name already taken is not allowed. */
2120 players_iterate(other_player) {
2121 if (other_player == pplayer) {
2122 /* We don't care if we're the one using the name/nation. */
2123 continue;
2124 } else if (nullptr != pnation && other_player->nation == pnation) {
2125 /* FIXME: currently cannot use nation_of_player(other_player) as the
2126 * nation debug code is buggy and doesn't test nation for nullptr. */
2127 fc_strlcpy(error_buf, _("That nation is already in use."),
2128 error_buf_len);
2129 return FALSE;
2130 } else if (0 == fc_strcasecmp(player_name(other_player), name)) {
2131 fc_snprintf(error_buf, error_buf_len,
2132 _("Another player already has the name '%s'. Please "
2133 "choose another name."), name);
2134 return FALSE;
2135 }
2136 } players_iterate_end;
2137
2138 if (nullptr == pnation) {
2139 /* FIXME: currently cannot use nation_of_player(other_player) as the
2140 * nation debug code is buggy and doesn't test nation for nullptr. */
2141 pnation = pplayer->nation;
2142 }
2143
2144 /* Any name from the default list is always allowed. */
2145 if (nullptr != pnation && nullptr != nation_leader_by_name(pnation, name)) {
2146 return TRUE;
2147 }
2148
2149 /* To prevent abuse, only players with HACK access (usually local
2150 * connections) can use non-ascii names. Otherwise players could use
2151 * confusing garbage names in multi-player games. */
2152 if (nullptr != caller
2153 && caller->access_level < ALLOW_HACK
2154 && !is_ascii_name(name)) {
2155 fc_strlcpy(error_buf,
2156 _("Please choose a name containing only ASCII characters."),
2157 error_buf_len);
2158 return FALSE;
2159 }
2160
2161 return TRUE;
2162}
2163
2164/**********************************************************************/
2168 bool server_player_set_name_full(const struct connection *caller,
2169 struct player *pplayer,
2170 const struct nation_type *pnation,
2171 const char *name,
2172 char *error_buf, size_t error_buf_len)
2173{
2174 char real_name[MAX_LEN_NAME];
2175 char buf[256];
2176 int i;
2177
2178 /* Always provide an error buffer. */
2179 if (nullptr == error_buf) {
2180 error_buf = buf;
2181 error_buf_len = sizeof(buf);
2182 }
2183 error_buf[0] = '\0';
2184
2185 if (nullptr != name) {
2186 /* Ensure this is a correct name. */
2187 sz_strlcpy(real_name, name);
2188 remove_leading_trailing_spaces(real_name);
2189 real_name[0] = fc_toupper(real_name[0]);
2190
2191 if (server_player_name_is_allowed(caller, pplayer, pnation, real_name,
2192 error_buf, error_buf_len)) {
2193 log_debug("Name of player nb %d set to \"%s\".",
2194 player_number(pplayer), real_name);
2195 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2196 return TRUE; /* Success! */
2197 } else {
2198 log_verbose("Failed to set the name of the player nb %d to \"%s\": %s",
2199 player_number(pplayer), real_name, error_buf);
2200 /* Fallthrough. */
2201 }
2202 }
2203
2204 if (nullptr != caller) {
2205 /* If we want to test, let's fail here. */
2206 fc_assert(nullptr != name);
2207 return FALSE;
2208 }
2209
2210 if (nullptr != name) {
2211 /* Try to append a number to 'real_name'. */
2212 char test[MAX_LEN_NAME];
2213
2214 for (i = 2; i <= player_slot_count(); i++) {
2215 fc_snprintf(test, sizeof(test), "%s%d", real_name, i);
2216 if (server_player_name_is_allowed(caller, pplayer, pnation,
2217 test, error_buf, error_buf_len)) {
2218 log_verbose("Name of player nb %d set to \"%s\" instead.",
2219 player_number(pplayer), test);
2220 fc_strlcpy(pplayer->name, test, sizeof(pplayer->name));
2221 return TRUE;
2222 } else {
2223 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2224 player_number(pplayer), test, error_buf);
2225 }
2226 }
2227 }
2228
2229 /* Try a default name. */
2230 fc_snprintf(real_name, sizeof(real_name),
2231 _("Player no. %d"), player_number(pplayer));
2232 if (server_player_name_is_allowed(caller, pplayer, pnation,
2233 real_name, error_buf, error_buf_len)) {
2234 log_verbose("Name of player nb %d set to \"%s\".",
2235 player_number(pplayer), real_name);
2236 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2237 return TRUE;
2238 } else {
2239 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2240 player_number(pplayer), real_name, error_buf);
2241 }
2242
2243 /* Try a very default name... */
2244 for (i = 0; i < player_slot_count(); i++) {
2245 fc_snprintf(real_name, sizeof(real_name), _("Player no. %d"), i);
2246 if (server_player_name_is_allowed(caller, pplayer, pnation,
2247 real_name, error_buf, error_buf_len)) {
2248 log_verbose("Name of player nb %d to \"%s\".",
2249 player_number(pplayer), real_name);
2250 fc_strlcpy(pplayer->name, real_name, sizeof(pplayer->name));
2251 return TRUE;
2252 } else {
2253 log_debug("Failed to set the name of the player nb %d to \"%s\": %s",
2254 player_number(pplayer), real_name, error_buf);
2255 }
2256 }
2257
2258 /* This is really not normal... Maybe the size of 'real_name'
2259 * is not enough big, or a bug in server_player_name_is_allowed(). */
2260 fc_strlcpy(pplayer->name, _("A poorly-named player"),
2261 sizeof(pplayer->name));
2262 return FALSE; /* Let's say it's a failure. */
2263}
2264
2265/**********************************************************************/
2268 void server_player_set_name(struct player *pplayer, const char *name)
2269{
2270#ifndef FREECIV_NDEBUG
2271 bool ret =
2272#endif
2273 server_player_set_name_full(nullptr, pplayer, nullptr, name, nullptr, 0);
2274
2275 fc_assert(ret);
2276}
2277
2278/**********************************************************************/
2284static enum diplstate_type
2285get_default_diplstate(const struct player *pplayer1,
2286 const struct player *pplayer2)
2287{
2288 players_iterate_alive(pplayer3) {
2289 if (pplayer3 != pplayer1
2290 && pplayer3 != pplayer2
2291 && pplayers_allied(pplayer3, pplayer1)
2292 && pplayers_allied(pplayer3, pplayer2)) {
2293 return DS_PEACE;
2294 }
2295 } players_iterate_alive_end;
2296
2297 return DS_WAR;
2298}
2299
2300/**********************************************************************/
2303 void make_contact(struct player *pplayer1, struct player *pplayer2,
2304 struct tile *ptile)
2305{
2306 struct player_diplstate *ds_plr1plr2, *ds_plr2plr1;
2307
2308 if (pplayer1 == pplayer2
2309 || !pplayer1->is_alive
2310 || !pplayer2->is_alive) {
2311 return;
2312 }
2313
2314 ds_plr1plr2 = player_diplstate_get(pplayer1, pplayer2);
2315 ds_plr2plr1 = player_diplstate_get(pplayer2, pplayer1);
2316
2317 if (get_player_bonus(pplayer1, EFT_NO_DIPLOMACY) <= 0
2318 && get_player_bonus(pplayer2, EFT_NO_DIPLOMACY) <= 0) {
2319 ds_plr1plr2->contact_turns_left = game.server.contactturns;
2320 ds_plr2plr1->contact_turns_left = game.server.contactturns;
2321 }
2322 if (ds_plr1plr2->type == DS_NO_CONTACT) {
2323 enum diplstate_type new_state = get_default_diplstate(pplayer1,
2324 pplayer2);
2325
2326 set_diplstate_type(ds_plr1plr2, ds_plr2plr1, new_state);
2327 ds_plr1plr2->first_contact_turn = game.info.turn;
2328 ds_plr2plr1->first_contact_turn = game.info.turn;
2329 notify_player(pplayer1, ptile, E_FIRST_CONTACT, ftc_server,
2330 _("You have made contact with the %s, ruled by %s."),
2331 nation_plural_for_player(pplayer2),
2332 player_name(pplayer2));
2333 notify_player(pplayer2, ptile, E_FIRST_CONTACT, ftc_server,
2334 _("You have made contact with the %s, ruled by %s."),
2335 nation_plural_for_player(pplayer1),
2336 player_name(pplayer1));
2337 send_player_all_c(pplayer1, pplayer2->connections);
2338 send_player_all_c(pplayer2, pplayer1->connections);
2339 send_player_all_c(pplayer1, pplayer1->connections);
2340 send_player_all_c(pplayer2, pplayer2->connections);
2341 if (is_ai(pplayer1)) {
2342 call_first_contact(pplayer1, pplayer2);
2343 }
2344 if (is_ai(pplayer2)) {
2345 call_first_contact(pplayer2, pplayer1);
2346 }
2347 return;
2348 } else {
2349 fc_assert(ds_plr2plr1->type != DS_NO_CONTACT);
2350 }
2351 if (team_has_embassy(pplayer1->team, pplayer2)
2352 || team_has_embassy(pplayer2->team, pplayer1)) {
2353 return; /* Avoid sending too much info over the network */
2354 }
2355 send_player_all_c(pplayer1, pplayer1->connections);
2356 send_player_all_c(pplayer2, pplayer2->connections);
2357}
2358
2359/**********************************************************************/
2362 void maybe_make_contact(struct tile *ptile, struct player *pplayer)
2363{
2364 square_iterate(&(wld.map), ptile, 1, tile1) {
2365 struct city *pcity = tile_city(tile1);
2366 if (pcity) {
2367 make_contact(pplayer, city_owner(pcity), ptile);
2368 }
2369 unit_list_iterate_safe(tile1->units, punit) {
2370 make_contact(pplayer, unit_owner(punit), ptile);
2371 } unit_list_iterate_safe_end;
2372 } square_iterate_end;
2373}
2374
2375/**********************************************************************/
2378 void shuffle_players(void)
2379{
2380 /* shuffled_order is defined global */
2381 int n = player_slot_count();
2382 int i;
2383
2384 log_debug("shuffle_players: creating shuffled order");
2385
2386 for (i = 0; i < n; i++) {
2387 shuffled_order[i] = i;
2388 }
2389
2390 /* Randomize it */
2391 array_shuffle(shuffled_order, n);
2392
2393#ifdef FREECIV_DEBUG
2394 for (i = 0; i < n; i++) {
2395 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2396 }
2397#endif /* FREECIV_DEBUG */
2398}
2399
2400/**********************************************************************/
2403 void set_shuffled_players(int *shuffled_players)
2404{
2405 int i;
2406
2407 log_debug("set_shuffled_players: loading shuffled array %p",
2408 shuffled_players);
2409
2410 for (i = 0; i < player_slot_count(); i++) {
2411 shuffled_order[i] = shuffled_players[i];
2412 log_debug("shuffled_order[%d] = %d", i, shuffled_order[i]);
2413 }
2414}
2415
2416/**********************************************************************/
2421 struct player *shuffled_player(int i)
2422{
2423 struct player *pplayer;
2424
2425 pplayer = player_by_number(shuffled_order[i]);
2426 log_debug("shuffled_player(%d) = %d (%s)",
2427 i, shuffled_order[i], player_name(pplayer));
2428 return pplayer;
2429}
2430
2431/**********************************************************************/
2453 struct nation_type *pick_a_nation(const struct nation_list *choices,
2454 bool ignore_conflicts,
2455 bool needs_startpos,
2456 enum barbarian_type barb_type)
2457{
2458 enum {
2459 UNAVAILABLE, AVAILABLE, PREFERRED, UNWANTED
2460 } nations_used[nation_count()], looking_for;
2461 int match[nation_count()], pick, idx;
2462 int num_avail_nations = 0, num_pref_nations = 0;
2463
2464 /* Values of nations_used:
2465 * UNAVAILABLE - nation is already used or is a special nation.
2466 * AVAILABLE - we can use this nation.
2467 * PREFERRED - we can use this nation and it is on the choices list.
2468 * UNWANTED - we can use this nation, but we really don't want to. */
2469 nations_iterate(pnation) {
2470 idx = nation_index(pnation);
2471
2472 if (!nation_is_in_current_set(pnation)
2473 || pnation->player
2474 || (needs_startpos && game.scenario.startpos_nations
2475 && pnation->server.no_startpos)
2476 || (barb_type != nation_barbarian_type(pnation))
2477 || (barb_type == NOT_A_BARBARIAN && !is_nation_playable(pnation))) {
2478 /* Nation is unplayable or already used: don't consider it.
2479 * (If nations aren't currently restricted to those with start
2480 * positions, we do nothing special here, but generate_players() will
2481 * tend to prefer them.) */
2482 nations_used[idx] = UNAVAILABLE;
2483 match[idx] = 0;
2484 continue;
2485 }
2486
2487 nations_used[idx] = AVAILABLE;
2488
2489 /* Determine which nations look good with nations already in the game,
2490 * or conflict with them. */
2491 match[idx] = 1;
2492 players_iterate(pplayer) {
2493 if (pplayer->nation != NO_NATION_SELECTED) {
2494 int x = nations_match(pnation, nation_of_player(pplayer),
2495 ignore_conflicts);
2496 if (x < 0) {
2497 log_debug("Nations '%s' (nb %d) and '%s' (nb %d) are in conflict.",
2498 nation_rule_name(pnation), nation_number(pnation),
2499 nation_rule_name(nation_of_player(pplayer)),
2500 nation_number(nation_of_player(pplayer)));
2501 nations_used[idx] = UNWANTED;
2502 match[idx] -= x * 100;
2503 break;
2504 } else {
2505 match[idx] += x * 100;
2506 }
2507 }
2508 } players_iterate_end;
2509
2510 if (AVAILABLE == nations_used[idx]) {
2511 num_avail_nations += match[idx];
2512 }
2513 } nations_iterate_end;
2514
2515 /* Mark as preferred those nations which are on the choices list and
2516 * which are AVAILABLE, but no UNWANTED */
2517 if (nullptr != choices) {
2518 nation_list_iterate(choices, pnation) {
2519 idx = nation_index(pnation);
2520 if (nations_used[idx] == AVAILABLE) {
2521 num_pref_nations += match[idx];
2522 nations_used[idx] = PREFERRED;
2523 }
2524 } nation_list_iterate_end;
2525 }
2526
2527 if (0 < num_pref_nations || 0 < num_avail_nations) {
2528 if (0 < num_pref_nations) {
2529 /* Use a preferred nation only. */
2530 pick = fc_rand(num_pref_nations);
2531 looking_for = PREFERRED;
2532 log_debug("Picking a preferred nation.");
2533 } else {
2534 /* Use any available nation. */
2535 fc_assert(0 < num_avail_nations);
2536 pick = fc_rand(num_avail_nations);
2537 looking_for = AVAILABLE;
2538 log_debug("Picking an available nation.");
2539 }
2540
2541 nations_iterate(pnation) {
2542 idx = nation_index(pnation);
2543 if (nations_used[idx] == looking_for) {
2544 pick -= match[idx];
2545
2546 if (0 > pick) {
2547 return pnation;
2548 }
2549 }
2550 } nations_iterate_end;
2551 } else {
2552 /* No available nation: use unwanted nation... */
2553 struct nation_type *less_worst_nation = NO_NATION_SELECTED;
2554 int less_worst_score = -FC_INFINITY;
2555
2556 log_debug("Picking an unwanted nation.");
2557 nations_iterate(pnation) {
2558 idx = nation_index(pnation);
2559 if (UNWANTED == nations_used[idx]) {
2560 pick = -fc_rand(match[idx]);
2561 if (pick > less_worst_score) {
2562 less_worst_nation = pnation;
2563 less_worst_score = pick;
2564 }
2565 }
2566 } nations_iterate_end;
2567
2568 if (NO_NATION_SELECTED != less_worst_nation) {
2569 return less_worst_nation;
2570 }
2571 }
2572
2573 log_verbose("No nation found!");
2574
2575 return NO_NATION_SELECTED;
2576}
2577
2578/**********************************************************************/
2581 static struct nation_set *current_nationset(void)
2582{
2583 return nation_set_by_setting_value(game.server.nationset);
2584}
2585
2586/**********************************************************************/
2590 bool nation_is_in_current_set(const struct nation_type *pnation)
2591{
2592 return nation_is_in_set(pnation, current_nationset());
2593}
2594
2595/**********************************************************************/
2599 void count_playable_nations(void)
2600{
2601 server.playable_nations = 0;
2602 allowed_nations_iterate(pnation) {
2603 if (is_nation_playable(pnation)) {
2604 server.playable_nations++;
2605 }
2606 } allowed_nations_iterate_end;
2607}
2608
2609/**********************************************************************/
2614 bool client_can_pick_nation(const struct nation_type *pnation)
2615{
2616 fc_assert_ret_val(pnation != nullptr, FALSE);
2617 return nation_is_in_current_set(pnation)
2618 && is_nation_playable(pnation)
2619 && (!game.scenario.startpos_nations
2620 || !pnation->server.no_startpos);
2621}
2622
2623/**********************************************************************/
2626 static void send_nation_availability_real(struct conn_list *dest,
2627 bool nationset_change)
2628{
2629 struct packet_nation_availability packet;
2630
2631 packet.ncount = nation_count();
2632 packet.nationset_change = nationset_change;
2633 nations_iterate(pnation) {
2634 packet.is_pickable[nation_index(pnation)] = client_can_pick_nation(pnation);
2635 } nations_iterate_end;
2636 lsend_packet_nation_availability(dest, &packet);
2637}
2638
2639/**********************************************************************/
2642 void send_nation_availability(struct conn_list *dest,
2643 bool nationset_change)
2644{
2645 if (0 < player_info_frozen_level) {
2646 return; /* Discard, see comment for player_info_freeze(). */
2647 } else {
2648 send_nation_availability_real(dest, nationset_change);
2649 }
2650}
2651
2652/**********************************************************************/
2659 void fit_nationset_to_players(void)
2660{
2661 int ncount = nation_set_count();
2662 int misfits[ncount];
2663
2664 memset(misfits, 0, sizeof(misfits));
2665
2666 nation_sets_iterate(pset) {
2667 players_iterate(pplayer) {
2668 if (pplayer->nation != NO_NATION_SELECTED
2669 && !nation_is_in_set(pplayer->nation, pset)) {
2670 misfits[nation_set_index(pset)]++;
2671 }
2672 } players_iterate_end;
2673 } nation_sets_iterate_end;
2674
2675 if (misfits[nation_set_index(current_nationset())] == 0) {
2676 /* Current set is OK. */
2677 return;
2678 }
2679
2680 /* Otherwise, pick the least bad set (requires unsetting fewest
2681 * players, possibly none). */
2682 {
2683 int i, least_misfits;
2684 const struct nation_set *best;
2685
2686 fc_assert(ncount > 0);
2687
2688 best = nation_set_by_number(0);
2689 least_misfits = misfits[0];
2690 for (i = 1; i < ncount && least_misfits != 0; i++) {
2691 if (best == nullptr || misfits[i] < least_misfits) {
2692 best = nation_set_by_number(i);
2693 least_misfits = misfits[i];
2694 }
2695 }
2696
2697 log_verbose("Current nationset \"%s\" doesn't fit all existing players.",
2698 nation_set_rule_name(current_nationset()));
2699 log_verbose("Selected nationset \"%s\".", nation_set_rule_name(best));
2700 fc_strlcpy(game.server.nationset, nation_set_rule_name(best),
2701 sizeof(game.server.nationset));
2702 count_playable_nations();
2703 /* No need to refresh clients, as we're assumed to be in the middle of
2704 * loading a savegame and will send new setting/availability later
2705 * along with everything else */
2706 }
2707
2708 /* The set we chose may not fit all the players; as a last resort,
2709 * unset nations (caller must then arrange new assignments). */
2710 players_iterate(pplayer) {
2711 if (pplayer->nation != NO_NATION_SELECTED
2712 && !nation_is_in_current_set(pplayer->nation)) {
2713 log_verbose("Nation %s of player %s not in nationset \"%s\", unsetting.",
2714 nation_plural_for_player(pplayer), player_name(pplayer),
2715 nation_set_rule_name(current_nationset()));
2716 player_set_nation(pplayer, NO_NATION_SELECTED);
2717 }
2718 } players_iterate_end;
2719}
2720
2721/**********************************************************************/
2724 void reset_all_start_commands(bool plrchange)
2725{
2726 if (S_S_INITIAL != server_state()) {
2727 return;
2728 }
2729 players_iterate(pplayer) {
2730 if (pplayer->is_ready) {
2731 bool persistent = FALSE;
2732
2733 if (plrchange) {
2734 switch (game.info.persistent_ready)
2735 {
2736 case PERSISTENTR_DISABLED:
2737 persistent = FALSE;
2738 break;
2739 case PERSISTENTR_CONNECTED:
2740 persistent = pplayer->is_connected;
2741 break;
2742 }
2743 }
2744
2745 if (!persistent) {
2746 pplayer->is_ready = FALSE;
2747 send_player_info_c(pplayer, game.est_connections);
2748 }
2749 }
2750 } players_iterate_end;
2751}
2752
2753/**********************************************************************/
2759 static struct player *split_player(struct player *pplayer)
2760{
2761 struct research *new_research, *old_research;
2762 struct player *cplayer;
2763 struct nation_type *rebel_nation;
2764
2765 /* Make a new player, or not */
2766 cplayer = server_create_player(-1, ai_name(pplayer->ai),
2767 nullptr, FALSE);
2768 if (!cplayer) {
2769 return nullptr;
2770 }
2771
2772 /* While this sets player->economic according to max rates as known
2773 * at this point, we redo that later, so that MaxRates effect
2774 * requirements will be evaluated with more completely set up player
2775 * (e.g. correct government) */
2776 server_player_init(cplayer, TRUE, TRUE);
2777
2778 /* Rebel will always be an AI player */
2779 rebel_nation = pick_a_nation(nation_of_player(pplayer)->server.civilwar_nations,
2780 TRUE, FALSE, NOT_A_BARBARIAN);
2781 player_nation_defaults(cplayer, rebel_nation, TRUE);
2782
2783 fc_assert(game_was_started());
2784 /* Find a color for the new player. */
2785 assign_player_colors();
2786
2787 /* Send information about the used player slot to all connections. */
2788 send_player_info_c(cplayer, nullptr);
2789
2790 sz_strlcpy(cplayer->username, _(ANON_USER_NAME));
2791 cplayer->unassigned_user = TRUE;
2792 cplayer->is_connected = FALSE;
2793 cplayer->government = init_government_of_nation(nation_of_player(cplayer));
2794 fc_assert(cplayer->revolution_finishes < 0);
2795 /* No capital for the splitted player. */
2796 BV_CLR(cplayer->flags, PLRF_FIRST_CITY);
2797
2798 players_iterate(other_player) {
2799 struct player_diplstate *ds_co
2800 = player_diplstate_get(cplayer, other_player);
2801 struct player_diplstate *ds_oc
2802 = player_diplstate_get(other_player, cplayer);
2803
2804 if (get_player_bonus(other_player, EFT_NO_DIPLOMACY) > 0) {
2805 /* FIXME: What about No-contact war? */
2806 set_diplstate_type(ds_co, ds_oc, DS_WAR);
2807 } else {
2808 set_diplstate_type(ds_co, ds_oc, DS_NO_CONTACT);
2809 }
2810
2811 ds_co->has_reason_to_cancel = 0;
2812 ds_co->turns_left = 0;
2813 ds_co->contact_turns_left = 0;
2814 ds_oc->has_reason_to_cancel = 0;
2815 ds_oc->turns_left = 0;
2816 ds_oc->contact_turns_left = 0;
2817
2818 /* Send so that other_player sees updated diplomatic info;
2819 * pplayer will be sent later anyway
2820 */
2821 if (other_player != pplayer) {
2822 send_player_all_c(other_player, other_player->connections);
2823 }
2824 } players_iterate_end;
2825
2826 /* Split the resources */
2827 cplayer->economic.gold = pplayer->economic.gold;
2828 cplayer->economic.gold /= 2;
2829 pplayer->economic.gold -= cplayer->economic.gold;
2830
2831 /* Copy the research */
2832 new_research = research_get(cplayer);
2833 old_research = research_get(pplayer);
2834
2835 new_research->bulbs_researched = 0;
2836 new_research->techs_researched = old_research->techs_researched;
2837 new_research->researching = old_research->researching;
2838 new_research->future_tech = old_research->future_tech;
2839 new_research->tech_goal = old_research->tech_goal;
2840
2841 advance_index_iterate(A_NONE, i) {
2842 if (TECH_KNOWN == research_invention_state(old_research, i)) {
2843 research_invention_set(new_research, i, TECH_KNOWN);
2844 new_research->inventions[i].bulbs_researched_saved
2845 = old_research->inventions[i].bulbs_researched_saved;
2846 }
2847 } advance_index_iterate_end;
2848 cplayer->phase_done = TRUE; /* Have other things to think
2849 about - paralysis */
2850 BV_CLR_ALL(cplayer->real_embassy); /* All embassies destroyed */
2851 research_update(new_research);
2852
2853 /* Do the ai */
2854 set_as_ai(cplayer);
2855 cplayer->ai_common.maxbuycost = pplayer->ai_common.maxbuycost;
2856 cplayer->ai_common.warmth = pplayer->ai_common.warmth;
2857 cplayer->ai_common.frost = pplayer->ai_common.frost;
2858 set_ai_level_direct(cplayer, game.info.skill_level);
2859
2860 /* Change the original player */
2861 if (government_of_player(pplayer) != game.government_during_revolution) {
2862 pplayer->target_government = pplayer->government;
2863 pplayer->government = game.government_during_revolution;
2864 pplayer->revolution_finishes = game.info.turn + 1;
2865 }
2866 old_research->bulbs_researched = 0;
2867 old_research->researching_saved = A_UNKNOWN;
2868 BV_CLR_ALL(pplayer->real_embassy); /* All embassies destroyed */
2869
2870 /* Give splitted player the embassies to their team mates back, if any */
2871 if (pplayer->team) {
2872 players_iterate(pdest) {
2873 if (pplayer->team == pdest->team
2874 && pplayer != pdest) {
2875 establish_embassy(pplayer, pdest);
2876 }
2877 } players_iterate_end;
2878 }
2879 research_update(old_research);
2880
2881 player_limit_to_max_rates(pplayer);
2882
2883 /* Copy the maps */
2884
2885 give_map_from_player_to_player(pplayer, cplayer);
2886
2887 pplayer->server.border_vision = cplayer->server.border_vision;
2888
2889 /* Not sure if this is necessary, but might be a good idea
2890 * to avoid doing some ai calculations with bogus data. */
2891 adv_data_phase_init(cplayer, TRUE);
2892 CALL_PLR_AI_FUNC(phase_begin, cplayer, cplayer, TRUE);
2893 CALL_PLR_AI_FUNC(gained_control, cplayer, cplayer);
2894 CALL_PLR_AI_FUNC(split_by_civil_war, pplayer, pplayer, cplayer);
2895 CALL_PLR_AI_FUNC(created_by_civil_war, cplayer, pplayer, cplayer);
2896
2897 player_limit_to_max_rates(cplayer);
2898
2899 return cplayer;
2900}
2901
2902/**********************************************************************/
2910 bool civil_war_possible(struct player *pplayer, bool conquering_city,
2911 bool honour_server_option)
2912{
2913 int n;
2914
2915 if (!game.info.civil_war_enabled) {
2916 return FALSE;
2917 }
2918
2919 n = city_list_size(pplayer->cities);
2920
2921 if (n - (conquering_city?1:0) < GAME_MIN_CIVILWARSIZE) {
2922 return FALSE;
2923 }
2924 if (honour_server_option) {
2925 return game.server.civilwarsize < GAME_MAX_CIVILWARSIZE
2926 && n >= game.server.civilwarsize;
2927 } else {
2928 return TRUE;
2929 }
2930}
2931
2932/**********************************************************************/
2957 bool civil_war_triggered(struct player *pplayer)
2958{
2959 /* Get base probabilities */
2960 int dice = fc_rand(100); /* Throw the dice */
2961 int prob = get_player_bonus(pplayer, EFT_CIVIL_WAR_CHANCE);
2962
2963 /* Now compute the contribution of the cities. */
2964 city_list_iterate(pplayer->cities, pcity) {
2965 if (city_unhappy(pcity)) {
2966 prob += game.info.civil_war_bonus_unhappy;
2967 }
2968 if (city_celebrating(pcity)) {
2969 prob += game.info.civil_war_bonus_celebrating;
2970 }
2971 } city_list_iterate_end;
2972
2973 log_verbose("Civil war chance for %s: prob %d, dice %d",
2974 player_name(pplayer), prob, dice);
2975
2976 return (dice < prob);
2977}
2978
2979/**********************************************************************/
3007 struct player *civil_war(struct player *pplayer)
3008{
3009 int i, j;
3010 struct player *cplayer;
3011 struct city *capital;
3012 struct city_list *defector_candidates;
3013 size_t plr_count;
3014
3015 /* It is possible that this function gets called after pplayer
3016 * died. Player pointers are safe even after death. */
3017 if (!pplayer->is_alive) {
3018 return nullptr;
3019 }
3020
3021 plr_count = normal_player_count();
3022 if (plr_count >= MAX_NUM_PLAYERS) {
3023 /* No space to make additional player */
3024 log_normal(_("Could not throw %s into civil war - too many players"),
3025 nation_plural_for_player(pplayer));
3026 return nullptr;
3027 }
3028
3029 if (plr_count >= game.server.max_players) {
3030 /* No space to make additional player */
3031 log_normal(_("Could not throw %s into civil war - maxplayers (%d) reached"),
3032 nation_plural_for_player(pplayer), game.server.max_players);
3033 return nullptr;
3034 }
3035
3036 if (plr_count >= server.playable_nations) {
3037 /* No nation for additional player */
3038 log_normal(_("Could not throw %s into civil war - no available nations"),
3039 nation_plural_for_player(pplayer));
3040 return nullptr;
3041 }
3042
3043 /* It doesn't make sense to try to split an empire of 1 city.
3044 * This should have been enforced by civil_war_possible(). */
3045 fc_assert_ret_val(city_list_size(pplayer->cities) > 1, nullptr);
3046
3047 defector_candidates = city_list_new();
3048 city_list_iterate(pplayer->cities, pcity) {
3049 bool gameloss_present = FALSE;
3050
3051 /* Capital (probably new capital) won't defect */
3052 if (is_capital(pcity)) {
3053 continue;
3054 }
3055
3056 /* City hosting victim's GameLoss unit won't defect */
3057 unit_list_iterate(city_tile(pcity)->units, punit) {
3058 if (unit_owner(punit) == pplayer
3059 && unit_has_type_flag(punit, UTYF_GAMELOSS)) {
3060 gameloss_present = TRUE;
3061 break;
3062 }
3063 } unit_list_iterate_end;
3064
3065 if (gameloss_present) {
3066 continue;
3067 }
3068
3069 city_list_append(defector_candidates, pcity);
3070 } city_list_iterate_end;
3071
3072 if (city_list_size(defector_candidates) == 0) {
3073 log_verbose(_("Could not throw %s into civil war - no available cities"),
3074 nation_plural_for_player(pplayer));
3075 city_list_destroy(defector_candidates);
3076
3077 return nullptr;
3078 }
3079
3080 /* We're definitely going to create a new rebel player. */
3081
3082 cplayer = split_player(pplayer);
3083
3084 /* Before units, cities, so clients know name of new nation
3085 * (for debugging etc).
3086 */
3087 send_player_all_c(cplayer, nullptr);
3088 send_player_all_c(pplayer, nullptr);
3089
3090 /* Now split the empire */
3091
3092 log_verbose("%s civil war; created AI %s",
3093 nation_rule_name(nation_of_player(pplayer)),
3094 nation_rule_name(nation_of_player(cplayer)));
3095 notify_player(pplayer, nullptr, E_CIVIL_WAR, ftc_server,
3096 _("Your nation is thrust into civil war."));
3097
3098 notify_player(pplayer, nullptr, E_FIRST_CONTACT, ftc_server,
3099 /* TRANS: <leader> ... the Poles. */
3100 _("%s is the rebellious leader of the %s."),
3101 player_name(cplayer),
3102 nation_plural_for_player(cplayer));
3103
3104 j = city_list_size(defector_candidates); /* number left to process */
3105 /* Number to try to flip; ensure that at least one eligible city is
3106 * flipped */
3107 i = MAX(j/2, 1);
3108 city_list_iterate(defector_candidates, pcity) {
3109 fc_assert_action(!is_capital(pcity), continue);
3110 if (i >= j || (i > 0 && fc_rand(2) == 1)) {
3111 /* Transfer city and units supported by this city to the new owner.
3112 * We do NOT resolve stack conflicts here, but rather later.
3113 * Reason: if we have a transporter from one city which is carrying
3114 * a unit from another city, and both cities join the rebellion. If we
3115 * resolved stack conflicts for each city we would teleport the first
3116 * of the units we met since the other would have another owner. */
3117 if (transfer_city(cplayer, pcity, -1, FALSE, FALSE, FALSE, FALSE)) {
3118 log_verbose("%s declares allegiance to the %s.", city_name_get(pcity),
3119 nation_rule_name(nation_of_player(cplayer)));
3120 notify_player(pplayer, pcity->tile, E_CITY_LOST, ftc_server,
3121 /* TRANS: <city> ... the Poles. */
3122 _("%s declares allegiance to the %s."),
3123 city_link(pcity),
3124 nation_plural_for_player(cplayer));
3125 script_server_signal_emit("city_transferred", pcity, pplayer,
3126 cplayer, "civil_war");
3127 }
3128 i--;
3129 }
3130 j--;
3131 } city_list_iterate_end;
3132
3133 city_list_destroy(defector_candidates);
3134
3135 resolve_unit_stacks(pplayer, cplayer, FALSE);
3136
3137 i = city_list_size(cplayer->cities);
3138 fc_assert(i > 0); /* Rebels should have got at least one city */
3139
3140 /* Choose a capital (random). */
3141 capital = city_list_get(cplayer->cities, fc_rand(i));
3142 city_build_free_buildings(capital);
3143 give_midgame_initial_units(cplayer, city_tile(capital));
3144
3145 notify_player(nullptr, nullptr, E_CIVIL_WAR, ftc_server,
3146 /* TRANS: ... Danes ... Poles ... <7> cities. */
3147 PL_("Civil war partitions the %s;"
3148 " the %s now hold %d city.",
3149 "Civil war partitions the %s;"
3150 " the %s now hold %d cities.",
3151 i),
3152 nation_plural_for_player(pplayer),
3153 nation_plural_for_player(cplayer),
3154 i);
3155
3156 return cplayer;
3157}
3158
3159/**********************************************************************/
3162 void handle_player_attribute_chunk(struct player *pplayer,
3163 const struct packet_player_attribute_chunk
3164 *chunk)
3165{
3166 generic_handle_player_attribute_chunk(pplayer, chunk);
3167}
3168
3169/**********************************************************************/
3172 void handle_player_attribute_block(struct player *pplayer)
3173{
3174 send_attribute_block(pplayer, pplayer->current_conn);
3175}
3176
3177/**********************************************************************/
3180 void handle_player_phase_done(struct player *pplayer,
3181 int turn)
3182{
3183 if (turn != game.info.turn) {
3184 /* If this happens then the player actually pressed turn-done on a
3185 * previous turn but we didn't receive it until now. The player
3186 * probably didn't actually mean to end their turn! */
3187 return;
3188 }
3189
3190 pplayer->phase_done = TRUE;
3191
3192 check_for_full_turn_done();
3193
3194 send_player_all_c(pplayer, nullptr);
3195}
3196
3197/**********************************************************************/
3200 int barbarian_count(void)
3201{
3202 return server.nbarbarians;
3203}
3204
3205/**********************************************************************/
3208 int normal_player_count(void)
3209{
3210 return player_count() - server.nbarbarians;
3211}
3212
3213/**********************************************************************/
3216 void player_status_add(struct player *plr, enum player_status pstatus)
3217{
3218 BV_SET(plr->server.status, pstatus);
3219}
3220
3221/**********************************************************************/
3224 bool player_status_check(struct player *plr, enum player_status pstatus)
3225{
3226 return BV_ISSET(plr->server.status, pstatus);
3227}
3228
3229/**********************************************************************/
3232 void player_status_reset(struct player *plr)
3233{
3234 BV_CLR_ALL(plr->server.status);
3235 player_status_add(plr, PSTATUS_NORMAL);
3236}
3237
3238/**********************************************************************/
3241 const char *player_delegation_get(const struct player *pplayer)
3242{
3243 if (pplayer == nullptr || strlen(pplayer->server.delegate_to) == 0) {
3244 /* No delegation if there is no player. */
3245 return nullptr;
3246 } else {
3247 return pplayer->server.delegate_to;
3248 }
3249}
3250
3251/**********************************************************************/
3254 void player_delegation_set(struct player *pplayer, const char *username)
3255{
3256 fc_assert_ret(pplayer != nullptr);
3257
3258 if (username == nullptr || strlen(username) == 0) {
3259 pplayer->server.delegate_to[0] = '\0';
3260 } else {
3261 sz_strlcpy(pplayer->server.delegate_to, username);
3262 }
3263}
3264
3265/**********************************************************************/
3270 bool player_delegation_active(const struct player *pplayer)
3271{
3272 return (pplayer && strlen(pplayer->server.orig_username) != 0);
3273}
3274
3275/**********************************************************************/
3278 void send_delegation_info(const struct connection *pconn)
3279{
3280 if (game.info.is_new_game) {
3281 return;
3282 }
3283
3284 if (!pconn->observer
3285 && pconn->playing && player_delegation_get(pconn->playing) != nullptr) {
3286 notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3287 /* TRANS: '/delegate cancel' is a server command and must not
3288 * be translated */
3289 _("User '%s' is currently allowed to take control of your "
3290 "player while you are away. Use '/delegate cancel' to "
3291 "revoke this access."),
3292 player_delegation_get(pconn->playing));
3293 }
3294
3295 {
3296 bool any_delegations = FALSE;
3297
3298 players_iterate(aplayer) {
3299 if (player_delegation_get(aplayer) != nullptr
3300 && strcmp(player_delegation_get(aplayer), pconn->username) == 0) {
3301 notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3302 _("Control of player '%s' is delegated to you."),
3303 player_name(aplayer));
3304 any_delegations = TRUE;
3305 }
3306 } players_iterate_end;
3307 if (any_delegations) {
3308 notify_conn(pconn->self, nullptr, E_CONNECTION, ftc_server,
3309 /* TRANS: '/delegate take' is a server command and must not
3310 * be translated; but <player> should be translated. */
3311 _("Use '/delegate take <player>' to take control of a "
3312 "delegated player."));
3313 }
3314 }
3315}
3316
3317/**********************************************************************/
3322 struct player *player_by_user_delegated(const char *name)
3323{
3324 players_iterate(pplayer) {
3325 if (player_delegation_get(pplayer)
3326 && fc_strcasecmp(name, pplayer->server.orig_username) == 0) {
3327 return pplayer;
3328 }
3329 } players_iterate_end;
3330
3331 return nullptr;
3332}
3333
3334/**********************************************************************/
3337 void playercolor_init(void)
3338{
3339 fc_assert_ret(game.server.plr_colors == nullptr);
3340
3341 game.server.plr_colors = rgbcolor_list_new();
3342}
3343
3344/**********************************************************************/
3347 void playercolor_free(void)
3348{
3349 if (game.server.plr_colors == nullptr) {
3350 return;
3351 }
3352
3353 if (rgbcolor_list_size(game.server.plr_colors) > 0) {
3354 rgbcolor_list_iterate(game.server.plr_colors, prgbcolor) {
3355 rgbcolor_list_remove(game.server.plr_colors, prgbcolor);
3356 rgbcolor_destroy(prgbcolor);
3357 } rgbcolor_list_iterate_end;
3358 };
3359 rgbcolor_list_destroy(game.server.plr_colors);
3360 game.server.plr_colors = nullptr;
3361}
3362
3363/**********************************************************************/
3366 void playercolor_add(struct rgbcolor *prgbcolor)
3367{
3368 fc_assert_ret(game.server.plr_colors != nullptr);
3369
3370 rgbcolor_list_append(game.server.plr_colors, prgbcolor);
3371}
3372
3373/**********************************************************************/
3376 struct rgbcolor *playercolor_get(int id)
3377{
3378 fc_assert_ret_val(game.server.plr_colors != nullptr, nullptr);
3379
3380 return rgbcolor_list_get(game.server.plr_colors, id);
3381}
3382
3383/**********************************************************************/
3386 int playercolor_count(void)
3387{
3388 fc_assert_ret_val(game.server.plr_colors != nullptr, -1);
3389
3390 return rgbcolor_list_size(game.server.plr_colors);
3391}
3392
3393/**********************************************************************/
3396 void handle_player_multiplier(struct player *pplayer, int count,
3397 const int *multipliers)
3398{
3399 int rval;
3400 int i;
3401
3402 if (count != multiplier_count()) {
3403 log_error("Bad number of multipliers %d from client for %s",
3404 count, player_name(pplayer));
3405 return;
3406 }
3407
3408 for (i = 0; i < count; i++) {
3409 struct multiplier *pmul = multiplier_by_number(i);
3410
3411 if (multiplier_can_be_changed(pmul, pplayer)) {
3412 if (multipliers[i] < pmul->start || multipliers[i] > pmul->stop) {
3413 log_error("Multiplier value %d for %s out of range for %s",
3414 multipliers[i], multiplier_rule_name(pmul),
3415 player_name(pplayer));
3416 } else {
3417 rval = (multipliers[i] - pmul->start) / pmul->step * pmul->step + pmul->start;
3418 if (rval != multipliers[i]) {
3419 log_error("Multiplier value %d between valid values for %s for %s",
3420 multipliers[i], multiplier_rule_name(pmul),
3421 player_name(pplayer));
3422 } else {
3423 pplayer->multipliers[i].target = multipliers[i];
3424 }
3425 }
3426 }
3427 }
3428
3429 send_player_info_c(pplayer, nullptr);
3430}
3431
3432/**********************************************************************/
3435 void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
3436{
3437 set_as_ai(pplayer);
3438
3439 set_ai_level_directer(pplayer, skill_level);
3440 cancel_all_meetings(pplayer);
3441 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
3442 if (is_player_phase(pplayer, game.info.phase)) {
3443 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
3444 }
3445
3446 if (S_S_RUNNING == server_state()) {
3447 /* In case this was last player who has not pressed turn done. */
3448 check_for_full_turn_done();
3449 }
3450
3451 fc_assert(pplayer->ai_common.skill_level == skill_level);
3452}
3453
3454/**********************************************************************/
3457 void player_set_under_human_control(struct player *pplayer)
3458{
3459 set_as_human(pplayer);
3460
3461 if (pplayer->ai_common.skill_level == AI_LEVEL_AWAY) {
3462 pplayer->ai_common.skill_level = ai_level_invalid();
3463 }
3464
3465 CALL_PLR_AI_FUNC(lost_control, pplayer, pplayer);
3466
3467 /* Because AI "cheats" with government rates but humans shouldn't. */
3468 if (!game.info.is_new_game) {
3469 check_player_max_rates(pplayer);
3470 }
3471 cancel_all_meetings(pplayer);
3472}
3473
3474/**********************************************************************/
3477 void update_national_activities(struct player *pplayer, int old_gold)
3478{
3479 char buf[200 + MAX_LEN_NAME];
3480
3481 /* gold_upkeep_style check currently redundant, but something we need
3482 * once homeless_gold_upkeep retired. */
3483 if (game.info.gold_upkeep_style != GOLD_UPKEEP_CITY
3484 && game.info.homeless_gold_upkeep) {
3485 int free_uk[O_LAST];
3486
3487 memset(free_uk, 0, sizeof(free_uk));
3488 unit_list_iterate(pplayer->units, punit) {
3489 if (is_unit_homeless(punit)) {
3490 int gold = utype_upkeep_cost(unit_type_get(punit), pplayer, O_GOLD);
3491
3492 punit->upkeep[O_GOLD] = gold;
3493 punit->server.upkeep_paid[O_GOLD] = gold;
3494
3495 pplayer->economic.gold -= gold;
3496 }
3497 } unit_list_iterate_end;
3498 }
3499
3500 if (pplayer->economic.gold < 0) {
3501 switch (game.info.gold_upkeep_style) {
3502 case GOLD_UPKEEP_CITY:
3503 break;
3504 case GOLD_UPKEEP_MIXED:
3505 /* Nation pays for units. */
3506 player_balance_treasury_units(pplayer);
3507 break;
3508 case GOLD_UPKEEP_NATION:
3509 /* Nation pays for units and buildings. */
3510 player_balance_treasury_units_and_buildings(pplayer);
3511 break;
3512 }
3513 }
3514
3515 /* This test includes the cost of the units because
3516 * units are paid for in update_city_activity() or
3517 * player_balance_treasury_units(). */
3518 if (old_gold - (old_gold - pplayer->economic.gold) * 3 < 0) {
3519 notify_player(pplayer, nullptr, E_LOW_ON_FUNDS, ftc_server,
3520 _("WARNING, we're LOW on FUNDS %s."),
3521 ruler_title_for_player(pplayer, buf, sizeof(buf)));
3522 }
3523
3524#if 0
3525 /* Uncomment to unbalance the game, like in civ1 (CLG). */
3526 if (pplayer->got_tech && pplayer->research->researched > 0) {
3527 pplayer->research->researched = 0;
3528 }
3529#endif
3530
3531 if (pplayer->economic.infra_points < 0) {
3532 pplayer->economic.infra_points = 0;
3533 }
3534
3535 pplayer->history += nation_history_gain(pplayer);
3536
3537 research_get(pplayer)->researching_saved = A_UNKNOWN;
3538 /* Reduce the number of bulbs by the amount needed for tech upkeep and
3539 * check for finished research */
3540 update_bulbs(pplayer, -player_tech_upkeep(pplayer), TRUE, FALSE);
3541}
adv_data_close
void adv_data_close(struct player *pplayer)
Definition advdata.c:752
adv_data_init
void adv_data_init(struct player *pplayer)
Definition advdata.c:697
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:729
advdata.h
ai_name
const char * ai_name(const struct ai_type *ai)
Definition ai.c:335
ai_type_name_or_fallback
const char * ai_type_name_or_fallback(const char *orig_name)
Definition ai.c:346
ai_type_by_name
struct ai_type * ai_type_by_name(const char *search)
Definition ai.c:290
CALL_FUNC_EACH_AI
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:387
INCIDENT_WAR
@ INCIDENT_WAR
Definition ai.h:46
CALL_PLR_AI_FUNC
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:377
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:235
aiiface.h
ai_traits_close
void ai_traits_close(struct player *pplayer)
Definition aitraits.c:59
aitraits.h
n
#define n
Definition astring.c:77
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:1571
city_name_get
const char * city_name_get(const struct city *pcity)
Definition city.c:1128
city_unhappy
bool city_unhappy(const struct city *pcity)
Definition city.c:1618
city_celebrating
bool city_celebrating(const struct city *pcity)
Definition city.c:1637
cities_iterate_end
#define cities_iterate_end
Definition city.h:517
city_list_iterate_safe
#define city_list_iterate_safe(citylist, _city)
Definition city.h:522
city_list_iterate
#define city_list_iterate(citylist, pcity)
Definition city.h:508
city_tile
#define city_tile(_pcity_)
Definition city.h:564
cities_iterate
#define cities_iterate(pcity)
Definition city.h:512
city_owner
#define city_owner(_pcity_)
Definition city.h:563
city_list_iterate_end
#define city_list_iterate_end
Definition city.h:510
city_list_iterate_safe_end
#define city_list_iterate_safe_end
Definition city.h:544
city_map_update_empty
void city_map_update_empty(struct city *pcity, struct tile *ptile)
Definition citytools.c:3245
city_build_free_buildings
void city_build_free_buildings(struct city *pcity)
Definition citytools.c:1429
sync_cities
void sync_cities(void)
Definition citytools.c:3319
city_map_update_all_cities_for_player
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3353
remove_city
void remove_city(struct city *pcity)
Definition citytools.c:1700
remove_trade_route
struct trade_route * remove_trade_route(struct city *pc1, struct trade_route *proute, bool announce, bool source_gone)
Definition citytools.c:2911
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:1072
citytools.h
city_refresh_queue_add
void city_refresh_queue_add(struct city *pcity)
Definition cityturn.c:196
player_balance_treasury_units_and_buildings
bool player_balance_treasury_units_and_buildings(struct player *pplayer)
Definition cityturn.c:3203
player_balance_treasury_units
bool player_balance_treasury_units(struct player *pplayer)
Definition cityturn.c:3266
city_refresh_for_player
void city_refresh_for_player(struct player *pplayer)
Definition cityturn.c:181
city_refresh_queue_processing
void city_refresh_queue_processing(void)
Definition cityturn.c:212
cityturn.h
incite_cost
char * incite_cost
Definition comments.c:74
connection_detach
void connection_detach(struct connection *pconn, bool remove_unused_player)
Definition connecthand.c:809
connecthand.h
conn_list_iterate
#define conn_list_iterate(connlist, pconn)
Definition connection.h:108
conn_list_iterate_end
#define conn_list_iterate_end
Definition connection.h:110
player_culture
int player_culture(const struct player *plr)
Definition culture.c:49
nation_history_gain
int nation_history_gain(const struct player *pplayer)
Definition culture.c:66
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:74
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:698
reject_all_treaties
void reject_all_treaties(struct player *pplayer)
Definition diplhand.c:935
set_diplstate_type
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:122
cancel_all_meetings
void cancel_all_meetings(struct player *pplayer)
Definition diplhand.c:923
diplhand.h
could_intel_with_player
bool could_intel_with_player(const struct player *pplayer, const struct player *aplayer)
Definition diptreaty.c:84
diptreaty.h
get_city_bonus
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
get_player_bonus
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:828
extra_owner
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1114
extra_type_by_cause_iterate_end
#define extra_type_by_cause_iterate_end
Definition extras.h:339
extra_type_by_cause_iterate
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
Tech_type_id
int Tech_type_id
Definition fc_types.h:381
citizens
unsigned char citizens
Definition fc_types.h:392
Impr_type_id
int Impr_type_id
Definition fc_types.h:380
MAX_NUM_PLAYERS
#define MAX_NUM_PLAYERS
Definition fc_types.h:36
revolen_type
revolen_type
Definition fc_types.h:1293
REVOLEN_RANDOM
@ REVOLEN_RANDOM
Definition fc_types.h:1295
REVOLEN_RANDQUICK
@ REVOLEN_RANDQUICK
Definition fc_types.h:1297
REVOLEN_FIXED
@ REVOLEN_FIXED
Definition fc_types.h:1294
REVOLEN_QUICKENING
@ REVOLEN_QUICKENING
Definition fc_types.h:1296
Government_type_id
int Government_type_id
Definition fc_types.h:385
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
O_GOLD
@ O_GOLD
Definition fc_types.h:101
O_LAST
@ O_LAST
Definition fc_types.h:101
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:997
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:1076
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:62
is_player_phase
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:713
wld
struct world wld
Definition game.c:63
GAME_DEFAULT_REVOLUTION_LENGTH
#define GAME_DEFAULT_REVOLUTION_LENGTH
Definition game.h:736
GAME_MIN_CIVILWARSIZE
#define GAME_MIN_CIVILWARSIZE
Definition game.h:489
any_web_conns
#define any_web_conns()
Definition game.h:316
GAME_MAX_CIVILWARSIZE
#define GAME_MAX_CIVILWARSIZE
Definition game.h:490
crole_to_unit_type
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Definition gamehand.c:120
gamehand.h
government_name_translation
const char * government_name_translation(const struct government *pgovern)
Definition government.c:143
untargeted_revolution_allowed
bool untargeted_revolution_allowed(void)
Definition government.c:565
ruler_title_for_player
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Definition government.c:391
government_count
Government_type_id government_count(void)
Definition government.c:71
government_by_number
struct government * government_by_number(const Government_type_id gov)
Definition government.c:103
government_of_player
struct government * government_of_player(const struct player *pplayer)
Definition government.c:114
government_name_for_player
const char * government_name_for_player(const struct player *pplayer)
Definition government.c:154
can_change_to_government
bool can_change_to_government(struct player *pplayer, const struct government *gov)
Definition government.c:166
government_number
Government_type_id government_number(const struct government *pgovern)
Definition government.c:91
government_rule_name
const char * government_rule_name(const struct government *pgovern)
Definition government.c:133
government.h
persistent
static GtkWidget * persistent
Definition rallypointdlg.c:40
type
GType type
Definition repodlgs.c:1313
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:194
wonder_visible_to_player
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner, enum fc_tristate embassy)
Definition improvement.c:944
WONDER_NOT_BUILT
#define WONDER_NOT_BUILT
Definition improvement.h:145
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:148
map.h
square_iterate
#define square_iterate(nmap, center_tile, radius, tile_itr)
Definition map.h:377
square_iterate_end
#define square_iterate_end
Definition map.h:380
whole_map_iterate
#define whole_map_iterate(_map, _tile)
Definition map.h:531
whole_map_iterate_end
#define whole_map_iterate_end
Definition map.h:540
player_map_init
void player_map_init(struct player *pplayer)
Definition maphand.c:1225
map_claim_base
void map_claim_base(struct tile *ptile, struct extra_type *pextra, struct player *powner, struct player *ploser)
Definition maphand.c:2387
map_claim_ownership
void map_claim_ownership(struct tile *ptile, struct player *powner, struct tile *psource, bool claim_bases)
Definition maphand.c:2194
map_know_and_see_all
void map_know_and_see_all(struct player *pplayer)
Definition maphand.c:1200
give_map_from_player_to_player
void give_map_from_player_to_player(struct player *pfrom, struct player *pdest)
Definition maphand.c:384
remove_shared_vision
void remove_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1697
player_map_free
void player_map_free(struct player *pplayer)
Definition maphand.c:1241
map_calculate_borders
void map_calculate_borders(void)
Definition maphand.c:2360
remove_player_from_maps
void remove_player_from_maps(struct player *pplayer)
Definition maphand.c:1262
give_distorted_map
bool give_distorted_map(struct player *pfrom, struct player *pto, int prob, bool reveal_cities)
Definition maphand.c:2670
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:138
nation_count
Nation_type_id nation_count(void)
Definition nation.c:507
nation_number
Nation_type_id nation_number(const struct nation_type *pnation)
Definition nation.c:486
nation_leader_by_name
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Definition nation.c:267
nations_match
int nations_match(const struct nation_type *pnation1, const struct nation_type *pnation2, bool ignore_conflicts)
Definition nation.c:1206
nation_adjective_for_player
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:169
nation_set_index
int nation_set_index(const struct nation_set *pset)
Definition nation.c:699
nation_of_player
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
is_nation_playable
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:200
nation_color
const struct rgbcolor * nation_color(const struct nation_type *pnation)
Definition nation.c:682
nation_is_in_set
bool nation_is_in_set(const struct nation_type *pnation, const struct nation_set *pset)
Definition nation.c:837
nation_set_count
int nation_set_count(void)
Definition nation.c:691
nation_set_by_number
struct nation_set * nation_set_by_number(int id)
Definition nation.c:762
nation_set_by_setting_value
struct nation_set * nation_set_by_setting_value(const char *setting)
Definition nation.c:859
nation_index
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
nation_set_rule_name
const char * nation_set_rule_name(const struct nation_set *pset)
Definition nation.c:807
nation_barbarian_type
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:211
nation_plural_for_player
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:178
init_government_of_nation
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:659
nation.h
nation_list_iterate
#define nation_list_iterate(nationlist, pnation)
Definition nation.h:84
nation_sets_iterate_end
#define nation_sets_iterate_end
Definition nation.h:305
nation_sets_iterate
#define nation_sets_iterate(NAME_pset)
Definition nation.h:301
nations_iterate_end
#define nations_iterate_end
Definition nation.h:336
nation_list_iterate_end
#define nation_list_iterate_end
Definition nation.h:86
nations_iterate
#define nations_iterate(NAME_pnation)
Definition nation.h:333
NATION_NONE
#define NATION_NONE
Definition nation.h:33
NO_NATION_SELECTED
#define NO_NATION_SELECTED
Definition nation.h:30
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, pconn,...)
Definition packets.h:56
dsend_packet_player_remove
int dsend_packet_player_remove(struct connection *pc, int playerno)
Definition packets_gen.c:22441
send_packet_player_diplstate
int send_packet_player_diplstate(struct connection *pc, const struct packet_player_diplstate *packet)
Definition packets_gen.c:26656
send_packet_player_info
int send_packet_player_info(struct connection *pc, const struct packet_player_info *packet)
Definition packets_gen.c:24992
lsend_packet_nation_availability
void lsend_packet_nation_availability(struct conn_list *dest, const struct packet_nation_availability *packet)
Definition packets_gen.c:54313
player_slot_is_used
bool player_slot_is_used(const struct player_slot *pslot)
Definition player.c:448
player_new
struct player * player_new(struct player_slot *pslot)
Definition player.c:493
player_by_number
struct player * player_by_number(const int player_id)
Definition player.c:849
players_on_same_team
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1480
player_count
int player_count(void)
Definition player.c:817
cancel_pact_result
enum diplstate_type cancel_pact_result(enum diplstate_type oldstate)
Definition player.c:68
player_slot_count
int player_slot_count(void)
Definition player.c:418
player_slot_by_number
struct player_slot * player_slot_by_number(int player_id)
Definition player.c:463
player_get_expected_income
int player_get_expected_income(const struct player *pplayer)
Definition player.c:1286
player_number
int player_number(const struct player *pplayer)
Definition player.c:837
player_name
const char * player_name(const struct player *pplayer)
Definition player.c:895
player_clear
void player_clear(struct player *pplayer, bool full)
Definition player.c:669
player_slot_index
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
player_has_real_embassy
bool player_has_real_embassy(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:240
team_has_embassy
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
Definition player.c:220
player_set_color
void player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition player.c:648
player_index
int player_index(const struct player *pplayer)
Definition player.c:829
player_set_nation
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:861
pplayer_can_cancel_treaty
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
Definition player.c:98
player_diplstate_get
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:324
pplayers_allied
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1409
gives_shared_tiles
bool gives_shared_tiles(const struct player *me, const struct player *them)
Definition player.c:1497
gives_shared_vision
bool gives_shared_vision(const struct player *me, const struct player *them)
Definition player.c:1489
player_destroy
void player_destroy(struct player *pplayer)
Definition player.c:756
player.h
players_iterate_end
#define players_iterate_end
Definition player.h:539
dipl_reason
dipl_reason
Definition player.h:192
DIPL_SENATE_BLOCKING
@ DIPL_SENATE_BLOCKING
Definition player.h:193
DIPL_OK
@ DIPL_OK
Definition player.h:193
players_iterate
#define players_iterate(_pplayer)
Definition player.h:534
player_list_iterate
#define player_list_iterate(playerlist, pplayer)
Definition player.h:557
ANON_USER_NAME
#define ANON_USER_NAME
Definition player.h:48
is_barbarian
static bool is_barbarian(const struct player *pplayer)
Definition player.h:491
is_ai
#define is_ai(plr)
Definition player.h:232
player_list_iterate_end
#define player_list_iterate_end
Definition player.h:559
set_as_human
#define set_as_human(plr)
Definition player.h:233
players_iterate_alive_end
#define players_iterate_alive_end
Definition player.h:549
PLRCOL_PLR_RANDOM
@ PLRCOL_PLR_RANDOM
Definition player.h:54
PLRCOL_PLR_SET
@ PLRCOL_PLR_SET
Definition player.h:55
PLRCOL_NATION_ORDER
@ PLRCOL_NATION_ORDER
Definition player.h:57
PLRCOL_TEAM_ORDER
@ PLRCOL_TEAM_ORDER
Definition player.h:56
PLRCOL_PLR_ORDER
@ PLRCOL_PLR_ORDER
Definition player.h:53
set_as_ai
#define set_as_ai(plr)
Definition player.h:234
is_human
#define is_human(plr)
Definition player.h:231
players_iterate_alive
#define players_iterate_alive(_pplayer)
Definition player.h:544
handle_player_phase_done
void handle_player_phase_done(struct player *pplayer, int turn)
Definition plrhand.c:3180
send_nation_availability
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2642
handle_player_multiplier
void handle_player_multiplier(struct player *pplayer, int count, const int *multipliers)
Definition plrhand.c:3396
server_player_set_name
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2268
barbarian_count
int barbarian_count(void)
Definition plrhand.c:3200
send_player_all_c
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1129
send_player_remove_info_c
static void send_player_remove_info_c(const struct player_slot *pslot, struct conn_list *dest)
Definition plrhand.c:1079
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:1894
player_preferred_color
const struct rgbcolor * player_preferred_color(struct player *pplayer)
Definition plrhand.c:1673
player_update_last_war_action
void player_update_last_war_action(struct player *pplayer)
Definition plrhand.c:865
handle_player_attribute_chunk
void handle_player_attribute_chunk(struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
Definition plrhand.c:3162
player_status_add
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3216
normal_player_count
int normal_player_count(void)
Definition plrhand.c:3208
send_player_info_c_real
static void send_player_info_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1166
player_info_level
static enum plr_info_level player_info_level(struct player *plr, struct player *receiver)
Definition plrhand.c:1570
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:1527
player_set_under_human_control
void player_set_under_human_control(struct player *pplayer)
Definition plrhand.c:3457
maybe_claim_base
static void maybe_claim_base(struct tile *ptile, struct player *new_owner, struct player *old_owner)
Definition plrhand.c:823
playercolor_free
void playercolor_free(void)
Definition plrhand.c:3347
current_nationset
static struct nation_set * current_nationset(void)
Definition plrhand.c:2581
give_midgame_initial_units
void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
Definition plrhand.c:1870
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:1603
player_limit_to_max_rates
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:2057
civil_war_triggered
bool civil_war_triggered(struct player *pplayer)
Definition plrhand.c:2957
server_player_set_color
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Definition plrhand.c:1823
player_set_to_ai_mode
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Definition plrhand.c:3435
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:2168
player_delegation_active
bool player_delegation_active(const struct player *pplayer)
Definition plrhand.c:3270
player_info_thaw
void player_info_thaw(void)
Definition plrhand.c:1108
player_info_freeze
void player_info_freeze(void)
Definition plrhand.c:1099
player_by_user_delegated
struct player * player_by_user_delegated(const char *name)
Definition plrhand.c:3322
maybe_make_contact
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Definition plrhand.c:2362
handle_player_attribute_block
void handle_player_attribute_block(struct player *pplayer)
Definition plrhand.c:3172
send_nation_availability_real
static void send_nation_availability_real(struct conn_list *dest, bool nationset_change)
Definition plrhand.c:2626
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:2453
get_default_diplstate
static enum diplstate_type get_default_diplstate(const struct player *pplayer1, const struct player *pplayer2)
Definition plrhand.c:2285
playercolor_init
void playercolor_init(void)
Definition plrhand.c:3337
check_player_max_rates
void check_player_max_rates(struct player *pplayer)
Definition plrhand.c:776
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:1843
send_player_info_c
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1146
set_shuffled_players
void set_shuffled_players(int *shuffled_players)
Definition plrhand.c:2403
civil_war
struct player * civil_war(struct player *pplayer)
Definition plrhand.c:3007
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:3232
send_delegation_info
void send_delegation_info(const struct connection *pconn)
Definition plrhand.c:3278
handle_player_change_government
void handle_player_change_government(struct player *pplayer, Government_type_id government)
Definition plrhand.c:565
update_national_activities
void update_national_activities(struct player *pplayer, int old_gold)
Definition plrhand.c:3477
player_reply_dest
struct conn_list * player_reply_dest(struct player *pplayer)
Definition plrhand.c:1593
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:804
revolentype_length
static int revolentype_length(enum revolen_type rltype, struct government *gov)
Definition plrhand.c:515
player_status_check
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3224
civil_war_possible
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Definition plrhand.c:2910
playercolor_get
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3376
player_delegation_set
void player_delegation_set(struct player *pplayer, const char *username)
Definition plrhand.c:3254
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:2106
playercolor_count
int playercolor_count(void)
Definition plrhand.c:3386
shuffle_players
void shuffle_players(void)
Definition plrhand.c:2378
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:1324
server_remove_player
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1943
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:1618
send_player_diplstate_c_real
static void send_player_diplstate_c_real(struct player *src, struct conn_list *dest)
Definition plrhand.c:1228
handle_diplomacy_cancel_pact
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:880
make_contact
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2303
playercolor_add
void playercolor_add(struct rgbcolor *prgbcolor)
Definition plrhand.c:3366
update_capital
void update_capital(struct player *pplayer)
Definition plrhand.c:731
count_playable_nations
void count_playable_nations(void)
Definition plrhand.c:2599
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:1716
assign_player_colors
void assign_player_colors(void)
Definition plrhand.c:1734
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:1261
client_can_pick_nation
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2614
send_player_diplstate_c
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1212
split_player
static struct player * split_player(struct player *pplayer)
Definition plrhand.c:2759
shuffled_player
struct player * shuffled_player(int i)
Definition plrhand.c:2421
player_loot_player
void player_loot_player(struct player *pvictor, struct player *pvictim)
Definition plrhand.c:410
player_delegation_get
const char * player_delegation_get(const struct player *pplayer)
Definition plrhand.c:3241
nation_is_in_current_set
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2590
enter_war
void enter_war(struct player *pplayer, struct player *pplayer2)
Definition plrhand.c:848
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:549
fit_nationset_to_players
void fit_nationset_to_players(void)
Definition plrhand.c:2659
reset_all_start_commands
void reset_all_start_commands(bool plrchange)
Definition plrhand.c:2724
update_revolution
void update_revolution(struct player *pplayer)
Definition plrhand.c:672
plrhand.h
plr_info_level
plr_info_level
Definition plrhand.h:25
INFO_MEETING
@ INFO_MEETING
Definition plrhand.h:25
INFO_MINIMUM
@ INFO_MINIMUM
Definition plrhand.h:25
INFO_EMBASSY
@ INFO_EMBASSY
Definition plrhand.h:25
INFO_FULL
@ INFO_FULL
Definition plrhand.h:25
allowed_nations_iterate
#define allowed_nations_iterate(pnation)
Definition plrhand.h:69
allowed_nations_iterate_end
#define allowed_nations_iterate_end
Definition plrhand.h:73
rand.h
fc_rand
#define fc_rand(_size)
Definition rand.h:56
research_invention_set
enum tech_state research_invention_set(struct research *presearch, Tech_type_id tech, enum tech_state value)
Definition research.c:637
research_advance_rule_name
const char * research_advance_rule_name(const struct research *presearch, Tech_type_id tech)
Definition research.c:240
player_tech_upkeep
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1058
research_get
struct research * research_get(const struct player *pplayer)
Definition research.c:128
research_invention_state
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:619
research_update
void research_update(struct research *presearch)
Definition research.c:501
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:2015
is_ascii_name
bool is_ascii_name(const char *name)
Definition shared.c:283
remove_leading_trailing_spaces
void remove_leading_trailing_spaces(char *s)
Definition shared.c:444
shared.h
TRI_YES
@ TRI_YES
Definition shared.h:46
TRI_NO
@ TRI_NO
Definition shared.h:46
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:129
spacerace.h
spaceship_init
void spaceship_init(struct player_spaceship *ship)
Definition spaceship.c:96
spaceship.h
specialist.h
DEFAULT_SPECIALIST
#define DEFAULT_SPECIALIST
Definition specialist.h:43
x
struct sprite int x
Definition sprite_g.h:31
player_nation_defaults
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2618
game_was_started
bool game_was_started(void)
Definition srv_main.c:353
check_for_full_turn_done
void check_for_full_turn_done(void)
Definition srv_main.c:2253
server_state
enum server_states server_state(void)
Definition srv_main.c:337
srv_main.h
set_ai_level_direct
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2004
stdinhand.h
city
Definition city.h:320
city::capital
enum capital_type capital
Definition city.h:328
city::specialists
citizens specialists[SP_MAX]
Definition city.h:336
civ_game::contactturns
int contactturns
Definition game.h:137
civ_game::plr_colors
struct rgbcolor_list * plr_colors
Definition game.h:245
civ_game::start_units
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:189
civ_game::plrcolormode
enum plrcolor_mode plrcolormode
Definition game.h:128
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:177
civ_game::civilwarsize
int civilwarsize
Definition game.h:135
civ_game::savepalace
bool savepalace
Definition game.h:187
civ_game::nationset
char nationset[MAX_LEN_NAME]
Definition game.h:157
civ_game::server
struct civ_game::@31::@35 server
civ_game::max_players
int max_players
Definition game.h:156
civ_game::revolution_length
int revolution_length
Definition game.h:178
civ_game::government_during_revolution
struct government * government_during_revolution
Definition game.h:94
connection
Definition connection.h:136
connection::access_level
enum cmdlevel access_level
Definition connection.h:177
connection::self
struct conn_list * self
Definition connection.h:163
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:41
nation_type
Definition nation.h:98
nation_type::barb_type
enum barbarian_type barb_type
Definition nation.h:110
nation_type::no_startpos
bool no_startpos
Definition nation.h:148
nation_type::server
struct nation_type::@51::@53 server
packet_game_info::gameloss_style
enum gameloss_style gameloss_style
Definition packets_gen.h:238
packet_game_info::gold_upkeep_style
enum gold_upkeep_style gold_upkeep_style
Definition packets_gen.h:172
packet_game_info::citizen_nationality
bool citizen_nationality
Definition packets_gen.h:146
packet_game_info::homeless_gold_upkeep
bool homeless_gold_upkeep
Definition packets_gen.h:173
packet_game_info::is_new_game
bool is_new_game
Definition packets_gen.h:192
packet_game_info::civil_war_enabled
bool civil_war_enabled
Definition packets_gen.h:253
packet_game_info::skill_level
enum ai_level skill_level
Definition packets_gen.h:228
packet_game_info::revolentype
enum revolen_type revolentype
Definition packets_gen.h:175
packet_game_info::civil_war_bonus_unhappy
int civil_war_bonus_unhappy
Definition packets_gen.h:255
packet_game_info::turn
int turn
Definition packets_gen.h:247
packet_game_info::phase
int phase
Definition packets_gen.h:212
packet_game_info::persistent_ready
enum persistent_ready persistent_ready
Definition packets_gen.h:123
packet_game_info::civil_war_bonus_celebrating
int civil_war_bonus_celebrating
Definition packets_gen.h:254
packet_nation_availability
Definition packets_gen.h:1159
packet_nation_availability::ncount
int ncount
Definition packets_gen.h:1160
packet_nation_availability::is_pickable
bool is_pickable[MAX_NUM_NATIONS]
Definition packets_gen.h:1161
packet_nation_availability::nationset_change
bool nationset_change
Definition packets_gen.h:1162
packet_player_attribute_chunk
Definition packets_gen.h:589
packet_player_diplstate
Definition packets_gen.h:596
packet_player_diplstate::plr1
int plr1
Definition packets_gen.h:598
packet_player_diplstate::plr2
int plr2
Definition packets_gen.h:599
packet_player_info
Definition packets_gen.h:515
packet_player_info::ai_skill_level
enum ai_level ai_skill_level
Definition packets_gen.h:546
packet_player_info::phase_done
bool phase_done
Definition packets_gen.h:532
packet_player_info::is_alive
bool is_alive
Definition packets_gen.h:535
packet_player_info::is_male
bool is_male
Definition packets_gen.h:521
packet_player_info::luxury
int luxury
Definition packets_gen.h:540
packet_player_info::turns_alive
int turns_alive
Definition packets_gen.h:534
packet_player_info::color_red
int color_red
Definition packets_gen.h:555
packet_player_info::is_ready
bool is_ready
Definition packets_gen.h:531
packet_player_info::multiplier
int multiplier[MAX_NUM_MULTIPLIERS]
Definition packets_gen.h:561
packet_player_info::username
char username[MAX_LEN_NAME]
Definition packets_gen.h:518
packet_player_info::tech_upkeep
int tech_upkeep
Definition packets_gen.h:542
packet_player_info::style
int style
Definition packets_gen.h:527
packet_player_info::culture
int culture
Definition packets_gen.h:551
packet_player_info::flags
bv_plr_flags flags
Definition packets_gen.h:558
packet_player_info::mood
enum mood_type mood
Definition packets_gen.h:526
packet_player_info::color_green
int color_green
Definition packets_gen.h:556
packet_player_info::color_valid
bool color_valid
Definition packets_gen.h:553
packet_player_info::gives_shared_vision
bv_player gives_shared_vision
Definition packets_gen.h:548
packet_player_info::team
int team
Definition packets_gen.h:530
packet_player_info::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition packets_gen.h:552
packet_player_info::autoselect_weight
int autoselect_weight
Definition packets_gen.h:536
packet_player_info::was_created
bool was_created
Definition packets_gen.h:522
packet_player_info::target_government
Government_type_id target_government
Definition packets_gen.h:524
packet_player_info::multiplier_target
int multiplier_target[MAX_NUM_MULTIPLIERS]
Definition packets_gen.h:562
packet_player_info::is_connected
bool is_connected
Definition packets_gen.h:544
packet_player_info::unassigned_user
bool unassigned_user
Definition packets_gen.h:519
packet_player_info::multiplier_changed
int multiplier_changed[MAX_NUM_MULTIPLIERS]
Definition packets_gen.h:563
packet_player_info::gives_shared_tiles
bv_player gives_shared_tiles
Definition packets_gen.h:549
packet_player_info::nturns_idle
int nturns_idle
Definition packets_gen.h:533
packet_player_info::score
int score
Definition packets_gen.h:520
packet_player_info::multip_count
int multip_count
Definition packets_gen.h:560
packet_player_info::nation
Nation_type_id nation
Definition packets_gen.h:529
packet_player_info::science_cost
int science_cost
Definition packets_gen.h:543
packet_player_info::barbarian_type
enum barbarian_type barbarian_type
Definition packets_gen.h:547
packet_player_info::name
char name[MAX_LEN_NAME]
Definition packets_gen.h:517
packet_player_info::government
Government_type_id government
Definition packets_gen.h:523
packet_player_info::real_embassy
bv_player real_embassy
Definition packets_gen.h:525
packet_player_info::wonders
int wonders[B_LAST]
Definition packets_gen.h:559
packet_player_info::tax
int tax
Definition packets_gen.h:538
packet_player_info::music_style
int music_style
Definition packets_gen.h:528
packet_player_info::history
int history
Definition packets_gen.h:550
packet_player_info::science
int science
Definition packets_gen.h:539
packet_player_info::gold
int gold
Definition packets_gen.h:537
packet_player_info::revolution_finishes
int revolution_finishes
Definition packets_gen.h:545
packet_player_info::color_changeable
bool color_changeable
Definition packets_gen.h:554
packet_player_info::color_blue
int color_blue
Definition packets_gen.h:557
packet_player_info::infrapoints
int infrapoints
Definition packets_gen.h:541
packet_player_info::playerno
int playerno
Definition packets_gen.h:516
packet_scenario_info::startpos_nations
bool startpos_nations
Definition packets_gen.h:1617
packet_web_player_info_addition
Definition packets_gen.h:1892
player_ai::skill_level
enum ai_level skill_level
Definition player.h:116
player_ai::barbarian_type
enum barbarian_type barbarian_type
Definition player.h:122
player_ai::warmth
int warmth
Definition player.h:121
player_ai::science_cost
int science_cost
Definition player.h:119
player_ai::love
int love[MAX_NUM_PLAYER_SLOTS]
Definition player.h:124
player_ai::maxbuycost
int maxbuycost
Definition player.h:114
player_ai::frost
int frost
Definition player.h:121
player_diplstate
Definition player.h:198
player_diplstate::contact_turns_left
char contact_turns_left
Definition player.h:204
player_diplstate::type
enum diplstate_type type
Definition player.h:199
player_diplstate::has_reason_to_cancel
char has_reason_to_cancel
Definition player.h:203
player_economic
Definition player.h:62
player_economic::luxury
int luxury
Definition player.h:66
player_economic::science
int science
Definition player.h:65
player_economic::tax
int tax
Definition player.h:64
player_economic::infra_points
int infra_points
Definition player.h:67
player_economic::gold
int gold
Definition player.h:63
player_score::units_killed
int units_killed
Definition player.h:105
player_score::units_used
int units_used
Definition player.h:108
player_score::units_lost
int units_lost
Definition player.h:106
player_score::game
int game
Definition player.h:110
player_score::units_built
int units_built
Definition player.h:104
player_slot
Definition player.c:46
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:322
player::primary_capital_id
int primary_capital_id
Definition player.h:275
player::is_male
bool is_male
Definition player.h:257
player::wonders
int wonders[B_LAST]
Definition player.h:305
player::target_government
struct government * target_government
Definition player.h:259
player::autoselect_weight
int autoselect_weight
Definition player.h:299
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:302
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:314
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::gives_shared_tiles
bv_player gives_shared_tiles
Definition player.h:304
player::is_ready
bool is_ready
Definition player.h:262
player::server
struct player::@70::@72 server
player::history
int history
Definition player.h:316
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:312
player::unassigned_user
bool unassigned_user
Definition player.h:253
research
Definition research.h:39
research::researching_saved
Tech_type_id researching_saved
Definition research.h:62
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:50
tile::units
struct unit_list * units
Definition tile.h:58
tile::extras_owner
struct player * extras_owner
Definition tile.h:63
trade_route
Definition traderoutes.h:83
unit_type
Definition unittype.h:507
unit::upkeep
int upkeep[O_LAST]
Definition unit.h:150
unit::server
struct unit::@81::@84 server
unit::upkeep_paid
int upkeep_paid[O_LAST]
Definition unit.h:259
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:960
fc_strlcpy
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
cat_snprintf
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
fc_toupper
char fc_toupper(char c)
Definition support.c:1262
support.h
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
fc__fallthrough
#define fc__fallthrough
Definition support.h:119
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:249
A_NONE
#define A_NONE
Definition tech.h:43
A_UNSET
#define A_UNSET
Definition tech.h:48
A_UNKNOWN
#define A_UNKNOWN
Definition tech.h:49
advance_index_iterate
#define advance_index_iterate(_start, _index)
Definition tech.h:245
steal_a_tech
Tech_type_id steal_a_tech(struct player *pplayer, struct player *victim, Tech_type_id preferred)
Definition techtools.c:1233
send_research_info
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:293
update_bulbs
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech, bool free_bulbs)
Definition techtools.c:654
techtools.h
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_owner
#define tile_owner(_tile)
Definition tile.h:97
trade_routes_iterate_safe_end
#define trade_routes_iterate_safe_end
Definition traderoutes.h:157
trade_routes_iterate_safe
#define trade_routes_iterate_safe(c, proute)
Definition traderoutes.h:139
unit_owner
#define unit_owner(_pu)
Definition unit.h:396
is_unit_homeless
#define is_unit_homeless(_pu_)
Definition unit.h:395
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:1416
remove_allied_visibility
void remove_allied_visibility(struct player *pplayer, struct player *aplayer, const struct unit_list *seen_units)
Definition unittools.c:1451
resolve_unit_stacks
void resolve_unit_stacks(struct player *pplayer, struct player *aplayer, bool verbose)
Definition unittools.c:1401
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:1605
wipe_unit
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2139
unittools.h
unit_type_get
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
utype_upkeep_cost
int utype_upkeep_cost(const struct unit_type *ut, struct player *pplayer, Output_type_id otype)
Definition unittype.c:132
unit_has_type_flag
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Definition unittype.c:190
send_updated_vote_totals
void send_updated_vote_totals(struct conn_list *dest)
Definition voting.c:866
voting.h