Freeciv-3.2: /fast/freeciv/nightly/S3_2/server/plrhand.c Source File

Freeciv-3.2

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