Freeciv-3.1
Loading...
Searching...
No Matches
srv_main.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 "fc_prehdrs.h"
19
20#include <ctype.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <time.h>
25
26#ifdef HAVE_NETDB_H
27#include <netdb.h>
28#endif
29#ifdef HAVE_SYS_IOCTL_H
30#include <sys/ioctl.h>
31#endif
32#ifdef HAVE_SYS_TERMIO_H
33#include <sys/termio.h>
34#endif
35#ifdef FREECIV_HAVE_SYS_TYPES_H
36#include <sys/types.h>
37#endif
38#ifdef HAVE_TERMIOS_H
39#include <termios.h>
40#endif
41#ifdef HAVE_UNISTD_H
42#include <unistd.h>
43#endif
44
45/* dependencies/lua */
46#include "lua.h" /* lua_Integer */
47
48/* utility */
49#include "astring.h"
50#include "bitvector.h"
51#include "bugs.h"
52#include "capability.h"
53#include "fc_cmdline.h"
54#include "fciconv.h"
55#include "fcintl.h"
56#include "log.h"
57#include "mem.h"
58#include "netintf.h"
59#include "rand.h"
60#include "randseed.h"
61#include "registry.h"
62#include "support.h"
63#include "timing.h"
64
65/* common/aicore */
66#include "citymap.h"
67
68/* common */
69#include "achievements.h"
70#include "calendar.h"
71#include "capstr.h"
72#include "city.h"
73#include "culture.h"
74#include "dataio.h"
75#include "effects.h"
76#include "events.h"
77#include "fc_interface.h"
78#include "government.h"
79#include "map.h"
80#include "mapimg.h"
81#include "nation.h"
82#include "packets.h"
83#include "player.h"
84#include "research.h"
85#include "tech.h"
86#include "unitlist.h"
87#include "version.h"
88#include "victory.h"
89
90/* server */
91#include "aiiface.h"
92#include "animals.h"
93#include "auth.h"
94#include "barbarian.h"
95#include "cityhand.h"
96#include "citytools.h"
97#include "cityturn.h"
98#include "connecthand.h"
99#include "console.h"
100#include "fcdb.h"
101#include "diplhand.h"
102#include "edithand.h"
103#include "gamehand.h"
104#include "handchat.h"
105#include "maphand.h"
106#include "meta.h"
107#include "notify.h"
108#include "plrhand.h"
109#include "report.h"
110#include "ruleset.h"
111#include "sanitycheck.h"
112#include "score.h"
113#include "sernet.h"
114#include "settings.h"
115#include "spacerace.h"
116#include "srv_log.h"
117#include "stdinhand.h"
118#include "techtools.h"
119#include "unithand.h"
120#include "unittools.h"
121#include "voting.h"
122
123/* server/advisors */
124#include "advdata.h"
125#include "autosettlers.h"
126#include "advbuilding.h"
127#include "advspace.h"
128#include "infracache.h"
129
130/* server/savegame */
131#include "savemain.h"
132
133/* server/scripting */
134#include "script_server.h"
135#include "luascript_types.h"
136
137/* server/generator */
138#include "mapgen.h"
139#include "mapgen_utils.h"
140
141/* ai */
142#include "aitraits.h"
143#include "difficulty.h"
144
145#include "srv_main.h"
146
147static void end_turn(void);
148static void announce_player(struct player *pplayer);
149static void fc_interface_init_server(void);
150
151static enum known_type mapimg_server_tile_known(const struct tile *ptile,
152 const struct player *pplayer,
153 bool knowledge);
154static struct terrain
155 *mapimg_server_tile_terrain(const struct tile *ptile,
156 const struct player *pplayer, bool knowledge);
157static struct player *mapimg_server_tile_owner(const struct tile *ptile,
158 const struct player *pplayer,
159 bool knowledge);
160static struct player *mapimg_server_tile_city(const struct tile *ptile,
161 const struct player *pplayer,
162 bool knowledge);
163static struct player *mapimg_server_tile_unit(const struct tile *ptile,
164 const struct player *pplayer,
165 bool knowledge);
166
167static int mapimg_server_plrcolor_count(void);
168static struct rgbcolor *mapimg_server_plrcolor_get(int i);
169
170static void handle_observer_ready(struct connection *pconn);
171
172/* command-line arguments to server */
174
175/* server aggregate information */
177
178/* server state information */
179static enum server_states civserver_state = S_S_INITIAL;
180
181/* This global is checked deep down the netcode.
182 packets handling functions can set it to none-zero, to
183 force end-of-tick asap
184*/
186
188
189/* server initialized flag */
191
192/* time server processing at end-of-turn */
193static struct timer *eot_timer = NULL;
194
195static struct timer *between_turns = NULL;
196
197/**********************************************************************/
201{
202 if (game.server.seed_setting == 0) {
203 /* We strip the high bit for now because neither game file nor
204 server options can handle unsigned ints yet. - Cedric */
206#ifdef FREECIV_TESTMATIC
207 /* Log command to reproduce the gameseed */
208 log_testmatic("set gameseed %u", game.server.seed);
209#else /* FREECIV_TESTMATIC */
210 log_debug("Setting game.seed:%u", game.server.seed);
211#endif /* FREECIV_TESTMATIC */
212 } else {
214 }
215
216 if (!fc_rand_is_init()) {
218 }
219}
220
221/**********************************************************************/
224void srv_init(void)
225{
226 /* fc_interface_init_server() includes low level support like
227 * guaranteeing that fc_vsnprintf() will work after it,
228 * so this need to be early. */
230
231 i_am_server(); /* Tell to libfreeciv that we are server */
232
233#ifdef ENABLE_NLS
234 (void) bindtextdomain("freeciv-nations", get_locale_dir());
235#endif
236
237 /* This is before ai module initializations so that if ai module
238 * wants to use registry files, it can. */
240
241 /* We want this before any AI stuff */
243
244 /* This must be before command line argument parsing.
245 This allocates default ai, and we want that to take place before
246 loading additional ai modules from command line. */
247 ai_init();
248
249 /* init server arguments... */
250
254 srvarg.identity_name[0] = '\0';
255 srvarg.serverid[0] = '\0';
256
257 srvarg.bind_addr = NULL;
258#ifdef FREECIV_JSON_CONNECTION
259 srvarg.port = FREECIV_JSON_PORT;
260#else /* FREECIV_JSON_CONNECTION */
261 srvarg.port = DEFAULT_SOCK_PORT;
262#endif /* FREECIV_JSON_CONNECTION */
263
264 srvarg.bind_meta_addr = NULL;
265
267
268 srvarg.log_filename = NULL;
271 srvarg.load_filename[0] = '\0';
272 srvarg.script_filename = NULL;
275 srvarg.ruleset = NULL;
276
277 srvarg.quitidle = 0;
278
280 srvarg.fcdb_conf = NULL;
284
285 /* mark as initialized */
287
288 /* init character encodings. */
290#ifdef ENABLE_NLS
291 bind_textdomain_codeset("freeciv-nations", get_internal_encoding());
292#endif
293
294 /* Initialize callbacks. */
296
297 /* Initialize global mutexes */
299
300 /* done */
301 return;
302}
303
304/**********************************************************************/
307void handle_client_info(struct connection *pc, enum gui_type gui,
308 int emerg_version, const char *distribution)
309{
310 pc->client_gui = gui;
311 log_debug("%s's client has %s gui.", pc->username, gui_type_name(gui));
312 if (emerg_version > 0) {
313 log_debug("It's emergency release .%d", emerg_version);
314 }
315 if (strcmp(distribution, "")) {
316 log_debug("It comes from %s distribution.", distribution);
317 }
318}
319
320/**********************************************************************/
323enum server_states server_state(void)
324{
325 return civserver_state;
326}
327
328/**********************************************************************/
331void set_server_state(enum server_states newstate)
332{
333 civserver_state = newstate;
334}
335
336/**********************************************************************/
340{
341 return (!game.info.is_new_game || S_S_INITIAL != server_state());
342}
343
344/**********************************************************************/
354{
355 int candidates, defeated;
356 struct player *victor;
357 int winners = 0;
358 struct astring str = ASTRING_INIT;
359
360 /* Check for scenario victory; dead players can win if they are on a team
361 * with the winners. */
362 players_iterate(pplayer) {
363 if (player_status_check(pplayer, PSTATUS_WINNER)
364 || get_player_bonus(pplayer, EFT_VICTORY) > 0) {
365 if (winners) {
366 /* TRANS: Another entry in winners list (", the Tibetans") */
367 astr_add(&str, Q_("?winners:, the %s"),
368 nation_plural_for_player(pplayer));
369 } else {
370 /* TRANS: Beginning of the winners list ("the French") */
371 astr_add(&str, Q_("?winners:the %s"),
372 nation_plural_for_player(pplayer));
373 }
374 pplayer->is_winner = TRUE;
375 winners++;
376 }
378 if (winners) {
379 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
380 /* TRANS: There can be several winners listed */
381 _("Scenario victory to %s."), astr_str(&str));
382 log_normal(_("Scenario victory to %s."), astr_str(&str));
383 astr_free(&str);
384 return TRUE;
385 }
386 astr_free(&str);
387
388 /* Count candidates for the victory. */
389 candidates = 0;
390 defeated = 0;
391 victor = NULL;
392 /* Do not use player_iterate_alive here - dead player must be counted as
393 * defeated to end the game with a victory. */
394 players_iterate(pplayer) {
395 if (is_barbarian(pplayer)) {
396 continue;
397 }
398
399 if ((pplayer)->is_alive
400 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
401 candidates++;
402 victor = pplayer;
403 } else {
404 defeated++;
405 }
407
408 if (0 == candidates) {
409 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
410 _("Game is over."));
411 log_normal(_("Game is over."));
412 return TRUE;
413 } else {
414 if (0 < defeated) {
415 /* If nobody conceded the game, it mays be a solo game or a single team
416 * game. */
417 fc_assert(NULL != victor);
418
419 /* Quit if we have team victory. */
420 if (1 < team_count()) {
421 teams_iterate(pteam) {
422 const struct player_list *members = team_members(pteam);
423 int team_candidates = 0, team_defeated = 0;
424
425 if (1 == player_list_size(members)) {
426 /* This is not really a team, single players are handled below. */
427 continue;
428 }
429
430 player_list_iterate(members, pplayer) {
431 if (pplayer->is_alive
432 && !player_status_check((pplayer), PSTATUS_SURRENDER)) {
433 team_candidates++;
434 } else {
435 team_defeated++;
436 }
438
439 fc_assert(team_candidates + team_defeated
440 == player_list_size(members));
441
442 if (team_candidates == candidates && team_defeated < defeated) {
443 /* We need a player in a other team to conced the game here. */
444 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
445 _("Team victory to %s."),
446 team_name_translation(pteam));
447 log_normal(_("Team victory to %s."), team_name_translation(pteam));
448 /* All players of the team win, even dead and surrended ones. */
449 player_list_iterate(members, pplayer) {
450 pplayer->is_winner = TRUE;
452 return TRUE;
453 }
455 }
456 }
457
458 /* Check for allied victory. */
459 if (1 < candidates && victory_enabled(VC_ALLIED)) {
460 struct player_list *winner_list = player_list_new();
461
462 /* Try to build a winner list. */
463 players_iterate_alive(pplayer) {
464 if (is_barbarian(pplayer)
465 || player_status_check((pplayer), PSTATUS_SURRENDER)) {
466 continue;
467 }
468
469 player_list_iterate(winner_list, aplayer) {
470 if (!pplayers_allied(aplayer, pplayer)) {
471 player_list_destroy(winner_list);
472 winner_list = NULL;
473 break;
474 }
476
477 if (NULL == winner_list) {
478 break;
479 }
480 player_list_append(winner_list, pplayer);
482
483 if (NULL != winner_list) {
484 bool first = TRUE;
485
486 fc_assert(candidates == player_list_size(winner_list));
487
488 astr_init(&str);
489 player_list_iterate(winner_list, pplayer) {
490 if (first) {
491 /* TRANS: Beginning of the winners list ("the French") */
492 astr_add(&str, Q_("?winners:the %s"),
493 nation_plural_for_player(pplayer));
494 first = FALSE;
495 } else {
496 /* TRANS: Another entry in winners list (", the Tibetans") */
497 astr_add(&str, Q_("?winners:, the %s"),
498 nation_plural_for_player(pplayer));
499 }
500 pplayer->is_winner = TRUE;
502 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
503 /* TRANS: There can be several winners listed */
504 _("Allied victory to %s."), astr_str(&str));
505 log_normal(_("Allied victory to %s."), astr_str(&str));
506 astr_free(&str);
507 player_list_destroy(winner_list);
508 return TRUE;
509 }
510 }
511
512 /* Check for single player victory. */
513 if (1 == candidates && NULL != victor) {
514 bool found = FALSE; /* We need at least one enemy defeated. */
515
516 players_iterate(pplayer) {
517 if (pplayer != victor
518 && !is_barbarian(pplayer)
519 && (!pplayer->is_alive
520 || player_status_check((pplayer), PSTATUS_SURRENDER))
521 && pplayer->team != victor->team
523 || !pplayers_allied(victor, pplayer))) {
524 found = TRUE;
525 break;
526 }
528
529 if (found) {
530 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
531 _("Game ended in conquest victory for %s."), player_name(victor));
532 log_normal(_("Game ended in conquest victory for %s."), player_name(victor));
533 victor->is_winner = TRUE;
534 return TRUE;
535 }
536 }
537 }
538
539 /* Check for culture victory */
541 struct player *best = NULL;
542 int best_value = -1;
543 int second_value = -1;
544
545 players_iterate(pplayer) {
546 if (is_barbarian(pplayer) || !pplayer->is_alive) {
547 continue;
548 }
549
550 if (pplayer->score.culture > best_value) {
551 best = pplayer;
552 second_value = best_value;
553 best_value = pplayer->score.culture;
554 } else if (pplayer->score.culture > second_value) {
555 second_value = pplayer->score.culture;
556 }
558
559 if (best != NULL && best_value >= game.info.culture_vic_points
560 && best_value > second_value * (100 + game.info.culture_vic_lead) / 100) {
561 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
562 _("Game ended in cultural domination victory for %s."),
563 player_name(best));
564 log_normal(_("Game ended in cultural domination victory for %s."),
565 player_name(best));
566 best->is_winner = TRUE;
567
568 return TRUE;
569 }
570 }
571
572 /* Quit if we are past the turn limit. */
574 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
575 _("Game ended as the turn limit was exceeded."));
576 log_normal(_("Game ended as the turn limit was exceeded."));
577 return TRUE;
578 } else if (game.info.turn == game.server.end_turn) {
579 /* Give them a chance to decide to extend the game */
580 notify_conn(game.est_connections, NULL, E_GAME_END, ftc_server,
581 _("Notice: game will end at the end of this turn due "
582 "to 'endturn' server setting."));
583 }
584
585 /* Check for a spacerace win (and notify of imminent arrivals).
586 * Check this after checking turn limit, because we are checking for
587 * the spaceship arriving in the year corresponding to the turn
588 * that's about to start. */
589 {
590 int n, i;
591 struct player *arrivals[MAX_NUM_PLAYER_SLOTS];
592
593 n = rank_spaceship_arrival(arrivals);
594
595 for (i = 0; i < n; i++) {
596 struct player *pplayer = arrivals[i];
597 const struct player_list *members;
598 bool win;
599
600 if (game.info.year < (int)spaceship_arrival(pplayer)) {
601 /* We are into the future arrivals */
602 break;
603 }
604
605 /* Mark as arrived and notify everyone. */
606 spaceship_arrived(pplayer);
607
608 if (!game.server.endspaceship) {
609 /* Games does not end on spaceship arrival. At least print all the
610 * arrival messages. */
611 continue;
612 }
613
614 /* This player has won, now check if anybody else wins with them. */
615 members = team_members(pplayer->team);
616 win = FALSE;
617 player_list_iterate(members, pteammate) {
618 if (pplayer->is_alive
619 && !player_status_check((pteammate), PSTATUS_SURRENDER)) {
620 /* We need at least one player to be a winner candidate in the
621 * team. */
622 win = TRUE;
623 break;
624 }
626
627 if (!win) {
628 /* Let's try next arrival. */
629 continue;
630 }
631
632 if (1 < player_list_size(members)) {
633 notify_conn(NULL, NULL, E_GAME_END, ftc_server,
634 _("Team victory to %s."),
635 team_name_translation(pplayer->team));
636 /* All players of the team win, even dead and surrendered ones. */
637 player_list_iterate(members, pteammate) {
638 pteammate->is_winner = TRUE;
640 } else {
641 notify_conn(NULL, NULL, E_GAME_END, ftc_server,
642 _("Game ended in victory for %s."), player_name(pplayer));
643 pplayer->is_winner = TRUE;
644 }
645 return TRUE;
646 }
647
648 /* Print notice(s) of imminent arrival. These are not infallible
649 * (quite apart from risk of enemy action) because arrival is
650 * year-based, and some effect may change the timeline between
651 * now and the end of the next turn.
652 * (Also the order of messages will not always indicate tie-breaks,
653 * if the shuffled order is changed every turn, as it is for
654 * PMT_CONCURRENT games.) */
655 for (; i < n; i++) {
656 const struct player *pplayer = arrivals[i];
657 struct packet_game_info next_info = game.info; /* struct copy */
658
659 /* Advance the calendar in a throwaway copy of game.info. */
660 game_next_year(&next_info);
661
662 if (next_info.year < (int)spaceship_arrival(pplayer)) {
663 /* Even further in the future */
664 break;
665 }
666
667 notify_player(NULL, NULL, E_SPACESHIP, ftc_server,
668 _("Notice: the %s spaceship will likely arrive at "
669 "Alpha Centauri next turn."),
671 }
672 }
673
674 return FALSE;
675}
676
677/**********************************************************************/
682void send_all_info(struct conn_list *dest)
683{
684 conn_list_iterate(dest, pconn) {
685 if (conn_controls_player(pconn)) {
686 send_attribute_block(pconn->playing, pconn);
687 }
689
690 /* Resend player info because it could have more infos (e.g. embassy). */
691 send_player_all_c(NULL, dest);
692 researches_iterate(presearch) {
693 send_research_info(presearch, dest);
695 send_map_info(dest);
699 send_spaceship_info(NULL, dest);
700
701 cities_iterate(pcity) {
704}
705
706/**********************************************************************/
710static void do_reveal_effects(void)
711{
712 phase_players_iterate(pplayer) {
713 if (get_player_bonus(pplayer, EFT_REVEAL_CITIES) > 0) {
714 players_iterate(other_player) {
715 city_list_iterate(other_player->cities, pcity) {
716 map_show_tile(pplayer, pcity->tile);
719 }
720 if (get_player_bonus(pplayer, EFT_REVEAL_MAP) > 0) {
721 /* map_know_all will mark all unknown tiles as known and send
722 * tile, unit, and city updates as necessary. No other actions are
723 * needed. */
724 map_show_all(pplayer);
725 }
727}
728
729/**********************************************************************/
733static void do_have_contacts_effect(void)
734{
735 phase_players_iterate(pplayer) {
736 if (get_player_bonus(pplayer, EFT_HAVE_CONTACTS) > 0) {
737 players_iterate(pother) {
738 /* Note this gives pplayer contact with pother, but doesn't give
739 * pother contact with pplayer. This may cause problems in other
740 * parts of the code if we're not careful. */
741 make_contact(pplayer, pother, NULL);
743 }
745}
746
747/**********************************************************************/
750static void do_border_vision_effect(void)
751{
753 /* Border_Vision is useless. If borders are disabled there are no
754 * borders to see inside. If borders are seen they are seen already.
755 * The borders setting can't change after the game has started. */
756 return;
757 }
758
760 bool new_border_vision;
761
762 /* Check the Border_Vision effect for this player. */
763 new_border_vision = (0 < get_player_bonus(plr, EFT_BORDER_VISION));
764
765 if (new_border_vision != plr->server.border_vision) {
766 /* Border vision changed. */
767
768 /* Update the map */
769 map_set_border_vision(plr, new_border_vision);
770 }
772}
773
774/**********************************************************************/
778 int *current, int *accum, int *level,
779 int percent,
780 void (*upset_action_fn)(int))
781{
782 int count;
783
784 count = 0;
785 extra_type_iterate(cause) {
786 if (extra_causes_env_upset(cause, type)) {
787 whole_map_iterate(&(wld.map), ptile) {
788 if (tile_has_extra(ptile, cause)) {
789 count++;
790 }
792 }
794
795 *current = (count * percent) / 100;
796 *accum += count;
797 if (*accum < *level) {
798 *accum = 0;
799 } else {
800 *accum -= *level;
801 if (fc_rand((map_num_tiles() + 19) / 20) < *accum) {
802 upset_action_fn((wld.map.xsize / 10) + (wld.map.ysize / 10) + ((*accum) * 5));
803 *accum = 0;
804 *level += (map_num_tiles() + 999) / 1000;
805 }
806 }
807
808 log_debug("environmental_upset: type=%-4d current=%-2d "
809 "level=%-2d accum=%-2d", type, *current, *level, *accum);
810}
811
812/**********************************************************************/
815static void notify_illegal_armistice_units(struct player *phost,
816 struct player *pguest,
817 int turns_left)
818{
819 int nunits = 0;
820 struct unit *a_unit = NULL;
821
822 unit_list_iterate(pguest->units, punit) {
823 if (tile_owner(unit_tile(punit)) == phost && is_military_unit(punit)) {
824 nunits++;
825 a_unit = punit;
826 }
828 if (nunits > 0) {
829 struct astring unitstr = ASTRING_INIT;
830
831 astr_set(&unitstr,
832 /* TRANS: "... 2 military units in Norwegian territory." */
833 PL_("Warning: you still have %d military unit in %s territory.",
834 "Warning: you still have %d military units in %s territory.",
835 nunits),
836 nunits, nation_adjective_for_player(phost));
837 /* If there's one lousy unit left, we may as well include a link for it */
838 notify_player(pguest, nunits == 1 ? unit_tile(a_unit) : NULL,
839 E_DIPLOMACY, ftc_server,
840 /* TRANS: %s is another, separately translated sentence,
841 * ending in a full stop. */
842 PL_("%s Any such units will be disbanded in %d turn, "
843 "in accordance with peace treaty.",
844 "%s Any such units will be disbanded in %d turns, "
845 "in accordance with peace treaty.", turns_left),
846 astr_str(&unitstr), turns_left);
847 astr_free(&unitstr);
848 }
849}
850
851/**********************************************************************/
854static void remove_illegal_armistice_units(struct player *plr1,
855 struct player *plr2)
856{
857 /* Remove illegal units */
859 if (tile_owner(unit_tile(punit)) == plr2
861 notify_player(plr1, unit_tile(punit), E_DIPLOMACY, ftc_server,
862 _("Your %s was disbanded in accordance with "
863 "your peace treaty with the %s."),
866 wipe_unit(punit, ULR_ARMISTICE, NULL);
867 }
870 if (tile_owner(unit_tile(punit)) == plr1
872 notify_player(plr2, unit_tile(punit), E_DIPLOMACY, ftc_server,
873 _("Your %s was disbanded in accordance with "
874 "your peace treaty with the %s."),
877 wipe_unit(punit, ULR_ARMISTICE, NULL);
878 }
880}
881
882/**********************************************************************/
886static void update_diplomatics(void)
887{
890 struct player_diplstate *state = player_diplstate_get(plr1, plr2);
891
892 /* Players might just met when first of them was being handled
893 * (pact with third player changed and units got bounced next
894 * to second unit to form first contact)
895 * Do not decrease the counters for the other player yet in this turn */
896 if (state->first_contact_turn != game.info.turn) {
897 struct player_diplstate *state2 = player_diplstate_get(plr2, plr1);
898
899 state->has_reason_to_cancel = MAX(state->has_reason_to_cancel - 1, 0);
900 state->contact_turns_left = MAX(state->contact_turns_left - 1, 0);
901
902 if (state->type == DS_ARMISTICE
903 /* Don't count down if auto canceled this turn. Auto canceling
904 * happens in this loop. */
905 && state->auto_cancel_turn != game.info.turn) {
906 state->turns_left--;
907 if (state->turns_left <= 0) {
908 state->type = DS_PEACE;
909 state2->type = DS_PEACE;
910 state->turns_left = 0;
911 state2->turns_left = 0;
913 } else {
914 notify_illegal_armistice_units(plr1, plr2, state->turns_left);
915 }
916 }
917
918 if (state->type == DS_CEASEFIRE) {
919 state->turns_left--;
920 switch (state->turns_left) {
921 case 1:
922 notify_player(plr1, NULL, E_DIPLOMACY, ftc_server,
923 _("Concerned citizens point out that the cease-fire "
924 "with %s will run out soon."), player_name(plr2));
925 /* Message to plr2 will be done when plr1 and plr2 will be swapped.
926 * Else, we will get a message duplication. Note the case is not
927 * the below, because the state will be changed for both players to
928 * war. */
929 break;
930 case 0:
931 notify_player(plr1, NULL, E_DIPLOMACY, ftc_server,
932 _("The cease-fire with %s has run out. "
933 "You are now at war with the %s."),
934 player_name(plr2),
936 notify_player(plr2, NULL, E_DIPLOMACY, ftc_server,
937 _("The cease-fire with %s has run out. "
938 "You are now at war with the %s."),
939 player_name(plr1),
941 state->type = DS_WAR;
942 state2->type = DS_WAR;
943 state->turns_left = 0;
944 state2->turns_left = 0;
945
946 enter_war(plr1, plr2);
947
950 sync_cities();
951
952 /* Avoid love-love-hate triangles */
954 if (plr3 != plr1 && plr3 != plr2
955 && pplayers_allied(plr3, plr1)
956 && pplayers_allied(plr3, plr2)) {
957 struct player_diplstate *to1
958 = player_diplstate_get(plr3, plr1);
959 struct player_diplstate *from1
960 = player_diplstate_get(plr1, plr3);
961 struct player_diplstate *to2
962 = player_diplstate_get(plr3, plr2);
963 struct player_diplstate *from2
964 = player_diplstate_get(plr2, plr3);
965 const char *plr1name = player_name(plr1);
966 const char *plr2name = player_name(plr2);
967 bool cancel1;
968 bool cancel2;
969
970 if (players_on_same_team(plr3, plr1)) {
971 fc_assert(!players_on_same_team(plr3, plr2));
972
973 cancel1 = FALSE;
974 cancel2 = TRUE;
975
976 notify_player(plr3, NULL, E_TREATY_BROKEN, ftc_server,
977 _("The cease-fire between %s and %s has run out. "
978 "They are at war. You cancel your alliance "
979 "with %s."),
980 plr1name, plr2name, plr2name);
981 } else if (players_on_same_team(plr3, plr2)) {
982
983 cancel1 = TRUE;
984 cancel2 = FALSE;
985
986 notify_player(plr3, NULL, E_TREATY_BROKEN, ftc_server,
987 _("The cease-fire between %s and %s has run out. "
988 "They are at war. You cancel your alliance "
989 "with %s."),
990 plr1name, plr2name, plr1name);
991 } else {
992
993 cancel1 = TRUE;
994 cancel2 = TRUE;
995
996 notify_player(plr3, NULL, E_TREATY_BROKEN, ftc_server,
997 _("The cease-fire between %s and %s has run out. "
998 "They are at war. You cancel your alliance "
999 "with both."),
1000 player_name(plr1),
1001 player_name(plr2));
1002 }
1003
1004 if (cancel1) {
1005 /* Cancel the alliance. */
1006 to1->has_reason_to_cancel = 1;
1007 handle_diplomacy_cancel_pact(plr3, player_number(plr1), CLAUSE_ALLIANCE);
1008
1009 /* Avoid asymmetric turns_left for the armistice. */
1011 from1->auto_cancel_turn = game.info.turn;
1012
1013 /* Count down for this turn. */
1014 to1->turns_left--;
1015 from1->turns_left--;
1016 }
1017
1018 if (cancel2) {
1019 /* Cancel the alliance. */
1020 to2->has_reason_to_cancel = 1;
1021 handle_diplomacy_cancel_pact(plr3, player_number(plr2), CLAUSE_ALLIANCE);
1022
1023 /* Avoid asymmetric turns_left for the armistice. */
1025 from2->auto_cancel_turn = game.info.turn;
1026
1027 /* Count down for this turn. */
1028 to2->turns_left--;
1029 from2->turns_left--;
1030 }
1031 }
1033 break;
1034 }
1035 }
1036 }
1039}
1040
1041/**********************************************************************/
1048static void kill_dying_players(void)
1049{
1050 bool voter_died = FALSE;
1051
1052 players_iterate_alive(pplayer) {
1053 /* cities or units remain? */
1054 if (0 == city_list_size(pplayer->cities)
1055 && 0 == unit_list_size(pplayer->units)) {
1056 player_status_add(pplayer, PSTATUS_DYING);
1057 }
1058 /* also UTYF_GAMELOSS in unittools server_remove_unit() */
1059 if (player_status_check(pplayer, PSTATUS_DYING)) {
1060 /* Can't get more dead than this. */
1061 voter_died = voter_died || pplayer->is_connected;
1062 kill_player(pplayer);
1063 }
1065
1066 if (voter_died) {
1068 }
1069}
1070
1071/**********************************************************************/
1074static void ai_start_phase(void)
1075{
1076 phase_players_iterate(pplayer) {
1077 if (is_ai(pplayer)) {
1078 CALL_PLR_AI_FUNC(first_activities, pplayer, pplayer);
1079 }
1082}
1083
1084/**********************************************************************/
1089static void begin_turn(bool is_new_turn)
1090{
1091 log_debug("Begin turn");
1092
1094
1095 /* Reset this each turn. */
1096 if (is_new_turn) {
1100 }
1101 }
1102
1103 /* NB: Phase logic must match is_player_phase(). */
1104 switch (game.info.phase_mode) {
1105 case PMT_CONCURRENT:
1107 break;
1108 case PMT_PLAYERS_ALTERNATE:
1110 break;
1111 case PMT_TEAMS_ALTERNATE:
1113 break;
1114 default:
1115 log_error("Unrecognized phase mode %d in begin_turn().",
1118 break;
1119 }
1120 send_game_info(NULL);
1121
1122 if (is_new_turn) {
1123 script_server_signal_emit("turn_begin",
1124 (lua_Integer)game.info.turn,
1125 (lua_Integer)game.info.year);
1126 script_server_signal_emit("turn_started",
1127 game.info.turn > 0
1128 ? (lua_Integer)game.info.turn - 1
1129 : (lua_Integer)game.info.turn,
1130 (lua_Integer)game.info.year);
1131
1132 /* We build scores at the beginning of every turn. We have to
1133 * build them at the beginning so that the AI can use the data,
1134 * and we are sure to have it when we need it. */
1135 players_iterate(pplayer) {
1136 calc_civ_score(pplayer);
1139
1140 /* Retire useless barbarian units */
1141 players_iterate(pplayer) {
1142 unit_list_iterate_safe(pplayer->units, punit) {
1143 struct tile *ptile = punit->tile;
1144
1146 && fc_rand(100) < get_unit_bonus(punit, EFT_RETIRE_PCT)) {
1147 notify_player(pplayer, ptile, E_UNIT_LOST_MISC, ftc_server,
1148 /* TRANS: %s is a unit type */
1149 _("%s retired!"), unit_tile_link(punit));
1150 wipe_unit(punit, ULR_RETIRED, NULL);
1151 continue;
1152 }
1155 }
1156
1157 /* find out if users attached to players have been attached to those players
1158 * for long enough. The first user to do so becomes "associated" to that
1159 * player for ranking purposes. */
1160 players_iterate(pplayer) {
1161 if (pplayer->unassigned_ranked
1162 && pplayer->user_turns++ > TURNS_NEEDED_TO_RANK
1163 && pplayer->is_alive) {
1164 sz_strlcpy(pplayer->ranked_username, pplayer->username);
1165 pplayer->unassigned_ranked = pplayer->unassigned_user;
1166 }
1168
1169 if (is_new_turn) {
1170 /* See if the value of fog of war has changed */
1172 if (game.info.fogofwar) {
1175 } else {
1178 }
1179 }
1180
1181 if (game.info.phase_mode == PMT_CONCURRENT) {
1182 log_debug("Shuffleplayers");
1184 }
1185
1186 game.info.phase = 0;
1187 }
1188
1189 sanity_check();
1190}
1191
1192/**********************************************************************/
1196static void begin_phase(bool is_new_phase)
1197{
1198 log_debug("Begin phase");
1199
1201
1202 phase_players_iterate(pplayer) {
1203 if (is_new_phase || !game.server.turnblock) {
1204 /* Otherwise respect what was loaded from the savegame. */
1205 pplayer->phase_done = FALSE;
1206 }
1207 pplayer->ai_phase_done = FALSE;
1209 send_player_all_c(NULL, NULL);
1210
1212
1213 if (!is_new_phase || game.info.turn == FIRST_TURN) {
1214 /* Starting from a savegame or from the very beginning */
1218 }
1219
1220 /* Must be the first thing as it is needed for lots of functions below! */
1221 phase_players_iterate(pplayer) {
1222 /* human players also need this for building advice */
1223 adv_data_phase_init(pplayer, is_new_phase);
1224 CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, is_new_phase);
1226
1227 if (is_new_phase) {
1228 /* Unit "end of turn" activities - of course these actually go at
1229 * the start of the turn! */
1230 whole_map_iterate(&(wld.map), ptile) {
1231 if (ptile->placing != NULL) {
1232 struct player *owner = NULL;
1233
1235 owner = tile_owner(ptile);
1236 } else {
1237 struct city *pcity = tile_worked(ptile);
1238
1239 if (pcity != NULL) {
1240 owner = city_owner(pcity);
1241 }
1242 }
1243
1244 if (owner == NULL) {
1245 /* Abandoned extra placing, clear it. */
1246 ptile->placing = NULL;
1247 } else {
1249 fc_assert(ptile->infra_turns > 0);
1250
1251 ptile->infra_turns--;
1252 if (ptile->infra_turns <= 0) {
1253 create_extra(ptile, ptile->placing, owner);
1254 ptile->placing = NULL;
1255
1256 /* Since extra has been added, tile is certainly
1257 * sent by update_tile_knowledge() including the
1258 * placing info, though it would not sent it if placing
1259 * were the only thing changed. */
1260 update_tile_knowledge(ptile);
1261 }
1262 }
1263 }
1264 }
1266
1267 phase_players_iterate(pplayer) {
1268 update_unit_activities(pplayer);
1269 flush_packets();
1271
1272 /* Execute orders after activities have been completed (roads built,
1273 * pillage done, etc.). */
1274 phase_players_iterate(pplayer) {
1275 int plrid = player_number(pplayer);
1276
1277 script_server_signal_emit("player_phase_begin", pplayer, is_new_phase);
1278 if (player_by_number(plrid) != pplayer) {
1279 /* Removed */
1280 continue;
1281 }
1282 execute_unit_orders(pplayer);
1283 flush_packets();
1285
1286 phase_players_iterate(pplayer) {
1287 city_tc_effect_refresh(pplayer);
1288 unit_tc_effect_refresh(pplayer);
1290
1291 phase_players_iterate(pplayer) {
1294
1295 flush_packets();
1296 }
1297
1298 phase_players_iterate(pplayer) {
1299 log_debug("beginning player turn for #%d (%s)",
1300 player_number(pplayer), player_name(pplayer));
1301 if (is_human(pplayer)) {
1302 building_advisor(pplayer);
1303 }
1305
1306 phase_players_iterate(pplayer) {
1307 send_player_cities(pplayer);
1309
1310 flush_packets(); /* to curb major city spam */
1312
1314 update_revolution(pplayer);
1315 update_capital(pplayer);
1317
1318 if (is_new_phase) {
1319 /* Try to avoid hiding events under a diplomacy dialog */
1320 phase_players_iterate(pplayer) {
1321 if (is_ai(pplayer)) {
1322 CALL_PLR_AI_FUNC(diplomacy_actions, pplayer, pplayer);
1323 }
1325
1326 log_debug("Aistartturn");
1328 } else {
1329 phase_players_iterate(pplayer) {
1330 if (is_ai(pplayer)) {
1331 CALL_PLR_AI_FUNC(restart_phase, pplayer, pplayer);
1332 }
1334 }
1335
1336 sanity_check();
1337
1343 send_game_info(NULL);
1344
1345 if (game.server.num_phases == 1) {
1346 /* All players in the same phase.
1347 * This means that AI has been handled above, and server
1348 * will be responsive again */
1350 }
1351}
1352
1353/**********************************************************************/
1357static void end_phase(void)
1358{
1359 log_debug("Endphase");
1360
1361 /*
1362 * This empties the client Messages window; put this before
1363 * everything else below, since otherwise any messages from the
1364 * following parts get wiped out before the user gets a chance to
1365 * see them. --dwp
1366 */
1367 phase_players_iterate(pplayer) {
1368 /* Unlike the start_phase packet we only send this one to the active
1369 * player. */
1370 lsend_packet_end_phase(pplayer->connections);
1372
1373 /* Enact any policy changes.
1374 * Do this first so that following end-phase activities take the
1375 * change into account. */
1376 phase_players_iterate(pplayer) {
1377 multipliers_iterate(pmul) {
1378 int idx = multiplier_index(pmul);
1379
1380 if (!multiplier_can_be_changed(pmul, pplayer)) {
1381 if (pplayer->multipliers[idx].value != pmul->def) {
1382 notify_player(pplayer, NULL, E_MULTIPLIER, ftc_server,
1383 _("%s restored to the default value %d"),
1385 pmul->def);
1386 pplayer->multipliers[idx].value = pmul->def;
1387 pplayer->multipliers[idx].changed = game.info.turn;
1388 }
1389 } else {
1390 if (pplayer->multipliers[idx].value != pplayer->multipliers[idx].target) {
1391 notify_player(pplayer, NULL, E_MULTIPLIER, ftc_server,
1392 _("%s now at value %d"),
1394 pplayer->multipliers[idx].target);
1395
1396 pplayer->multipliers[idx].value = pplayer->multipliers[idx].target;
1397 pplayer->multipliers[idx].changed = game.info.turn;
1398 }
1399 }
1402
1403 phase_players_iterate(pplayer) {
1404 struct research *presearch = research_get(pplayer);
1405
1406 if (A_UNSET == presearch->researching) {
1407 Tech_type_id next_tech = research_goal_step(presearch,
1408 presearch->tech_goal);
1409
1410 if (A_UNSET != next_tech) {
1411 choose_tech(presearch, next_tech);
1412 } else {
1413 choose_random_tech(presearch);
1414 }
1415 /* Add the researched bulbs to the pool; do *NOT* check for finished
1416 * research */
1417 update_bulbs(pplayer, 0, FALSE);
1418 }
1420
1421 /* Freeze sending of cities. */
1423
1424 /* AI end of turn activities */
1425 players_iterate(pplayer) {
1426 unit_list_iterate(pplayer->units, punit) {
1427 CALL_PLR_AI_FUNC(unit_turn_end, pplayer, punit);
1430 phase_players_iterate(pplayer) {
1431 auto_settlers_player(pplayer);
1432 if (is_ai(pplayer)) {
1433 CALL_PLR_AI_FUNC(last_activities, pplayer, pplayer);
1434 }
1436
1437 /* Refresh cities */
1438 phase_players_iterate(pplayer) {
1439 research_get(pplayer)->got_tech = FALSE;
1440 research_get(pplayer)->got_tech_multi = FALSE;
1442
1444 int plrid = player_number(pplayer);
1445
1446 do_tech_parasite_effect(pplayer);
1447 script_server_signal_emit("player_alive_phase_end", pplayer);
1448 if (player_by_number(plrid) != pplayer) {
1449 /* removed */
1450 continue;
1451 }
1452 if (!pplayer->is_alive) {
1453 /* died */
1454 continue;
1455 }
1456 player_restore_units(pplayer);
1457
1458 /* If player finished spaceship parts last turn already, and didn't place them
1459 * during this entire turn, autoplace them. */
1460 if (adv_spaceship_autoplace(pplayer, &pplayer->spaceship)) {
1461 notify_player(pplayer, NULL, E_SPACESHIP, ftc_server,
1462 _("Automatically placed spaceship parts that were still not placed."));
1463 }
1464
1465 update_city_activities(pplayer);
1467 pplayer->history += nation_history_gain(pplayer);
1469 /* reduce the number of bulbs by the amount needed for tech upkeep and
1470 * check for finished research */
1471 update_bulbs(pplayer, -player_tech_upkeep(pplayer), TRUE);
1472 flush_packets();
1474
1475 /* Some player/global effect may have changed cities' vision range */
1476 phase_players_iterate(pplayer) {
1479
1481
1482 /* Unfreeze sending of cities. */
1484
1485 phase_players_iterate(pplayer) {
1486 send_player_cities(pplayer);
1488 flush_packets(); /* to curb major city spam */
1489
1493
1494 phase_players_iterate(pplayer) {
1495 int plrid = player_number(pplayer);
1496
1497 script_server_signal_emit("player_phase_end", pplayer);
1498 if (player_by_number(plrid) != pplayer) {
1499 /* removed */
1500 continue;
1501 }
1502 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1503 /* This has to be after all access to advisor data. */
1504 /* We used to run this for ai players only, but data phase
1505 is initialized for human players also. */
1506 adv_data_phase_done(pplayer);
1508}
1509
1510/**********************************************************************/
1513static void end_turn(void)
1514{
1515 log_debug("Endturn");
1516
1517 /* Hack: because observer players never get an end-phase packet we send
1518 * one here. */
1520 if (NULL == pconn->playing) {
1521 send_packet_end_phase(pconn);
1522 }
1524
1526
1528
1529#ifdef FREECIV_DEBUG
1530 /* Output some AI measurement information
1531 * log_debug() means that the values would never be used outside FREECIV_DEBUG
1532 * build even if we calculated them. */
1533 players_iterate(pplayer) {
1534 int food = 0, shields = 0, trade = 0, settlers = 0;
1535
1536 if (!is_ai(pplayer) || is_barbarian(pplayer)) {
1537 continue;
1538 }
1539
1540 unit_list_iterate(pplayer->units, punit) {
1542 settlers++;
1543 }
1545
1546 city_list_iterate(pplayer->cities, pcity) {
1547 shields += pcity->prod[O_SHIELD];
1548 food += pcity->prod[O_FOOD];
1549 trade += pcity->prod[O_TRADE];
1551
1552 log_debug("%s T%d cities:%d pop:%d food:%d prod:%d "
1553 "trade:%d settlers:%d units:%d", player_name(pplayer),
1554 game.info.turn, city_list_size(pplayer->cities),
1555 total_player_citizens(pplayer), food, shields, trade,
1556 settlers, unit_list_size(pplayer->units));
1557
1559#endif /* FREECIV_DEBUG */
1560
1561 log_debug("Season of native unrests");
1562 summon_barbarians(); /* wild guess really, no idea where to put it, but
1563 * I want to give them chance to move their units */
1564
1565 if (game.server.migration) {
1566 log_debug("Season of migrations");
1567 if (check_city_migrations()) {
1568 /* Make sure everyone has updated information about BOTH ends of the
1569 * migration movements. */
1570 players_iterate(plr) {
1571 city_list_iterate(plr->cities, pcity) {
1572 send_city_info(NULL, pcity);
1575 }
1576 }
1577
1579
1580 /* Check for new achievements during the turn.
1581 * This is not within phase, as multiple players may
1582 * achieve at the same turn and everyone deserves equal opportunity
1583 * to win. */
1585 struct player_list *achievers = player_list_new();
1586 struct player *first = achievement_plr(ach, achievers);
1587 struct packet_achievement_info pack;
1588
1589 pack.id = achievement_index(ach);
1590 pack.gained = TRUE;
1591
1592 if (first != NULL) {
1593 notify_player(first, NULL, E_ACHIEVEMENT, ftc_server,
1594 "%s", achievement_first_msg(ach));
1595
1596 pack.first = TRUE;
1597
1598 lsend_packet_achievement_info(first->connections, &pack);
1599
1600 script_server_signal_emit("achievement_gained", ach, first, TRUE);
1601
1602 }
1603
1604 pack.first = FALSE;
1605
1606 if (!ach->unique) {
1607 player_list_iterate(achievers, pplayer) {
1608 /* Message already sent to first one */
1609 if (pplayer != first) {
1610 notify_player(pplayer, NULL, E_ACHIEVEMENT, ftc_server,
1611 "%s", achievement_later_msg(ach));
1612
1613 lsend_packet_achievement_info(pplayer->connections, &pack);
1614
1615 script_server_signal_emit("achievement_gained", ach, pplayer,
1616 FALSE);
1617 }
1619 }
1620
1621 player_list_destroy(achievers);
1623
1624 if (game.info.global_warming) {
1630 }
1631
1632 if (game.info.nuclear_winter) {
1638 }
1639
1640 /* Handle disappearing extras before appearing extras ->
1641 * Extra never appears only to disappear at the same turn,
1642 * but it can disappear and reappear. */
1643 extra_type_by_rmcause_iterate(ERM_DISAPPEARANCE, pextra) {
1644 whole_map_iterate(&(wld.map), ptile) {
1645 if (tile_has_extra(ptile, pextra)
1646 && fc_rand(10000) < pextra->disappearance_chance
1647 && can_extra_disappear(pextra, ptile)) {
1648 tile_extra_rm_apply(ptile, pextra);
1649
1650 update_tile_knowledge(ptile);
1651
1652 if (tile_owner(ptile) != NULL) {
1653 /* TODO: Should notify players nearby even when borders disabled,
1654 * like in case of barbarian uprising */
1655 notify_player(tile_owner(ptile), ptile,
1656 E_SPONTANEOUS_EXTRA, ftc_server,
1657 /* TRANS: Small Fish disappears from (32, 72). */
1658 _("%s disappears from %s."),
1659 extra_name_translation(pextra),
1660 tile_link(ptile));
1661 }
1662
1663 /* Activities at the target tile and its neighbors may now
1664 * be illegal because of present reqs. */
1666 }
1669
1670 extra_type_by_cause_iterate(EC_APPEARANCE, pextra) {
1671 whole_map_iterate(&(wld.map), ptile) {
1672 if (!tile_has_extra(ptile, pextra)
1673 && fc_rand(10000) < pextra->appearance_chance
1674 && can_extra_appear(pextra, ptile)) {
1675
1676 tile_extra_apply(ptile, pextra);
1677
1678 update_tile_knowledge(ptile);
1679
1680 if (tile_owner(ptile) != NULL) {
1681 /* TODO: Should notify players nearby even when borders disabled,
1682 * like in case of barbarian uprising */
1683 notify_player(tile_owner(ptile), ptile,
1684 E_SPONTANEOUS_EXTRA, ftc_server,
1685 /* TRANS: Small Fish appears to (32, 72). */
1686 _("%s appears to %s."),
1687 extra_name_translation(pextra),
1688 tile_link(ptile));
1689 }
1690
1691 /* Activities at the target tile and its neighbors may now
1692 * be illegal because of !present reqs. */
1694 }
1697
1700 settings_turn();
1702 voting_turn();
1704
1705 log_debug("Gamenextyear");
1707 players_iterate_alive(pplayer) {
1708 pplayer->turns_alive++;
1710
1711 log_debug("Updatetimeout");
1713
1714 log_debug("Sendgameinfo");
1715 send_game_info(NULL);
1716
1717 log_debug("Sendplayerinfo");
1718 send_player_all_c(NULL, NULL);
1719
1720 log_debug("Sendresearchinfo");
1721 researches_iterate(presearch) {
1722 send_research_info(presearch, NULL);
1724
1725 log_debug("Sendyeartoclients");
1727}
1728
1729/**********************************************************************/
1732void save_game_auto(const char *save_reason, enum autosave_type type)
1733{
1734 char filename[512];
1735 const char *reason_filename = NULL;
1736
1737 if (!(game.server.autosaves & (1 << type))) {
1738 return;
1739 }
1740
1741 switch (type) {
1742 case AS_TURN:
1743 reason_filename = NULL;
1744 break;
1745 case AS_GAME_OVER:
1746 reason_filename = "final";
1747 break;
1748 case AS_QUITIDLE:
1749 reason_filename = "quitidle";
1750 break;
1751 case AS_INTERRUPT:
1752 reason_filename = "interrupted";
1753 break;
1754 case AS_TIMER:
1755 reason_filename = "timer";
1756 break;
1757 }
1758
1759 fc_assert(256 > strlen(game.server.save_name));
1760
1761 if (type != AS_TIMER) {
1762 generate_save_name(game.server.save_name, filename, sizeof(filename),
1763 reason_filename);
1764 } else {
1765 fc_snprintf(filename, sizeof(filename), "%s-timer", game.server.save_name);
1766 }
1767 save_game(filename, save_reason, FALSE);
1768}
1769
1770/**********************************************************************/
1773void start_game(void)
1774{
1775 if (S_S_INITIAL != server_state()) {
1776 con_puts(C_SYNTAX, _("The game is already running."));
1777 return;
1778 }
1779
1780 /* Remove ALLOW_CTRL from whoever has it (gotten from 'first'). */
1782 if (pconn->access_level == ALLOW_CTRL) {
1783 notify_conn(NULL, NULL, E_SETTING, ftc_server,
1784 _("%s lost control cmdlevel on "
1785 "game start. Use voting from now on."),
1786 pconn->username);
1787 conn_set_access(pconn, ALLOW_BASIC, FALSE);
1788 }
1791
1792 con_puts(C_OK, _("Starting game."));
1793
1794 /* Prevent problems with commands that only make sense in pregame. */
1796
1797 /* This value defines if the player data should be saved for a scenario. It
1798 * is only FALSE if the editor was used to set it to this value. For
1799 * such scenarios it has to be reset at game start so that player data
1800 * is saved. */
1802
1804 /* There's no stateful packet set to client until srv_ready(). */
1805}
1806
1807/**********************************************************************/
1810void server_quit(void)
1811{
1812 if (server_state() == S_S_RUNNING) {
1813 /* Quitting mid-game. */
1814
1815 phase_players_iterate(pplayer) {
1816 CALL_PLR_AI_FUNC(phase_finished, pplayer, pplayer);
1817 /* This has to be after all access to advisor data. */
1818 /* We used to run this for ai players only, but data phase
1819 is initialized for human players also. */
1820 adv_data_phase_done(pplayer);
1822 }
1823
1825
1826 if (game.server.save_timer != NULL) {
1828 game.server.save_timer = NULL;
1829 }
1830 if (between_turns != NULL) {
1832 between_turns = NULL;
1833 }
1834 if (eot_timer != NULL) {
1836 }
1837 set_server_state(S_S_OVER);
1838 mapimg_free();
1840 diplhand_free();
1841 voting_free();
1843 ai_timer_free();
1844 if (game.server.phase_timer != NULL) {
1846 game.server.phase_timer = NULL;
1847 }
1848 if (game.server.save_timer != NULL) {
1850 game.server.save_timer = NULL;
1851 }
1852
1853#ifdef HAVE_FCDB
1854 if (srvarg.fcdb_enabled) {
1855 /* If freeciv database has been initialized */
1856 fcdb_free();
1857 }
1858#endif /* HAVE_FCDB */
1859
1860 settings_free();
1862 edithand_free();
1863 voting_free();
1867 CALL_FUNC_EACH_AI(module_close);
1872 con_log_close();
1875
1876 exit(EXIT_SUCCESS);
1877}
1878
1879/**********************************************************************/
1883{
1884 struct conn_list *dest = pconn->self;
1885
1886 if (S_S_RUNNING != server_state() && S_S_OVER != server_state()) {
1887 log_error("Got a report request %d before game start", type);
1888 return;
1889 }
1890
1891 if (NULL == pconn->playing && !pconn->observer) {
1892 log_error("Got a report request %d from detached connection", type);
1893 return;
1894 }
1895
1896 switch (type) {
1899 return;
1902 return;
1903 case REPORT_DEMOGRAPHIC:
1904 report_demographics(pconn);
1905 return;
1907 report_achievements(pconn);
1908 return;
1909 }
1910
1911 notify_conn(dest, NULL, E_BAD_COMMAND, ftc_server,
1912 _("request for unknown report (type %d)"), type);
1913}
1914
1915/**********************************************************************/
1919{
1921}
1922
1923/**********************************************************************/
1927{
1929}
1930
1931/**********************************************************************/
1934static bool identity_number_is_used(int id)
1935{
1936 return BV_ISSET(identity_numbers_used, id);
1937}
1938
1939/**********************************************************************/
1943{
1944 server.identity_number = (server.identity_number + 1) % IDENTITY_NUMBER_SIZE;
1945 return server.identity_number;
1946}
1947
1948/**********************************************************************/
1953{
1954 int retries = 0;
1955
1957 /* try again */
1958 if (++retries >= IDENTITY_NUMBER_SIZE) {
1959 /* Always fails. */
1961 "Exhausted city and unit numbers!");
1962 }
1963 }
1964 identity_number_reserve(server.identity_number);
1965 return server.identity_number;
1966}
1967
1968/**********************************************************************/
1975{
1977}
1978
1979/**********************************************************************/
1983bool server_packet_input(struct connection *pconn, void *packet, int type)
1984{
1985 struct player *pplayer;
1986
1987 /* a NULL packet can be returned from receive_packet_goto_route() */
1988 if (!packet) {
1989 return TRUE;
1990 }
1991
1992 /*
1993 * Old pre-delta clients (before 2003-11-28) send a
1994 * PACKET_LOGIN_REQUEST (type 0) to the server. We catch this and
1995 * reply with an old reject packet. Since there is no struct for
1996 * this old packet anymore we build it by hand.
1997 */
1998 if (type == 0) {
1999 unsigned char buffer[4096];
2000 struct raw_data_out dout;
2001
2002 log_normal(_("Warning: rejecting old client %s"),
2003 conn_description(pconn));
2004
2005 dio_output_init(&dout, buffer, sizeof(buffer));
2006 dio_put_uint16_raw(&dout, 0);
2007
2008 /* 1 == PACKET_LOGIN_REPLY in the old client */
2009 dio_put_uint8_raw(&dout, 1);
2010
2011 dio_put_bool32_raw(&dout, FALSE);
2012 dio_put_string_raw(&dout,
2013 _("Your client is too old. To use this server, "
2014 "please upgrade your client to a "
2015 "Freeciv 2.2 or later."));
2016 dio_put_string_raw(&dout, "");
2017
2018 {
2019 size_t size = dio_output_used(&dout);
2020 dio_output_rewind(&dout);
2021 dio_put_uint16_raw(&dout, size);
2022
2023 /*
2024 * Use send_connection_data instead of send_packet_data to avoid
2025 * compression.
2026 */
2027 connection_send_data(pconn, buffer, size);
2028 }
2029
2030 return FALSE;
2031 }
2032
2034 return handle_login_request(pconn,
2035 (struct packet_server_join_req *) packet);
2036 }
2037
2038 /* May be received on a non-established connection. */
2040 return auth_handle_reply(pconn,
2041 ((struct packet_authentication_reply *)
2042 packet)->password);
2043 }
2044
2045 if (type == PACKET_CONN_PONG) {
2046 handle_conn_pong(pconn);
2047 return TRUE;
2048 }
2049
2050 if (!pconn->established) {
2051 log_error("Received game packet %s(%d) from unaccepted connection %s.",
2053 return TRUE;
2054 }
2055
2056 /* valid packets from established connections but non-players */
2066
2067 /* Except for PACKET_EDIT_MODE (used to set edit mode), check
2068 * that the client is allowed to send the given edit packet. */
2070 && !can_conn_edit(pconn)) {
2071 notify_conn(pconn->self, NULL, E_BAD_COMMAND, ftc_editor,
2072 _("You are not allowed to edit."));
2073 return TRUE;
2074 }
2075
2076 if (!server_handle_packet(type, packet, NULL, pconn)) {
2077 log_error("Received unknown packet %d from %s.",
2078 type, conn_description(pconn));
2079 }
2080 return TRUE;
2081 }
2082
2083 pplayer = pconn->playing;
2084
2085 if (NULL == pplayer || pconn->observer) {
2086 if (type == PACKET_PLAYER_READY && pconn->observer) {
2087 handle_observer_ready(pconn);
2088 return TRUE;
2089 }
2090 /* don't support these yet */
2091 log_error("Received packet %s(%d) from non-player connection %s.",
2093 return TRUE;
2094 }
2095
2096 if (S_S_RUNNING != server_state()
2099 && type != PACKET_VOTE_SUBMIT) {
2100 if (S_S_OVER == server_state()) {
2101 /* This can happen by accident, so we don't want to print
2102 * out lots of error messages. Ie, we use log_debug(). */
2103 log_debug("Got a packet of type %s(%d) in %s.",
2104 packet_name(type), type, server_states_name(S_S_OVER));
2105 } else {
2106 log_error("Got a packet of type %s(%d) outside %s.",
2107 packet_name(type), type, server_states_name(S_S_RUNNING));
2108 }
2109 return TRUE;
2110 }
2111
2112 pplayer->nturns_idle = 0;
2113
2114 if (!pplayer->is_alive && type != PACKET_REPORT_REQ) {
2115 log_error("Got a packet of type %s(%d) from a dead player.",
2117 return TRUE;
2118 }
2119
2120 /* Make sure to set this back to NULL before leaving this function: */
2121 pplayer->current_conn = pconn;
2122
2123 if (!server_handle_packet(type, packet, pplayer, pconn)) {
2124 log_error("Received unknown packet %d from %s.",
2125 type, conn_description(pconn));
2126 }
2127
2128 if (S_S_RUNNING == server_state()
2129 && type != PACKET_PLAYER_READY) {
2130 /* handle_player_ready() calls start_game(), but the game isn't started
2131 * until the main loop is re-entered, so kill_dying_players would think
2132 * all players are dead. This should be solved by adding a new
2133 * game state (now S_S_GENERATING_WAITING). */
2135 }
2136
2137 pplayer->current_conn = NULL;
2138 return TRUE;
2139}
2140
2141/**********************************************************************/
2146{
2147 bool connected = FALSE;
2148
2149 if (S_S_RUNNING != server_state()) {
2150 /* Not in a running state, no turn done. */
2151 return;
2152 }
2153
2154 /* fixedlength is only applicable if we have a timeout set */
2156 return;
2157 }
2158
2159 /* If there are no connected players, don't automatically advance. This is
2160 * a hack to prevent all-AI games from running rampant. Note that if
2161 * timeout is set to -1 this function call is skipped entirely and the
2162 * server will run rampant. */
2163 players_iterate_alive(pplayer) {
2164 if (pplayer->is_connected && (is_human(pplayer) || pplayer->phase_done)) {
2165 connected = TRUE;
2166 break;
2167 }
2169
2170 if (!connected) {
2171 return;
2172 }
2173
2174 phase_players_iterate(pplayer) {
2175 if (!pplayer->phase_done && pplayer->is_alive) {
2176 if (pplayer->is_connected) {
2177 /* In all cases, we wait for any connected players. */
2178 return;
2179 }
2180 if (game.server.turnblock && is_human(pplayer)) {
2181 /* If turnblock is enabled check for human players, connected
2182 * or not. */
2183 return;
2184 }
2185 if (is_ai(pplayer) && !pplayer->ai_phase_done) {
2186 /* AI player has not finished */
2187 return;
2188 }
2189 }
2191
2193}
2194
2195/**********************************************************************/
2201{
2202 if (!game_was_started() && 0 < map_startpos_count()) {
2203 /* Restrict nations to those for which start positions are defined. */
2204 nations_iterate(pnation) {
2205 fc_assert_action_msg(NULL == pnation->player,
2206 if (pnation->player->nation == pnation) {
2207 /* At least assignment is consistent. Leave nation assigned,
2208 * and make sure that nation is also marked pickable. */
2209 pnation->server.no_startpos = FALSE;
2210 continue;
2211 } else if (NULL != pnation->player->nation) {
2212 /* Not consistent. Just initialize the pointer and hope for the
2213 * best. */
2214 pnation->player->nation->player = NULL;
2215 pnation->player = NULL;
2216 } else {
2217 /* Not consistent. Just initialize the pointer and hope for the
2218 * best. */
2219 pnation->player = NULL;
2220 }, "Player assigned to nation before %s()!", __FUNCTION__);
2221
2222 if (nation_barbarian_type(pnation) != NOT_A_BARBARIAN) {
2223 /* Always allow land and sea barbarians regardless of start
2224 * positions. */
2225 pnation->server.no_startpos = FALSE;
2226 } else {
2227 /* Restrict the set of nations offered to players, based on
2228 * start positions.
2229 * If there are no start positions for a nation, remove it from the
2230 * available set. */
2231 pnation->server.no_startpos = TRUE;
2233 if (startpos_nation_allowed(psp, pnation)) {
2234 /* There is at least one start position that allows this nation,
2235 * so allow it to be picked.
2236 * (Depending on what nations players actually pick, it's not
2237 * guaranteed that the server can always find a match between
2238 * nations in this subset and start positions, in which case the
2239 * server may create mismatches.) */
2240 pnation->server.no_startpos = FALSE;
2241 break;
2242 }
2244 }
2246 } else {
2247 /* Not restricting nations by start positions. */
2248 nations_iterate(pnation) {
2249 pnation->server.no_startpos = FALSE;
2251 }
2252}
2253
2254/**********************************************************************/
2259void handle_nation_select_req(struct connection *pc, int player_no,
2260 Nation_type_id nation_no, bool is_male,
2261 const char *name, int style)
2262{
2263 struct nation_type *new_nation;
2264 struct player *pplayer = player_by_number(player_no);
2265
2266 if (!pplayer || !can_conn_edit_players_nation(pc, pplayer)) {
2267 return;
2268 }
2269
2270 new_nation = nation_by_number(nation_no);
2271
2272 if (new_nation != NO_NATION_SELECTED) {
2273 char message[1024];
2274
2275 /* check sanity of the packet sent by client */
2276 if (style < 0 || style >= game.control.num_styles) {
2277 return;
2278 }
2279
2280 if (!client_can_pick_nation(new_nation)) {
2281 notify_player(pplayer, NULL, E_NATION_SELECTED, ftc_server,
2282 _("%s nation is not available for user selection."),
2283 nation_adjective_translation(new_nation));
2284 return;
2285 }
2286 if (new_nation->player && new_nation->player != pplayer) {
2287 notify_player(pplayer, NULL, E_NATION_SELECTED, ftc_server,
2288 _("%s nation is already in use."),
2289 nation_adjective_translation(new_nation));
2290 return;
2291 }
2292
2293 if (!server_player_set_name_full(pc, pplayer, new_nation, name,
2294 message, sizeof(message))) {
2295 notify_player(pplayer, NULL, E_NATION_SELECTED,
2296 ftc_server, "%s", message);
2297 return;
2298 }
2299
2300 /* Should be caught by is_nation_pickable() */
2302
2303 notify_conn(NULL, NULL, E_NATION_SELECTED, ftc_server,
2304 _("%s is the %s ruler %s."),
2305 pplayer->username,
2306 nation_adjective_translation(new_nation),
2307 player_name(pplayer));
2308
2309 pplayer->is_male = is_male;
2310 pplayer->style = style_by_number(style);
2311 } else if (name[0] == '\0') {
2312 char message[1024];
2313
2315 message, sizeof(message));
2316 }
2317
2318 (void) player_set_nation(pplayer, new_nation);
2320}
2321
2322/**********************************************************************/
2325static void handle_observer_ready(struct connection *pconn)
2326{
2327 if (pconn->access_level == ALLOW_HACK) {
2328 players_iterate(plr) {
2329 if (is_human(plr)) {
2330 return;
2331 }
2333
2334 start_command(NULL, FALSE, TRUE);
2335 }
2336}
2337
2338/**********************************************************************/
2341void handle_player_ready(struct player *requestor,
2342 int player_no,
2343 bool is_ready)
2344{
2345 struct player *pplayer = player_by_number(player_no);
2346
2347 if (NULL == pplayer || S_S_INITIAL != server_state()) {
2348 return;
2349 }
2350
2351 if (pplayer != requestor) {
2352 /* Currently you can only change your own readiness. */
2353 return;
2354 }
2355
2356 pplayer->is_ready = is_ready;
2357 send_player_info_c(pplayer, NULL);
2358
2359 /* Note this is called even if the player has pressed /start once
2360 * before. For instance, when a player leaves everyone remaining
2361 * might have pressed /start already but the start won't happen
2362 * until someone presses it again. Also you can press start more
2363 * than once to remind other people to start (which is a good thing
2364 * until somebody does it too much and it gets labeled as spam). */
2365 if (is_ready) {
2366 int num_ready = 0, num_unready = 0;
2367
2368 players_iterate_alive(other_player) {
2369 if (other_player->is_connected) {
2370 if (other_player->is_ready) {
2371 num_ready++;
2372 } else {
2373 num_unready++;
2374 }
2375 }
2377
2378 if (num_unready > 0) {
2379 notify_conn(NULL, NULL, E_SETTING, ftc_server,
2380 _("Waiting to start game: %d out of %d alive players "
2381 "are ready to start."),
2382 num_ready, num_ready + num_unready);
2383 } else {
2384 /* Check minplayers etc. and then start */
2385 start_command(NULL, FALSE, TRUE);
2386 }
2387 }
2388}
2389
2390/**********************************************************************/
2395const char *aifill(int amount)
2396{
2397 char *limitreason = NULL;
2398 int limit;
2399
2400 if (game_was_started()) {
2401 return NULL;
2402 }
2403
2404 limit = MIN(amount, game.server.max_players);
2405 if (limit < amount) {
2406 limitreason = _("requested more than 'maxplayers' setting");
2407 }
2408
2409 /* Limit to nations provided by ruleset */
2410 if (limit > server.playable_nations) {
2411 limit = server.playable_nations;
2412 if (nation_set_count() > 1) {
2413 limitreason = _("not enough playable nations in this nation set "
2414 "(see 'nationset' setting)");
2415 } else {
2416 limitreason = _("not enough playable nations");
2417 }
2418 }
2419
2420 if (limit < player_count()) {
2421 int removal = player_slot_count() - 1;
2422
2423 while (limit < player_count() && 0 <= removal) {
2424 struct player *pplayer = player_by_number(removal);
2425
2426 removal--;
2427 if (!pplayer) {
2428 continue;
2429 }
2430
2431 if (!pplayer->is_connected && !pplayer->was_created) {
2432 server_remove_player(pplayer);
2433 }
2434 }
2435
2436 /* 'limit' can be different from 'player_count()' at this point if
2437 * there are more human or created players than the 'limit'. */
2438 return limitreason;
2439 }
2440
2441 while (limit > player_count()) {
2443 int filled = 1;
2444 struct player *pplayer;
2445
2447 NULL, FALSE);
2448 /* !game_was_started() so no need to assign_player_colors() */
2449 if (!pplayer) {
2450 break;
2451 }
2452 server_player_init(pplayer, FALSE, TRUE);
2453
2454 player_set_nation(pplayer, NULL);
2455
2456 do {
2457 fc_snprintf(leader_name, sizeof(leader_name), "AI*%d", filled++);
2458 } while (player_by_name(leader_name));
2460 pplayer->random_name = TRUE;
2461 sz_strlcpy(pplayer->username, _(ANON_USER_NAME));
2462 pplayer->unassigned_user = TRUE;
2463
2465 set_as_ai(pplayer);
2467
2468 CALL_PLR_AI_FUNC(gained_control, pplayer, pplayer);
2469
2470 log_normal(_("%s has been added as %s level AI-controlled player (%s)."),
2471 player_name(pplayer),
2472 ai_level_translated_name(pplayer->ai_common.skill_level),
2473 ai_name(pplayer->ai));
2474 notify_conn(NULL, NULL, E_SETTING, ftc_server,
2475 _("%s has been added as %s level AI-controlled player (%s)."),
2476 player_name(pplayer),
2477 ai_level_translated_name(pplayer->ai_common.skill_level),
2478 ai_name(pplayer->ai));
2479
2480 send_player_info_c(pplayer, NULL);
2481 }
2482
2483 return limitreason;
2484}
2485
2486/**********************************************************************/
2489#define SPECHASH_TAG startpos
2490#define SPECHASH_IKEY_TYPE struct startpos *
2491#define SPECHASH_INT_DATA_TYPE
2492#include "spechash.h"
2493#define startpos_hash_iterate(hash, psp, c) \
2494 TYPED_HASH_ITERATE(struct startpos *, intptr_t, hash, psp, c)
2495#define startpos_hash_iterate_end HASH_ITERATE_END
2496
2497/**********************************************************************/
2500static void player_set_nation_full(struct player *pplayer,
2501 struct nation_type *pnation)
2502{
2503 /* Don't change the name of a created player. */
2504 player_nation_defaults(pplayer, pnation, pplayer->random_name);
2505}
2506
2507/**********************************************************************/
2510void player_nation_defaults(struct player *pplayer, struct nation_type *pnation,
2511 bool set_name)
2512{
2513 struct nation_leader *pleader;
2514
2515 fc_assert(NO_NATION_SELECTED != pnation);
2516 player_set_nation(pplayer, pnation);
2517 fc_assert(pnation == pplayer->nation);
2518
2519 pplayer->style = style_of_nation(pnation);
2520
2521 if (set_name) {
2523 }
2524
2525 if ((pleader = nation_leader_by_name(pnation, player_name(pplayer)))) {
2526 pplayer->is_male = nation_leader_is_male(pleader);
2527 } else {
2528 pplayer->is_male = (fc_rand(2) == 1);
2529 }
2530
2531 ai_traits_init(pplayer);
2532}
2533
2534/**********************************************************************/
2561static void generate_players(void)
2562{
2563 int nations_to_assign = 0;
2564
2565 /* Announce players who already have nations, and select nations based
2566 * on player names. */
2567 players_iterate(pplayer) {
2568 if (pplayer->nation != NO_NATION_SELECTED) {
2569 /* Traits are initialized here, and not already when nation gets
2570 * picked, as player may change their mind after picking one nation,
2571 * and picks another and we want to init traits only once, for the
2572 * correct nation. */
2573 ai_traits_init(pplayer);
2574 announce_player(pplayer);
2575 continue;
2576 }
2577
2578 /* See if the player name matches a known leader name.
2579 * If more than one nation has this leader name, pick one at random.
2580 * No attempt is made to avoid clashes to maximise the number of
2581 * nations that can be assigned in this way. */
2582 {
2583 struct nation_list *candidates = nation_list_new();
2584 int n = 0;
2585
2586 allowed_nations_iterate(pnation) {
2587 if (is_nation_playable(pnation)
2588 && client_can_pick_nation(pnation)
2589 && NULL == pnation->player
2590 && (nation_leader_by_name(pnation, player_name(pplayer)))) {
2591 nation_list_append(candidates, pnation);
2592 n++;
2593 }
2595 if (n > 0) {
2596 player_set_nation_full(pplayer,
2597 nation_list_get(candidates, fc_rand(n)));
2598 }
2599 nation_list_destroy(candidates);
2600 }
2601 if (pplayer->nation != NO_NATION_SELECTED) {
2602 announce_player(pplayer);
2603 } else {
2604 nations_to_assign++;
2605 }
2607
2608 if (0 < nations_to_assign && 0 < map_startpos_count()) {
2609 /* We're running a scenario game with specified start positions.
2610 * Prefer nations assigned to those positions (but we can fall back
2611 * to others, even if game.scenario.startpos_nations is set). */
2612 struct startpos_hash *hash = startpos_hash_new();
2613 struct nation_type *picked;
2614 int c, max = -1;
2615 int i, min;
2616
2617 /* Initialization. */
2619 if (startpos_allows_all(psp)) {
2620 continue;
2621 }
2622
2623 /* Count the already-assigned players whose nations can use this
2624 * start position. */
2625 c = 0;
2626 players_iterate(pplayer) {
2627 if (NO_NATION_SELECTED != pplayer->nation
2628 && startpos_nation_allowed(psp, pplayer->nation)) {
2629 c++;
2630 }
2632
2633 startpos_hash_insert(hash, psp, c);
2634 if (c > max) {
2635 max = c;
2636 }
2638
2639 /* Try to assign nations with start positions to the unassigned
2640 * players, preferring nations whose start positions aren't usable
2641 * by already-assigned players. */
2642 players_iterate(pplayer) {
2643 if (NO_NATION_SELECTED != pplayer->nation) {
2644 continue;
2645 }
2646
2647 picked = NO_NATION_SELECTED;
2648 min = max;
2649 i = 0;
2650
2651 allowed_nations_iterate(pnation) {
2652 if (!is_nation_playable(pnation)
2653 || NULL != pnation->player) {
2654 /* Not available. */
2655 continue;
2656 }
2657
2658 startpos_hash_iterate(hash, psp, val) {
2659 if (!startpos_nation_allowed(psp, pnation)) {
2660 continue;
2661 }
2662
2663 if (val < min) {
2664 /* Pick this nation, as fewer nations already in the game
2665 * can use this start position. */
2666 picked = pnation;
2667 min = val;
2668 i = 1;
2669 } else if (val == min && 0 == fc_rand(++i)) {
2670 /* More than one nation is equally desirable. Pick one at
2671 * random. */
2672 picked = pnation;
2673 }
2676
2677 if (NO_NATION_SELECTED != picked) {
2678 player_set_nation_full(pplayer, picked);
2679 nations_to_assign--;
2680 announce_player(pplayer);
2681 /* Update the counts for the newly assigned nation. */
2682 startpos_hash_iterate(hash, psp, val) {
2683 if (startpos_nation_allowed(psp, picked)) {
2684 startpos_hash_replace(hash, psp, val + 1);
2685 }
2687 } else {
2688 /* No need to continue; we failed to pick a nation this time,
2689 * so we're not going to succeed next time. Fall back to
2690 * standard nation selection. */
2691 break;
2692 }
2694
2695 startpos_hash_destroy(hash);
2696 }
2697
2698 if (0 < nations_to_assign) {
2699 /* Pick random races. Try to select from the set permitted by
2700 * starting positions -- if we fell through here after failing to
2701 * match start positions, this will at least keep the picked
2702 * nations vaguely in keeping with the scenario.
2703 * However, even this may fail (if there are start positions that
2704 * can only be filled by nations outside the current nationset),
2705 * in which case we fall back to completely random nations. */
2706 bool needs_startpos = TRUE;
2707 players_iterate(pplayer) {
2708 if (NO_NATION_SELECTED == pplayer->nation) {
2709 struct nation_type *pnation = pick_a_nation(NULL, FALSE, needs_startpos,
2710 NOT_A_BARBARIAN);
2711 if (pnation == NO_NATION_SELECTED && needs_startpos) {
2712 needs_startpos = FALSE;
2713 pnation = pick_a_nation(NULL, FALSE, needs_startpos, NOT_A_BARBARIAN);
2714 }
2715 fc_assert(pnation != NO_NATION_SELECTED);
2716 player_set_nation_full(pplayer, pnation);
2717 nations_to_assign--;
2718 announce_player(pplayer);
2719 }
2721 }
2722
2723 fc_assert(0 == nations_to_assign);
2724
2726}
2727
2728/**********************************************************************/
2733const char *pick_random_player_name(const struct nation_type *pnation)
2734{
2735 const char *choice = NULL;
2736 struct nation_leader_list *candidates = nation_leader_list_new();
2737 int n;
2738
2739 nation_leader_list_iterate(nation_leaders(pnation), pleader) {
2740 const char *name = nation_leader_name(pleader);
2741
2742 if (NULL == player_by_name(name)
2743 && NULL == player_by_user(name)) {
2744 nation_leader_list_append(candidates, pleader);
2745 }
2747
2748 n = nation_leader_list_size(candidates);
2749 if (n > 0) {
2750 choice = nation_leader_name(nation_leader_list_get(candidates,
2751 fc_rand(n)));
2752 }
2753 nation_leader_list_destroy(candidates);
2754
2755 return choice;
2756}
2757
2758/**********************************************************************/
2761static void announce_player(struct player *pplayer)
2762{
2763 log_normal(_("%s rules the %s."),
2764 player_name(pplayer), nation_plural_for_player(pplayer));
2765
2766 notify_conn(game.est_connections, NULL, E_GAME_START,
2767 ftc_server, _("%s rules the %s."),
2768 player_name(pplayer), nation_plural_for_player(pplayer));
2769
2770 /* Let the clients knows the nation of the players as soon as possible.
2771 * When a player's nation is server assigned its client will think of it
2772 * as NULL until informed about the assigned nation. */
2773 send_player_info_c(pplayer, NULL);
2774}
2775
2776/**********************************************************************/
2779static void srv_running(void)
2780{
2781 int i;
2782 bool is_new_turn = game.info.is_new_game;
2783 bool skip_mapimg = !game.info.is_new_game; /* Do not overwrite start-of-turn image */
2784 bool need_send_pending_events = !game.info.is_new_game;
2785 int save_counter = game.info.is_new_game ? 1 : 0;
2786
2787 /* We may as well reset is_new_game now. */
2789
2790 log_verbose("srv_running() mostly redundant send_server_settings()");
2792
2794
2795 if (game.server.autosaves & (1 << AS_TIMER)) {
2799 }
2800
2801 /*
2802 * This will freeze the reports and agents at the client.
2803 *
2804 * Do this before the body so that the PACKET_THAW_CLIENT packet is
2805 * balanced.
2806 */
2808
2809 fc_assert(S_S_RUNNING == server_state());
2810 while (S_S_RUNNING == server_state()) {
2811 /* The beginning of a turn.
2812 *
2813 * We have to initialize data as well as do some actions. However when
2814 * loading a game we don't want to do these actions (like AI unit
2815 * movement and AI diplomacy). */
2816 begin_turn(is_new_turn);
2817
2818 if (game.server.num_phases != 1) {
2819 /* We allow everyone to begin adjusting cities and such
2820 * from the beginning of the turn.
2821 * With simultaneous movement we send begin_turn packet in
2822 * begin_phase() only after AI players have finished their actions. */
2824 }
2825
2827 log_debug("Starting phase %d/%d.", game.info.phase,
2829 begin_phase(is_new_turn);
2830 if (need_send_pending_events) {
2831 /* When loading a savegame, we need to send loaded events, after
2832 * the clients switched to the game page (after the first
2833 * packet_start_phase is received). */
2835 send_pending_events(pconn, TRUE);
2837 need_send_pending_events = FALSE;
2838 }
2839
2840 is_new_turn = TRUE;
2841
2843
2844 /*
2845 * This will thaw the reports and agents at the client.
2846 */
2848
2849#ifdef LOG_TIMERS
2850 /* Before sniff (human player activites), report time to now: */
2851 log_verbose("End/start-turn server/ai activities: %g seconds",
2853#endif
2854
2855 /* Do auto-saves just before starting server_sniff_all_input(), so that
2856 * autosave happens effectively "at the same time" as manual
2857 * saves, from the point of view of restarting and AI players.
2858 * Post-increment so we don't count the first loop. */
2859 if (game.info.phase == 0) {
2860 /* Create autosaves if requested. */
2861 if (save_counter >= game.server.save_nturns
2862 && game.server.save_nturns > 0) {
2863 save_counter = 0;
2864 save_game_auto("Autosave", AS_TURN);
2865 }
2866 save_counter++;
2867
2868 if (!skip_mapimg) {
2869 /* Save map image(s). */
2870 for (i = 0; i < mapimg_count(); i++) {
2871 struct mapdef *pmapdef = mapimg_isvalid(i);
2872 if (pmapdef != NULL) {
2875 } else {
2876 log_error("%s", mapimg_error());
2877 }
2878 }
2879 } else {
2880 skip_mapimg = FALSE;
2881 }
2882 }
2883
2884 log_debug("sniffingpackets");
2885 check_for_full_turn_done(); /* HACK: don't wait during AI phases */
2886
2887 if (between_turns != NULL) {
2889 log_debug("Unresponsive between turns %g seconds", game.server.turn_change_time);
2890 }
2891
2893 /* nothing */
2894 }
2895
2898
2899 /* After sniff, re-zero the timer: (read-out above on next loop) */
2902
2904
2905 sanity_check();
2906
2907 /*
2908 * This will freeze the reports and agents at the client.
2909 */
2911
2912 end_phase();
2913
2915
2916 if (S_S_OVER == server_state()) {
2917 break;
2918 }
2920 }
2921
2922 /* Make sure is_new_turn is reset before next turn even if
2923 * we did zero rounds in the loop (i.e. if current phase from
2924 * the savegame was >= num phases). Without this begin_turn()
2925 * would not reset phase, so there would be infinite loop
2926 * where phase is too high for is_new_turn to get set. */
2927 is_new_turn = TRUE;
2928
2929 end_turn();
2930 log_debug("Sendinfotometaserver");
2932
2933 if (S_S_OVER != server_state() && check_for_game_over()) {
2934 set_server_state(S_S_OVER);
2935 if (game.info.turn > game.server.end_turn) {
2936 /* endturn was reached - rank users based on team scores */
2938 } else {
2939 /* game ended for victory conditions - rank users based on survival */
2941 }
2942 } else if (S_S_OVER == server_state()) {
2943 /* game terminated by /endgame command - calculate team scores */
2945 }
2946 }
2947
2948 /* This will thaw the reports and agents at the client. */
2950
2951 if (game.server.save_timer != NULL) {
2953 game.server.save_timer = NULL;
2954 }
2955 if (between_turns != NULL) {
2957 between_turns = NULL;
2958 }
2960}
2961
2962/**********************************************************************/
2965static void srv_prepare(void)
2966{
2967#ifdef HAVE_FCDB
2968 if (!srvarg.auth_enabled) {
2969 con_write(C_COMMENT, _("This freeciv-server program has player "
2970 "authentication support, but it's currently not "
2971 "in use."));
2972 }
2973#endif /* HAVE_FCDB */
2974
2975 /* make sure it's initialized */
2976 if (!has_been_srv_init) {
2977 srv_init();
2978 }
2979
2981
2982 /* must be before con_log_init() */
2986 /* logging available after this point */
2987
2989
2990#if IS_BETA_VERSION || IS_DEVEL_VERSION
2991 con_puts(C_COMMENT, "");
2993 con_puts(C_COMMENT, "");
2994#endif /* IS_BETA_VERSION || IS_DEVEL_VERSION */
2995
2996 con_flush();
2997
3000 edithand_init();
3001 voting_init();
3002 diplhand_init();
3003 voting_init();
3004 ai_timer_init();
3005
3011
3012#ifdef HAVE_FCDB
3013 if (srvarg.fcdb_enabled) {
3014 bool success;
3015
3016 success = fcdb_init(srvarg.fcdb_conf);
3017 free(srvarg.fcdb_conf); /* Never needed again */
3018 srvarg.fcdb_conf = NULL;
3019 if (!success) {
3020 exit(EXIT_FAILURE);
3021 }
3022 }
3023#endif /* HAVE_FCDB */
3024
3025 if (srvarg.ruleset != NULL) {
3026 const char *testfilename;
3027
3028 testfilename = fileinfoname(get_data_dirs(), srvarg.ruleset);
3029 if (testfilename == NULL) {
3030 log_fatal(_("Ruleset directory \"%s\" not found"), srvarg.ruleset);
3031 exit(EXIT_FAILURE);
3032 }
3034 }
3035
3036 /* load a saved game */
3037 if ('\0' == srvarg.load_filename[0]
3039 /* Rulesets are loaded on game initialization, but may be changed later
3040 * if /load or /rulesetdir is done. */
3041 load_rulesets(NULL, NULL, FALSE, NULL, TRUE, FALSE, TRUE);
3042 }
3043
3045
3046 if (!(srvarg.metaserver_no_send)) {
3047 log_normal(_("Sending info to metaserver <%s>."), meta_addr_port());
3048 /* Open socket for meta server */
3051 con_write(C_FAIL, _("Not starting without explicitly requested metaserver connection."));
3052 exit(EXIT_FAILURE);
3053 }
3054 }
3055
3057}
3058
3059/**********************************************************************/
3062static void srv_scores(void)
3063{
3064 /* Recalculate the scores in case of a spaceship victory */
3065 players_iterate(pplayer) {
3066 calc_civ_score(pplayer);
3068
3070
3071 report_final_scores(NULL);
3073 notify_player(NULL, NULL, E_GAME_END, ftc_server,
3074 _("The game is over..."));
3076
3077 if (game.server.save_nturns > 0
3078 && (conn_list_size(game.est_connections) > 0
3079 || !srvarg.quitidle)) {
3080 /* Save game on game_over, but not when the gameover was caused by
3081 * the -q parameter. Be sure that it's the -q, and not an autogame
3082 * with no human players. */
3083 save_game_auto("Game over", AS_GAME_OVER);
3084 }
3085}
3086
3087/**********************************************************************/
3093{
3094 players_iterate(pplayer) {
3095 struct nation_type *pnation = nation_of_player(pplayer);
3096
3097 pplayer->government = init_government_of_nation(pnation);
3098
3100 /* If we do not do this, an assertion will trigger. This enables us to
3101 * select a valid government on game start. */
3102 pplayer->revolution_finishes = 0;
3103 }
3104
3105 multipliers_iterate(pmul) {
3106 int midx = multiplier_index(pmul);
3107
3108 pplayer->multipliers[midx].value
3109 = pplayer->multipliers[midx].target
3110 = pmul->def;
3113}
3114
3115/**********************************************************************/
3118static void srv_ready(void)
3119{
3121
3123 players_iterate(pplayer) {
3124 if (!pplayer->is_connected && is_human(pplayer)) {
3125 toggle_ai_player_direct(NULL, pplayer);
3126 }
3128 }
3129
3131
3132#ifdef TEST_RANDOM /* not defined anywhere, set it if you want it */
3133 test_random1(200);
3134 test_random1(2000);
3135 test_random1(20000);
3136 test_random1(200000);
3137#endif
3138
3139 if (game.info.is_new_game) {
3140 /* Must come before assign_player_colors() */
3143
3144 game.info.turn++; /* Pregame T0 -> game T1 */
3145 fc_assert(game.info.turn == 1);
3147 }
3148
3149 /* If we have a tile map, and MAPGEN_SCENARIO == map.server.generator,
3150 * call map_fractal_generate() anyway to make the specials, huts and
3151 * continent numbers. */
3152 if (map_is_empty()
3154 && game.info.is_new_game)) {
3155 struct {
3156 const char *name;
3157 char value[MAX_LEN_NAME * 2];
3158 char pretty[MAX_LEN_NAME * 2];
3159 } mapgen_settings[] = {
3160 { "generator", },
3161 { "startpos", },
3162 { "teamplacement", }
3163 };
3164 int i;
3165 /* If a specific seed has been requested, there's no point retrying,
3166 * as the map will be the same every time. */
3167 bool retry_ok = (wld.map.server.seed_setting == 0
3169 int max = retry_ok ? 3 : 1;
3170 bool created = FALSE;
3171 struct unit_type *utype = NULL;
3172 int sucount = strlen(game.server.start_units);
3173
3174 if (sucount > 0) {
3175 for (i = 0; utype == NULL && i < sucount; i++) {
3176 utype = crole_to_unit_type(game.server.start_units[i], NULL);
3177 }
3178 } else {
3179 /* First unit the initial city might build. */
3180 utype = get_role_unit(L_FIRSTBUILD, 0);
3181 }
3182 fc_assert(utype != NULL);
3183
3184 /* Register map generator setting main values. */
3185 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3186 const struct setting *pset = setting_by_name(mapgen_settings[i].name);
3187
3188 fc_assert_action(pset != NULL, continue);
3189 (void) setting_value_name(pset, FALSE,
3190 mapgen_settings[i].value,
3191 sizeof(mapgen_settings[i].value));
3192 (void) setting_value_name(pset, TRUE,
3193 mapgen_settings[i].pretty,
3194 sizeof(mapgen_settings[i].pretty));
3195 }
3196
3197 for (i = 0; !created && i < max ; i++) {
3198 created = map_fractal_generate(TRUE, utype);
3199 if (!created && max > 1) {
3200 int set;
3201
3202 /* If we're retrying, seed_setting == 0, which will yield a new map
3203 * next time */
3205 if (i == 0) {
3206 /* We will retry only if max attempts allow it */
3207 log_normal(_("Failed to create suitable map, retrying with another mapseed."));
3208 } else {
3209 /* +1 - start human readable count from 1 and not from 0
3210 * +1 - refers to next round, not to one we just did
3211 * ==
3212 * +2 */
3213 log_normal(_("Attempt %d/%d"), i + 2, max);
3214 }
3216
3217 /* Remove old information already present in tiles */
3218 main_map_free();
3220 /* Restore the settings. */
3221 for (set = 0; set < ARRAY_SIZE(mapgen_settings); set++) {
3222 struct setting *pset = setting_by_name(mapgen_settings[set].name);
3223#ifdef FREECIV_NDEBUG
3224 setting_enum_set(pset, mapgen_settings[set].value, NULL, NULL, 0);
3225#else /* FREECIV_NDEBUG */
3226 char error[128];
3227 bool success;
3228
3229 fc_assert_action(pset != NULL, continue);
3230 success = setting_enum_set(pset, mapgen_settings[set].value,
3231 NULL, error, sizeof(error));
3232 fc_assert_msg(success,
3233 "Failed to restore '%s': %s",
3234 mapgen_settings[set].name,
3235 error);
3236#endif /* FREECIV_NDEBUG */
3237 }
3238 main_map_allocate(); /* NOT map_init() as that would overwrite settings */
3239 }
3240 }
3241 if (!created) {
3242 bugreport_request(_("Cannot create suitable map with given settings."));
3243
3244 exit(EXIT_FAILURE);
3245 }
3246
3248 script_server_signal_emit("map_generated");
3249 }
3250
3251 game_map_init();
3252
3253 /* Test if main map generator settings have changed. */
3254 for (i = 0; i < ARRAY_SIZE(mapgen_settings); i++) {
3255 const struct setting *pset = setting_by_name(mapgen_settings[i].name);
3256 char pretty[sizeof(mapgen_settings[i].pretty)];
3257
3258 fc_assert_action(pset != NULL, continue);
3259 if (0 == strcmp(setting_value_name(pset, TRUE, pretty,
3260 sizeof(pretty)),
3261 mapgen_settings[i].pretty)) {
3262 continue; /* Setting didn't change. */
3263 }
3264 notify_conn(NULL, NULL, E_SETTING, ftc_server,
3265 _("Setting '%s' has been adjusted from %s to %s."),
3266 setting_name(pset),
3267 mapgen_settings[i].pretty,
3268 pretty);
3269 log_normal(_("Setting '%s' has been adjusted from %s to %s."),
3270 setting_name(pset),
3271 mapgen_settings[i].pretty,
3272 pretty);
3273 }
3274 }
3275
3276 CALL_FUNC_EACH_AI(map_ready);
3277
3278 /* start the game */
3279 set_server_state(S_S_RUNNING);
3281
3282 if (game.info.is_new_game) {
3284
3285 /* If we're starting a new game, reset the max_players to be at
3286 * least the number of players currently in the game. */
3288
3289 /* Before the player map is allocated (and initialized)! */
3291
3292 players_iterate(pplayer) {
3293 player_map_init(pplayer);
3295 pplayer->economic.gold = game.info.gold;
3296 pplayer->economic.infra_points = game.info.infrapoints;
3298
3299 /* Give initial technologies, as specified in the ruleset and the
3300 * settings. */
3301 researches_iterate(presearch) {
3302 init_tech(presearch, TRUE);
3303 give_initial_techs(presearch, game.info.tech);
3305
3306 /* Set up alliances based on team selections */
3307 players_iterate(pplayer) {
3308 players_iterate(pdest) {
3309 if (players_on_same_team(pplayer, pdest)
3310 && player_number(pplayer) != player_number(pdest)) {
3312 player_diplstate_get(pdest, pplayer),
3313 DS_TEAM);
3314 give_shared_vision(pplayer, pdest);
3315 BV_SET(pplayer->real_embassy, player_index(pdest));
3316 }
3319
3320 /* Assign colors from the ruleset for any players who weren't
3321 * explicitly assigned colors during the pregame.
3322 * This must come after generate_players() since it can depend on
3323 * assigned nations. */
3325
3326 /* Save all settings for the 'reset game' command. */
3328 }
3329
3330 /* FIXME: can this be moved? */
3331 players_iterate(pplayer) {
3334
3335 if (!game.info.is_new_game) {
3336 players_iterate(pplayer) {
3337 if (is_ai(pplayer)) {
3338 set_ai_level_direct(pplayer, pplayer->ai_common.skill_level);
3339 }
3341 } else {
3342 players_iterate(pplayer) {
3343 /* Initialize this again to be sure */
3344 adv_data_default(pplayer);
3346 }
3347
3351
3352 if (game.info.is_new_game) {
3353 /* Place players' initial units, etc */
3354 init_new_game();
3356
3357 if (game.server.revealmap & REVEAL_MAP_START) {
3358 players_iterate(pplayer) {
3359 map_show_all(pplayer);
3361 }
3362 }
3363
3365 /* This is a heavy scenario. It may include research. The sciencebox
3366 * setting may have been changed. A change to the sciencebox setting
3367 * may have caused the stored amount of bulbs to be enough to finish
3368 * the current research. */
3369
3370 players_iterate(pplayer) {
3371 /* Check for finished research. */
3372 update_bulbs(pplayer, 0, TRUE);
3374 }
3375
3376 CALL_FUNC_EACH_AI(game_start);
3377}
3378
3379/**********************************************************************/
3382void server_game_init(bool keep_ruleset_value)
3383{
3384 /* was redundantly in game_load() */
3385 server.playable_nations = 0;
3386 server.nbarbarians = 0;
3387 server.identity_number = IDENTITY_NUMBER_SKIP;
3388
3391
3393 game_init(keep_ruleset_value);
3394 /* game_init() set game.server.plr_colors to NULL. So we need to
3395 * initialize the colors after. */
3397
3399}
3400
3401/**********************************************************************/
3407{
3409
3410 /* Free all the treaties that were left open when game finished. */
3411 free_treaties();
3412
3413 /* Free the vision data, without sending updates. */
3414 players_iterate(pplayer) {
3415 unit_list_iterate(pplayer->units, punit) {
3416 /* don't bother using vision_clear_sight() */
3418 punit->server.vision->radius_sq[v] = -1;
3421 punit->server.vision = NULL;
3423
3424 city_list_iterate(pplayer->cities, pcity) {
3425 /* don't bother using vision_clear_sight() */
3427 pcity->server.vision->radius_sq[v] = -1;
3429 vision_free(pcity->server.vision);
3430 pcity->server.vision = NULL;
3431 adv_city_free(pcity);
3434
3435 /* Destroy all players; with must be separate as the player information is
3436 * needed above. This also sends the information to the clients. */
3437 players_iterate(pplayer) {
3438 server_remove_player(pplayer);
3440
3444 citymap_free();
3445 game_free();
3446}
3447
3448/**********************************************************************/
3451void srv_main(void)
3452{
3453 srv_prepare();
3454
3455 /* Run server loop */
3456 do {
3457 set_server_state(S_S_INITIAL);
3458
3459 /* Load a script file. */
3460 if (NULL != srvarg.script_filename) {
3461 /* Adding an error message more here will duplicate them. */
3463 }
3464
3465 (void) aifill(game.info.aifill);
3466 if (!game_was_started()) {
3468 }
3469
3470 log_normal(_("Now accepting new client connections on port %d."),
3471 srvarg.port);
3472 /* Remain in S_S_INITIAL until all players are ready. */
3474 /* When force_end_of_sniff is used in pregame, it means that the server
3475 * is ready to start (usually set within start_game()). */
3476 }
3477
3478 if (S_S_RUNNING > server_state()) {
3479 /* If restarting for lack of players, the state is S_S_OVER,
3480 * so don't try to start the game. */
3481 srv_ready(); /* srv_ready() sets server state to S_S_RUNNING. */
3482 srv_running();
3483 srv_scores();
3484 }
3485
3486 /* Remain in S_S_OVER until players log out */
3487 while (conn_list_size(game.est_connections) > 0) {
3489 }
3490
3491 if (game.info.timeout == -1 || srvarg.exit_on_end) {
3492 /* For autogames or if the -e option is specified, exit the server. */
3493 server_quit();
3494 }
3495
3496 /* Close it even between games. */
3498
3499 /* Reset server */
3503 mapimg_reset();
3504 load_rulesets(NULL, NULL, FALSE, NULL, TRUE, FALSE, TRUE);
3506 } while (TRUE);
3507
3508 /* Technically, we won't ever get here. We exit via server_quit. */
3509}
3510
3511/**********************************************************************/
3514struct color;
3515static inline void server_gui_color_free(struct color *pcolor)
3516{
3517 fc_assert_ret(pcolor == NULL);
3518
3519 return;
3520}
3521
3522/**********************************************************************/
3526static int server_plr_tile_city_id_get(const struct tile *ptile,
3527 const struct player *pplayer)
3528{
3529 const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3530
3531 return plrtile && plrtile->site ? plrtile->site->identity
3533}
3534
3535/**********************************************************************/
3539{
3540 struct setting *pset = setting_by_name(name);
3541
3542 if (pset) {
3543 return setting_number(pset);
3544 } else {
3545 log_error("No server setting named %s exists.", name);
3546 return SERVER_SETTING_NONE;
3547 }
3548}
3549
3550/**********************************************************************/
3554{
3555 struct setting *pset = setting_by_number(id);
3556
3557 if (pset) {
3558 return setting_name(pset);
3559 } else {
3560 log_error("No server setting with the id %d exists.", id);
3561 return NULL;
3562 }
3563}
3564
3565/**********************************************************************/
3569{
3570 struct setting *pset = setting_by_number(id);
3571
3572 if (pset) {
3573 return setting_type(pset);
3574 } else {
3575 log_error("No server setting with the id %d exists.", id);
3576 return sset_type_invalid();
3577 }
3578}
3579
3580/**********************************************************************/
3584{
3585 struct setting *pset = setting_by_number(id);
3586
3587 if (pset) {
3588 return setting_bool_get(pset);
3589 } else {
3590 log_error("No server setting with the id %d exists.", id);
3591 return FALSE;
3592 }
3593}
3594
3595/**********************************************************************/
3599{
3600 struct setting *pset = setting_by_number(id);
3601
3602 if (pset) {
3603 return setting_int_get(pset);
3604 } else {
3605 log_error("No server setting with the id %d exists.", id);
3606 return 0;
3607 }
3608}
3609
3610/**********************************************************************/
3614{
3615 struct setting *pset = setting_by_number(id);
3616
3617 if (pset) {
3618 return setting_bitwise_get(pset);
3619 } else {
3620 log_error("No server setting with the id %d exists.", id);
3621 return FALSE;
3622 }
3623}
3624
3625/**********************************************************************/
3629{
3631
3632 funcs->server_setting_by_name = server_ss_by_name;
3633 funcs->server_setting_name_get = server_ss_name_get;
3634 funcs->server_setting_type_get = server_ss_type_get;
3635 funcs->server_setting_val_bool_get = server_ss_val_bool_get;
3636 funcs->server_setting_val_int_get = server_ss_val_int_get;
3637 funcs->server_setting_val_bitwise_get = server_ss_val_bitwise_get;
3638 funcs->create_extra = create_extra;
3639 funcs->destroy_extra = destroy_extra;
3640 funcs->destroy_city = remove_city;
3641 funcs->player_tile_vision_get = map_is_known_and_seen;
3642 funcs->player_tile_city_id_get = server_plr_tile_city_id_get;
3643 funcs->gui_color_free = server_gui_color_free;
3644
3645 /* Keep this function call at the end. It checks if all required functions
3646 are defined. */
3648}
3649
3650/**********************************************************************/
3653static enum known_type mapimg_server_tile_known(const struct tile *ptile,
3654 const struct player *pplayer,
3655 bool knowledge)
3656{
3657 if (knowledge && pplayer) {
3658 return tile_get_known(ptile, pplayer);
3659 }
3660
3661 return TILE_KNOWN_SEEN;
3662}
3663
3664/**********************************************************************/
3667static struct terrain
3668 *mapimg_server_tile_terrain(const struct tile *ptile,
3669 const struct player *pplayer, bool knowledge)
3670{
3671 if (knowledge && pplayer) {
3672 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3673 return plrtile->terrain;
3674 }
3675
3676 return tile_terrain(ptile);
3677}
3678
3679/**********************************************************************/
3682static struct player *mapimg_server_tile_owner(const struct tile *ptile,
3683 const struct player *pplayer,
3684 bool knowledge)
3685{
3686 if (knowledge && pplayer
3687 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3688 struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
3689 return plrtile->owner;
3690 }
3691
3692 return tile_owner(ptile);
3693}
3694
3695/**********************************************************************/
3698static struct player *mapimg_server_tile_city(const struct tile *ptile,
3699 const struct player *pplayer,
3700 bool knowledge)
3701{
3702 struct city *pcity = tile_city(ptile);
3703
3704 if (!pcity) {
3705 return NULL;
3706 }
3707
3708 if (knowledge && pplayer) {
3709 struct vision_site *pdcity = map_get_player_city(ptile, pplayer);
3710
3711 if (pdcity) {
3712 return pdcity->owner;
3713 } else {
3714 return NULL;
3715 }
3716 }
3717
3718 return city_owner(tile_city(ptile));
3719}
3720
3721/**********************************************************************/
3724static struct player *mapimg_server_tile_unit(const struct tile *ptile,
3725 const struct player *pplayer,
3726 bool knowledge)
3727{
3728 int unit_count = unit_list_size(ptile->units);
3729
3730 if (unit_count == 0) {
3731 return NULL;
3732 }
3733
3734 if (knowledge && pplayer
3735 && tile_get_known(ptile, pplayer) != TILE_KNOWN_SEEN) {
3736 return NULL;
3737 }
3738
3739 return unit_owner(unit_list_get(ptile->units, 0));
3740}
3741
3742/**********************************************************************/
3746{
3747 return playercolor_count();
3748}
3749
3750/**********************************************************************/
3754{
3755 return playercolor_get(i);
3756}
int achievement_index(const struct achievement *pach)
struct player * achievement_plr(struct achievement *ach, struct player_list *achievers)
const char * achievement_later_msg(struct achievement *pach)
const char * achievement_first_msg(struct achievement *pach)
#define achievements_iterate_end
#define achievements_iterate(_ach_)
void building_advisor(struct player *pplayer)
void adv_data_analyze_rulesets(struct player *pplayer)
Definition advdata.c:192
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
Definition advdata.c:262
void adv_data_phase_done(struct player *pplayer)
Definition advdata.c:553
void adv_data_default(struct player *pplayer)
Definition advdata.c:718
bool adv_spaceship_autoplace(struct player *pplayer, struct player_spaceship *ship)
Definition advspace.c:33
const char * ai_name(const struct ai_type *ai)
Definition ai.c:329
#define ai_timer_free(...)
Definition ai.h:355
#define CALL_FUNC_EACH_AI(_func,...)
Definition ai.h:384
#define ai_timer_init(...)
Definition ai.h:354
#define CALL_PLR_AI_FUNC(_func, _player,...)
Definition ai.h:374
void ai_init(void)
Definition aiiface.c:133
const char * default_ai_type_name(void)
Definition aiiface.c:262
void ai_traits_init(struct player *pplayer)
Definition aitraits.c:32
void create_animals(void)
Definition animals.c:95
void astr_free(struct astring *astr)
Definition astring.c:153
void astr_set(struct astring *astr, const char *format,...)
Definition astring.c:267
void astr_init(struct astring *astr)
Definition astring.c:144
void astr_add(struct astring *astr, const char *format,...)
Definition astring.c:287
#define str
Definition astring.c:76
#define n
Definition astring.c:77
static const char * astr_str(const struct astring *astr) fc__attribute((nonnull(1)))
Definition astring.h:93
#define ASTRING_INIT
Definition astring.h:44
bool auth_handle_reply(struct connection *pconn, char *password)
Definition auth.c:156
void auto_settlers_player(struct player *pplayer)
void adv_settlers_free(void)
void summon_barbarians(void)
Definition barbarian.c:732
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
#define BV_CLR(bv, bit)
Definition bitvector.h:86
void bugreport_request(const char *reason_format,...)
Definition bugs.c:31
void game_advance_year(void)
Definition calendar.c:91
void game_next_year(struct packet_game_info *info)
Definition calendar.c:30
#define FIRST_TURN
Definition calendar.h:20
struct canvas int int struct sprite bool int int fog_y struct canvas struct sprite struct color * pcolor
Definition canvas_g.h:57
void free_city_map_index(void)
Definition city.c:604
#define cities_iterate_end
Definition city.h:497
#define city_list_iterate(citylist, pcity)
Definition city.h:488
#define cities_iterate(pcity)
Definition city.h:492
#define city_owner(_pcity_)
Definition city.h:543
#define city_list_iterate_end
Definition city.h:490
void citymap_free(void)
Definition citymap.c:110
void package_and_send_worker_tasks(struct city *pcity)
Definition citytools.c:3512
void send_city_info(struct player *dest, struct city *pcity)
Definition citytools.c:2327
bool send_city_suppression(bool now)
Definition citytools.c:2143
void sync_cities(void)
Definition citytools.c:3238
void refresh_player_cities_vision(struct player *pplayer)
Definition citytools.c:3353
void city_map_update_all_cities_for_player(struct player *pplayer)
Definition citytools.c:3272
void remove_city(struct city *pcity)
Definition citytools.c:1684
void city_thaw_workers_queue(void)
Definition citytools.c:196
void send_player_cities(struct player *pplayer)
Definition citytools.c:2307
void send_all_known_cities(struct conn_list *dest)
Definition citytools.c:2284
bool check_city_migrations(void)
Definition cityturn.c:4023
void send_city_turn_notifications(struct connection *pconn)
Definition cityturn.c:579
void update_city_activities(struct player *pplayer)
Definition cityturn.c:605
void city_tc_effect_refresh(struct player *pplayer)
Definition cityturn.c:4388
void check_disasters(void)
Definition cityturn.c:4184
bool handle_login_request(struct connection *pconn, struct packet_server_join_req *req)
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
Definition connecthand.c:68
void conn_list_do_unbuffer(struct conn_list *dest)
Definition connection.c:365
bool can_conn_edit(const struct connection *pconn)
Definition connection.c:510
void conn_list_compression_thaw(const struct conn_list *pconn_list)
Definition connection.c:729
void conn_list_do_buffer(struct conn_list *dest)
Definition connection.c:355
void conn_list_compression_freeze(const struct conn_list *pconn_list)
Definition connection.c:717
bool conn_controls_player(const struct connection *pconn)
Definition connection.c:742
const char * conn_description(const struct connection *pconn)
Definition connection.c:473
bool connection_send_data(struct connection *pconn, const unsigned char *data, int len)
Definition connection.c:286
#define conn_list_iterate(connlist, pconn)
Definition connection.h:113
#define conn_list_iterate_end
Definition connection.h:115
void con_log_init(const char *log_filename, enum log_level level, int fatal_assertions)
Definition console.c:150
void con_flush(void)
Definition console.c:243
void con_write(enum rfc_status rfc_status, const char *message,...)
Definition console.c:203
void con_puts(enum rfc_status rfc_status, const char *str)
Definition console.c:226
void con_log_close(void)
Definition console.c:167
@ C_FAIL
Definition console.h:45
@ C_SYNTAX
Definition console.h:47
@ C_OK
Definition console.h:41
@ C_COMMENT
Definition console.h:37
int nation_history_gain(const struct player *pplayer)
Definition culture.c:61
void dio_output_init(struct raw_data_out *dout, void *destination, size_t dest_size)
Definition dataio_raw.c:171
void dio_put_uint16_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:284
void dio_put_uint8_raw(struct raw_data_out *dout, int value)
Definition dataio_raw.c:265
void dio_put_string_raw(struct raw_data_out *dout, const char *value)
Definition dataio_raw.c:499
size_t dio_output_used(struct raw_data_out *dout)
Definition dataio_raw.c:184
void dio_put_bool32_raw(struct raw_data_out *dout, bool value)
Definition dataio_raw.c:393
void dio_output_rewind(struct raw_data_out *dout)
Definition dataio_raw.c:193
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
void set_ai_level_directer(struct player *pplayer, enum ai_level level)
Definition difficulty.c:39
void diplhand_free(void)
Definition diplhand.c:96
void send_diplomatic_meetings(struct connection *dest)
Definition diplhand.c:912
void diplhand_init(void)
Definition diplhand.c:88
void free_treaties(void)
Definition diplhand.c:107
void set_diplstate_type(struct player_diplstate *state1, struct player_diplstate *state2, enum diplstate_type type)
Definition diplhand.c:159
void edithand_free(void)
Definition edithand.c:97
void edithand_init(void)
Definition edithand.c:79
int get_unit_bonus(const struct unit *punit, enum effect_type effect_type)
Definition effects.c:992
int get_player_bonus(const struct player *pplayer, enum effect_type effect_type)
Definition effects.c:771
bool extra_causes_env_upset(struct extra_type *pextra, enum environment_upset_type upset)
Definition extras.c:965
bool can_extra_appear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1076
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:186
bool can_extra_disappear(const struct extra_type *pextra, const struct tile *ptile)
Definition extras.c:1090
#define extra_type_iterate(_p)
Definition extras.h:291
#define extra_type_iterate_end
Definition extras.h:297
#define extra_type_by_rmcause_iterate_end
Definition extras.h:334
#define extra_type_by_rmcause_iterate(_rmcause, _extra)
Definition extras.h:329
#define extra_type_by_cause_iterate_end
Definition extras.h:315
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:309
void cmdline_option_values_free(void)
Definition fc_cmdline.c:97
void i_am_server(void)
void libfreeciv_init(bool check_fc_interface)
void libfreeciv_free(void)
struct functions * fc_interface_funcs(void)
environment_upset_type
Definition fc_types.h:1129
@ EUT_NUCLEAR_WINTER
Definition fc_types.h:1131
@ EUT_GLOBAL_WARMING
Definition fc_types.h:1130
int server_setting_id
Definition fc_types.h:924
int Tech_type_id
Definition fc_types.h:347
int Nation_type_id
Definition fc_types.h:350
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_LEN_NAME
Definition fc_types.h:66
@ VC_CULTURE
Definition fc_types.h:1125
@ VC_ALLIED
Definition fc_types.h:1124
@ O_SHIELD
Definition fc_types.h:91
@ O_FOOD
Definition fc_types.h:91
@ O_TRADE
Definition fc_types.h:91
@ BORDERS_ENABLED
Definition fc_types.h:892
@ BORDERS_DISABLED
Definition fc_types.h:891
#define IDENTITY_NUMBER_ZERO
Definition fc_types.h:82
void fcdb_free(void)
Definition fcdb.c:234
bool fcdb_init(const char *conf_file)
Definition fcdb.c:218
const char * get_internal_encoding(void)
Definition fciconv.c:182
static char void init_character_encodings(const char *my_internal_encoding, bool my_use_transliteration)
Definition fciconv.c:70
#define FC_DEFAULT_DATA_ENCODING
Definition fciconv.h:89
const char * get_locale_dir(void)
Definition fcintl.c:111
#define Q_(String)
Definition fcintl.h:70
#define bindtextdomain(Package, Directory)
Definition fcintl.h:82
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
void fc_destroy_mutex(fc_mutex *mutex)
void fc_init_mutex(fc_mutex *mutex)
const char * tile_link(const struct tile *ptile)
const struct ft_color ftc_server
const struct ft_color ftc_editor
const char * unit_tile_link(const struct unit *punit)
struct civ_game game
Definition game.c:57
bool is_player_phase(const struct player *pplayer, int phase)
Definition game.c:687
int current_turn_timeout(void)
Definition game.c:828
void game_init(bool keep_ruleset_value)
Definition game.c:429
struct world wld
Definition game.c:58
void game_free(void)
Definition game.c:459
void game_map_init(void)
Definition game.c:446
int generate_save_name(const char *format, char *buf, int buflen, const char *reason)
Definition game.c:771
#define TURNS_NEEDED_TO_RANK
Definition game.h:80
autosave_type
Definition game.h:59
@ AS_INTERRUPT
Definition game.h:63
@ AS_GAME_OVER
Definition game.h:61
@ AS_QUITIDLE
Definition game.h:62
@ AS_TIMER
Definition game.h:64
@ AS_TURN
Definition game.h:60
void send_year_to_clients(void)
Definition gamehand.c:879
int update_timeout(void)
Definition gamehand.c:983
void send_game_info(struct conn_list *dest)
Definition gamehand.c:905
void init_new_game(void)
Definition gamehand.c:449
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
Definition gamehand.c:118
struct city * owner
Definition citydlg.c:219
GType type
Definition repodlgs.c:1312
static GHashTable * hash
Definition wldlg.c:320
static char * leader_name
Definition dialogs.c:96
static struct gui_funcs funcs
bool server_handle_packet(enum packet_type type, const void *packet, struct player *pplayer, struct connection *pconn)
Definition hand_gen.c:20
void handle_conn_pong(struct connection *pc)
Definition sernet.c:1431
void handle_diplomacy_cancel_pact(struct player *pplayer, int other_player_id, enum clause_type clause)
Definition plrhand.c:761
void adv_city_free(struct city *pcity)
Definition infracache.c:501
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define fc_assert_exit_msg(condition, message,...)
Definition log.h:211
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_action_msg(condition, action, message,...)
Definition log.h:201
#define log_fatal(message,...)
Definition log.h:100
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
@ LOG_NORMAL
Definition log.h:32
#define log_error(message,...)
Definition log.h:103
#define log_testmatic(message,...)
Definition log.h:123
void main_map_free(void)
Definition map.c:552
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
Definition map.c:1488
int map_num_tiles(void)
Definition map.c:1012
bool startpos_allows_all(const struct startpos *psp)
Definition map.c:1499
void main_map_allocate(void)
Definition map.c:517
int map_startpos_count(void)
Definition map.c:1656
bool map_is_empty(void)
Definition map.c:149
#define map_startpos_iterate(NAME_psp)
Definition map.h:124
#define map_startpos_iterate_end
Definition map.h:127
#define whole_map_iterate(_map, _tile)
Definition map.h:539
#define whole_map_iterate_end
Definition map.h:548
@ MAPGEN_SCENARIO
Definition map_types.h:47
bool map_fractal_generate(bool autosize, struct unit_type *initial_unit)
Definition mapgen.c:1262
void generator_free(void)
void player_map_init(struct player *pplayer)
Definition maphand.c:1202
void map_set_border_vision(struct player *pplayer, const bool is_enabled)
Definition maphand.c:732
void send_map_info(struct conn_list *dest)
Definition maphand.c:644
void destroy_extra(struct tile *ptile, struct extra_type *pextra)
Definition maphand.c:2605
void disable_fog_of_war(void)
Definition maphand.c:1773
void show_map_to_all(void)
Definition maphand.c:1191
void send_all_known_tiles(struct conn_list *dest)
Definition maphand.c:441
struct vision_site * map_get_player_city(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1346
void enable_fog_of_war(void)
Definition maphand.c:1749
void create_extra(struct tile *ptile, struct extra_type *pextra, struct player *pplayer)
Definition maphand.c:2540
void map_show_all(struct player *pplayer)
Definition maphand.c:871
void map_show_tile(struct player *src_player, struct tile *ptile)
Definition maphand.c:760
void nuclear_winter(int effect)
Definition maphand.c:116
void tile_change_side_effects(struct tile *ptile, bool refresh_city)
Definition maphand.c:2708
bool map_is_known_and_seen(const struct tile *ptile, const struct player *pplayer, enum vision_layer vlayer)
Definition maphand.c:900
void map_calculate_borders(void)
Definition maphand.c:2357
void update_tile_knowledge(struct tile *ptile)
Definition maphand.c:1427
void give_shared_vision(struct player *pfrom, struct player *pto)
Definition maphand.c:1620
void global_warming(int effect)
Definition maphand.c:103
struct player_tile * map_get_player_tile(const struct tile *ptile, const struct player *pplayer)
Definition maphand.c:1370
void mapimg_free(void)
Definition mapimg.c:557
struct mapdef * mapimg_isvalid(int id)
Definition mapimg.c:1120
void mapimg_init(mapimg_tile_known_func mapimg_tile_known, mapimg_tile_terrain_func mapimg_tile_terrain, mapimg_tile_player_func mapimg_tile_owner, mapimg_tile_player_func mapimg_tile_city, mapimg_tile_player_func mapimg_tile_unit, mapimg_plrcolor_count_func mapimg_plrcolor_count, mapimg_plrcolor_get_func mapimg_plrcolor_get)
Definition mapimg.c:505
int mapimg_count(void)
Definition mapimg.c:572
bool mapimg_create(struct mapdef *pmapdef, bool force, const char *savename, const char *path)
Definition mapimg.c:1331
const char * mapimg_error(void)
Definition mapimg.c:758
void mapimg_reset(void)
Definition mapimg.c:540
void maybe_automatic_meta_message(const char *automatic)
Definition meta.c:151
char * meta_addr_port(void)
Definition meta.c:202
const char * default_meta_message_string(void)
Definition meta.c:90
bool send_server_info_to_metaserver(enum meta_flag flag)
Definition meta.c:490
bool server_open_meta(bool persistent)
Definition meta.c:463
#define DEFAULT_META_SERVER_ADDR
Definition meta.h:21
#define DEFAULT_META_SERVER_NO_SEND
Definition meta.h:20
@ META_INFO
Definition meta.h:26
@ META_REFRESH
Definition meta.h:27
static mpgui * gui
Definition mpgui_qt.cpp:52
const char * multiplier_name_translation(const struct multiplier *pmul)
Definition multipliers.c:97
bool multiplier_can_be_changed(struct multiplier *pmul, struct player *pplayer)
Multiplier_type_id multiplier_index(const struct multiplier *pmul)
Definition multipliers.c:80
#define multipliers_iterate(_mul_)
Definition multipliers.h:61
#define multipliers_iterate_end
Definition multipliers.h:67
struct nation_leader * nation_leader_by_name(const struct nation_type *pnation, const char *name)
Definition nation.c:266
bool nation_leader_is_male(const struct nation_leader *pleader)
Definition nation.c:289
const char * nation_adjective_for_player(const struct player *pplayer)
Definition nation.c:168
const char * nation_adjective_translation(const struct nation_type *pnation)
Definition nation.c:148
struct nation_type * nation_by_number(const Nation_type_id nation)
Definition nation.c:474
const struct nation_leader_list * nation_leaders(const struct nation_type *pnation)
Definition nation.c:229
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:443
bool is_nation_playable(const struct nation_type *nation)
Definition nation.c:199
int nation_set_count(void)
Definition nation.c:690
bool can_conn_edit_players_nation(const struct connection *pconn, const struct player *pplayer)
Definition nation.c:1186
const char * nation_leader_name(const struct nation_leader *pleader)
Definition nation.c:280
enum barbarian_type nation_barbarian_type(const struct nation_type *nation)
Definition nation.c:210
const char * nation_plural_for_player(const struct player *pplayer)
Definition nation.c:177
struct government * init_government_of_nation(const struct nation_type *pnation)
Definition nation.c:658
struct nation_style * style_of_nation(const struct nation_type *pnation)
Definition nation.c:671
#define nation_leader_list_iterate(leaderlist, pleader)
Definition nation.h:56
#define nations_iterate_end
Definition nation.h:335
#define nations_iterate(NAME_pnation)
Definition nation.h:332
#define nation_leader_list_iterate_end
Definition nation.h:58
#define NO_NATION_SELECTED
Definition nation.h:29
void fc_init_network(void)
Definition netintf.c:198
void notify_player(const struct player *pplayer, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:291
void event_cache_remove_old(void)
Definition notify.c:602
void send_pending_events(struct connection *pconn, bool include_public)
Definition notify.c:753
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
Definition notify.c:238
void event_cache_clear(void)
Definition notify.c:594
void event_cache_free(void)
Definition notify.c:582
void event_cache_phases_invalidate(void)
Definition notify.c:977
void event_cache_init(void)
Definition notify.c:570
void send_attribute_block(const struct player *pplayer, struct connection *pconn)
Definition packets.c:746
report_type
Definition packets.h:73
@ REPORT_WONDERS_OF_THE_WORLD
Definition packets.h:74
@ REPORT_DEMOGRAPHIC
Definition packets.h:76
@ REPORT_TOP_5_CITIES
Definition packets.h:75
@ REPORT_ACHIEVEMENTS
Definition packets.h:77
const char * packet_name(enum packet_type type)
Definition packets_gen.c:49
void lsend_packet_begin_turn(struct conn_list *dest)
int send_packet_end_phase(struct connection *pc)
void dlsend_packet_start_phase(struct conn_list *dest, int phase)
void lsend_packet_freeze_client(struct conn_list *dest)
void lsend_packet_end_phase(struct conn_list *dest)
void lsend_packet_achievement_info(struct conn_list *dest, const struct packet_achievement_info *packet)
void lsend_packet_end_turn(struct conn_list *dest)
void lsend_packet_thaw_client(struct conn_list *dest)
@ PACKET_SAVE_SCENARIO
@ PACKET_EDIT_MODE
@ PACKET_EDIT_GAME
@ PACKET_NATION_SELECT_REQ
@ PACKET_SERVER_JOIN_REQ
@ PACKET_REPORT_REQ
@ PACKET_CHAT_MSG_REQ
@ PACKET_CLIENT_HEARTBEAT
@ PACKET_CLIENT_INFO
@ PACKET_AUTHENTICATION_REPLY
@ PACKET_SINGLE_WANT_HACK_REQ
@ PACKET_VOTE_SUBMIT
@ PACKET_PLAYER_READY
@ PACKET_CONN_PONG
struct player * player_by_number(const int player_id)
Definition player.c:840
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Definition player.c:1452
int player_count(void)
Definition player.c:808
int player_slot_count(void)
Definition player.c:411
int player_number(const struct player *pplayer)
Definition player.c:828
const char * player_name(const struct player *pplayer)
Definition player.c:886
struct player * player_by_name(const char *name)
Definition player.c:872
int player_index(const struct player *pplayer)
Definition player.c:820
struct player * player_by_user(const char *name)
Definition player.c:931
bool player_set_nation(struct player *pplayer, struct nation_type *pnation)
Definition player.c:852
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Definition player.c:317
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
Definition player.c:1381
#define players_iterate_end
Definition player.h:535
#define players_iterate(_pplayer)
Definition player.h:530
#define player_list_iterate(playerlist, pplayer)
Definition player.h:553
#define ANON_USER_NAME
Definition player.h:48
static bool is_barbarian(const struct player *pplayer)
Definition player.h:488
#define is_ai(plr)
Definition player.h:234
#define player_list_iterate_end
Definition player.h:555
#define players_iterate_alive_end
Definition player.h:545
#define set_as_ai(plr)
Definition player.h:236
#define ANON_PLAYER_NAME
Definition player.h:43
#define is_human(plr)
Definition player.h:233
#define players_iterate_alive(_pplayer)
Definition player.h:540
void server_player_set_name(struct player *pplayer, const char *name)
Definition plrhand.c:2097
void send_player_all_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:983
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Definition plrhand.c:1723
void player_status_add(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3042
int normal_player_count(void)
Definition plrhand.c:3034
void playercolor_free(void)
Definition plrhand.c:3171
void player_limit_to_max_rates(struct player *pplayer)
Definition plrhand.c:1886
bool server_player_set_name_full(const struct connection *caller, struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
Definition plrhand.c:1997
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
Definition plrhand.c:2282
void playercolor_init(void)
Definition plrhand.c:3162
void kill_player(struct player *pplayer)
Definition plrhand.c:125
void send_player_info_c(struct player *src, struct conn_list *dest)
Definition plrhand.c:1000
bool player_status_check(struct player *plr, enum player_status pstatus)
Definition plrhand.c:3050
struct rgbcolor * playercolor_get(int id)
Definition plrhand.c:3200
int playercolor_count(void)
Definition plrhand.c:3210
void shuffle_players(void)
Definition plrhand.c:2207
void server_remove_player(struct player *pplayer)
Definition plrhand.c:1772
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Definition plrhand.c:1450
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Definition plrhand.c:2132
void update_capital(struct player *pplayer)
Definition plrhand.c:612
void assign_player_colors(void)
Definition plrhand.c:1563
bool client_can_pick_nation(const struct nation_type *pnation)
Definition plrhand.c:2443
bool nation_is_in_current_set(const struct nation_type *pnation)
Definition plrhand.c:2419
void enter_war(struct player *pplayer, struct player *pplayer2)
Definition plrhand.c:729
void update_revolution(struct player *pplayer)
Definition plrhand.c:553
#define alive_phase_players_iterate(pplayer)
Definition plrhand.h:121
#define alive_phase_players_iterate_end
Definition plrhand.h:126
#define phase_players_iterate(pplayer)
Definition plrhand.h:111
#define allowed_nations_iterate(pnation)
Definition plrhand.h:67
#define allowed_nations_iterate_end
Definition plrhand.h:71
#define phase_players_iterate_end
Definition plrhand.h:116
bool fc_rand_is_init(void)
Definition rand.c:167
void fc_srand(RANDOM_TYPE seed)
Definition rand.c:128
void test_random1(int n)
Definition rand.c:220
void fc_rand_uninit(void)
Definition rand.c:159
#define fc_rand(_size)
Definition rand.h:34
randseed generate_game_seed(void)
Definition randseed.c:192
void registry_module_init(void)
Definition registry.c:30
void registry_module_close(void)
Definition registry.c:40
void report_final_scores(struct conn_list *dest)
Definition report.c:1555
void report_wonders_of_the_world(struct conn_list *dest)
Definition report.c:401
void report_demographics(struct connection *pconn)
Definition report.c:993
void report_top_five_cities(struct conn_list *dest)
Definition report.c:327
void make_history_report(void)
Definition report.c:1533
void log_civ_score_free(void)
Definition report.c:1302
void report_achievements(struct connection *pconn)
Definition report.c:1057
void log_civ_score_now(void)
Definition report.c:1332
int player_tech_upkeep(const struct player *pplayer)
Definition research.c:1040
struct research * research_get(const struct player *pplayer)
Definition research.c:126
Tech_type_id research_goal_step(const struct research *presearch, Tech_type_id goal)
Definition research.c:717
#define researches_iterate(_presearch)
Definition research.h:157
#define researches_iterate_end
Definition research.h:160
void rulesets_deinit(void)
Definition ruleset.c:9311
bool load_rulesets(const char *restore, const char *alt, bool compat_mode, rs_conversion_logger logger, bool act, bool buffer_script, bool load_luadata)
Definition ruleset.c:9227
#define sanity_check()
Definition sanitycheck.h:43
void save_system_close(void)
Definition savemain.c:334
void save_game(const char *orig_filename, const char *save_reason, bool scenario)
Definition savemain.c:142
void calc_civ_score(struct player *pplayer)
Definition score.c:251
void rank_users(bool interrupt)
Definition score.c:417
int total_player_citizens(const struct player *pplayer)
Definition score.c:382
void script_server_signal_emit(const char *signal_name,...)
int server_open_socket(void)
Definition sernet.c:1127
void flush_packets(void)
Definition sernet.c:379
void init_connections(void)
Definition sernet.c:1355
enum server_events server_sniff_all_input(void)
Definition sernet.c:524
void readline_atexit(void)
Definition sernet.c:209
void close_connections_and_socket(void)
Definition sernet.c:259
@ S_E_OTHERWISE
Definition sernet.h:30
@ S_E_FORCE_END_OF_SNIFF
Definition sernet.h:31
#define SERVER_SETTING_NONE
void settings_init(bool act)
Definition settings.c:4952
int setting_int_get(struct setting *pset)
Definition settings.c:3608
struct setting * setting_by_name(const char *name)
Definition settings.c:3138
const char * setting_value_name(const struct setting *pset, bool pretty, char *buf, size_t buf_len)
Definition settings.c:4066
int setting_number(const struct setting *pset)
Definition settings.c:3153
struct setting * setting_by_number(int id)
Definition settings.c:3130
enum sset_type setting_type(const struct setting *pset)
Definition settings.c:3191
void settings_free(void)
Definition settings.c:4993
void settings_turn(void)
Definition settings.c:4985
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:183
void settings_game_start(void)
Definition settings.c:4548
bool setting_enum_set(struct setting *pset, const char *val, struct connection *caller, char *reject_msg, size_t reject_msg_len)
Definition settings.c:3832
const char * setting_name(const struct setting *pset)
Definition settings.c:3162
int setting_bitwise_get(struct setting *pset)
Definition settings.c:4056
bool setting_bool_get(struct setting *pset)
Definition settings.c:3496
void send_server_settings(struct conn_list *dest)
Definition settings.c:5133
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#define MAX_UINT32
Definition shared.h:81
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MIN(x, y)
Definition shared.h:55
#define MAX(x, y)
Definition shared.h:54
int rank_spaceship_arrival(struct player **result)
Definition spacerace.c:459
double spaceship_arrival(const struct player *pplayer)
Definition spacerace.c:445
void send_spaceship_info(struct player *src, struct conn_list *dest)
Definition spacerace.c:128
void spaceship_arrived(struct player *pplayer)
Definition spacerace.c:419
size_t size
Definition specvec.h:72
void timing_log_init(void)
Definition srv_log.c:217
void timing_log_free(void)
Definition srv_log.c:231
static void srv_prepare(void)
Definition srv_main.c:2965
static struct player * mapimg_server_tile_owner(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3682
static void server_gui_color_free(struct color *pcolor)
Definition srv_main.c:3515
void server_game_init(bool keep_ruleset_value)
Definition srv_main.c:3382
static struct terrain * mapimg_server_tile_terrain(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3668
static struct player * mapimg_server_tile_city(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3698
static void update_diplomatics(void)
Definition srv_main.c:886
static struct player * mapimg_server_tile_unit(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3724
void handle_nation_select_req(struct connection *pc, int player_no, Nation_type_id nation_no, bool is_male, const char *name, int style)
Definition srv_main.c:2259
static void do_have_contacts_effect(void)
Definition srv_main.c:733
static void ai_start_phase(void)
Definition srv_main.c:1074
static struct timer * eot_timer
Definition srv_main.c:193
const char * pick_random_player_name(const struct nation_type *pnation)
Definition srv_main.c:2733
void identity_number_release(int id)
Definition srv_main.c:1918
void player_nation_defaults(struct player *pplayer, struct nation_type *pnation, bool set_name)
Definition srv_main.c:2510
static void handle_observer_ready(struct connection *pconn)
Definition srv_main.c:2325
bv_id identity_numbers_used
Definition srv_main.c:187
void srv_main(void)
Definition srv_main.c:3451
void handle_report_req(struct connection *pconn, enum report_type type)
Definition srv_main.c:1882
static void generate_players(void)
Definition srv_main.c:2561
bool force_end_of_sniff
Definition srv_main.c:185
static void do_reveal_effects(void)
Definition srv_main.c:710
static int mapimg_server_plrcolor_count(void)
Definition srv_main.c:3745
void start_game(void)
Definition srv_main.c:1773
void handle_client_info(struct connection *pc, enum gui_type gui, int emerg_version, const char *distribution)
Definition srv_main.c:307
void handle_player_ready(struct player *requestor, int player_no, bool is_ready)
Definition srv_main.c:2341
const char * aifill(int amount)
Definition srv_main.c:2395
static bool identity_number_is_used(int id)
Definition srv_main.c:1934
static void end_phase(void)
Definition srv_main.c:1357
static enum server_states civserver_state
Definition srv_main.c:179
static void begin_turn(bool is_new_turn)
Definition srv_main.c:1089
static void end_turn(void)
Definition srv_main.c:1513
void save_game_auto(const char *save_reason, enum autosave_type type)
Definition srv_main.c:1732
static struct rgbcolor * mapimg_server_plrcolor_get(int i)
Definition srv_main.c:3753
void set_server_state(enum server_states newstate)
Definition srv_main.c:331
static int increment_identity_number(void)
Definition srv_main.c:1942
const char * server_ss_name_get(server_setting_id id)
Definition srv_main.c:3553
static void begin_phase(bool is_new_phase)
Definition srv_main.c:1196
static void update_environmental_upset(enum environment_upset_type type, int *current, int *accum, int *level, int percent, void(*upset_action_fn)(int))
Definition srv_main.c:777
static void kill_dying_players(void)
Definition srv_main.c:1048
bool game_was_started(void)
Definition srv_main.c:339
static void srv_scores(void)
Definition srv_main.c:3062
#define startpos_hash_iterate(hash, psp, c)
Definition srv_main.c:2493
void identity_number_reserve(int id)
Definition srv_main.c:1926
struct server_arguments srvarg
Definition srv_main.c:173
static void srv_ready(void)
Definition srv_main.c:3118
static void srv_running(void)
Definition srv_main.c:2779
static void final_ruleset_adjustments(void)
Definition srv_main.c:3092
#define startpos_hash_iterate_end
Definition srv_main.c:2495
static int server_plr_tile_city_id_get(const struct tile *ptile, const struct player *pplayer)
Definition srv_main.c:3526
static bool is_client_edit_packet(int type)
Definition srv_main.c:1974
static void notify_illegal_armistice_units(struct player *phost, struct player *pguest, int turns_left)
Definition srv_main.c:815
bool server_ss_val_bool_get(server_setting_id id)
Definition srv_main.c:3583
static void remove_illegal_armistice_units(struct player *plr1, struct player *plr2)
Definition srv_main.c:854
int identity_number(void)
Definition srv_main.c:1952
server_setting_id server_ss_by_name(const char *name)
Definition srv_main.c:3538
void check_for_full_turn_done(void)
Definition srv_main.c:2145
static void player_set_nation_full(struct player *pplayer, struct nation_type *pnation)
Definition srv_main.c:2500
static void announce_player(struct player *pplayer)
Definition srv_main.c:2761
void srv_init(void)
Definition srv_main.c:224
bool server_packet_input(struct connection *pconn, void *packet, int type)
Definition srv_main.c:1983
static void fc_interface_init_server(void)
Definition srv_main.c:3628
int server_ss_val_int_get(server_setting_id id)
Definition srv_main.c:3598
static struct timer * between_turns
Definition srv_main.c:195
unsigned int server_ss_val_bitwise_get(server_setting_id id)
Definition srv_main.c:3613
static bool has_been_srv_init
Definition srv_main.c:190
void send_all_info(struct conn_list *dest)
Definition srv_main.c:682
void init_game_seed(void)
Definition srv_main.c:200
void update_nations_with_startpos(void)
Definition srv_main.c:2200
void server_quit(void)
Definition srv_main.c:1810
enum sset_type server_ss_type_get(server_setting_id id)
Definition srv_main.c:3568
bool check_for_game_over(void)
Definition srv_main.c:353
static enum known_type mapimg_server_tile_known(const struct tile *ptile, const struct player *pplayer, bool knowledge)
Definition srv_main.c:3653
static void do_border_vision_effect(void)
Definition srv_main.c:750
enum server_states server_state(void)
Definition srv_main.c:323
void server_game_free(void)
Definition srv_main.c:3406
#define IDENTITY_NUMBER_SIZE
Definition srv_main.h:71
#define IDENTITY_NUMBER_SKIP
Definition srv_main.h:85
bool read_init_script(struct connection *caller, char *script_filename, bool from_cmdline, bool check)
Definition stdinhand.c:1167
void set_running_game_access_level(void)
Definition stdinhand.c:1633
void stdinhand_turn(void)
Definition stdinhand.c:254
void stdinhand_init(void)
Definition stdinhand.c:241
void set_ai_level_direct(struct player *pplayer, enum ai_level level)
Definition stdinhand.c:2003
void stdinhand_free(void)
Definition stdinhand.c:262
bool load_command(struct connection *caller, const char *filename, bool check, bool cmdline_load)
Definition stdinhand.c:3733
bool start_command(struct connection *caller, bool check, bool notify)
Definition stdinhand.c:6044
void toggle_ai_player_direct(struct connection *caller, struct player *pplayer)
Definition stdinhand.c:704
Definition city.h:309
int num_phases
Definition game.h:168
void(* unit_deallocate)(int unit_id)
Definition game.h:293
struct civ_game::@30::@34 server
char start_units[MAX_LEN_STARTUNIT]
Definition game.h:188
int save_nturns
Definition game.h:182
float turn_change_time
Definition game.h:217
bool fixedlength
Definition game.h:145
struct packet_ruleset_control control
Definition game.h:83
struct civ_game::@32 callbacks
bool fogofwar_old
Definition game.h:232
int end_turn
Definition game.h:143
fc_mutex city_list
Definition game.h:267
struct conn_list * est_connections
Definition game.h:97
struct packet_game_info info
Definition game.h:89
unsigned autosaves
Definition game.h:184
struct timer * save_timer
Definition game.h:216
bool endspaceship
Definition game.h:144
char rulesetdir[MAX_LEN_NAME]
Definition game.h:236
int start_year
Definition game.h:190
bool migration
Definition game.h:163
int additional_phase_seconds
Definition game.h:211
randseed seed
Definition game.h:225
struct packet_scenario_info scenario
Definition game.h:87
struct civ_game::@30::@34::@38 mutexes
randseed seed_setting
Definition game.h:224
struct timer * phase_timer
Definition game.h:210
int nuclear_winter_percent
Definition game.h:230
unsigned revealmap
Definition game.h:176
char save_name[MAX_LEN_NAME]
Definition game.h:219
struct packet_timeout_info tinfo
Definition game.h:91
int phase_mode_stored
Definition game.h:215
int max_players
Definition game.h:155
bool auto_ai_toggle
Definition game.h:129
int global_warming_percent
Definition game.h:228
struct government * government_during_revolution
Definition game.h:94
bool turnblock
Definition game.h:196
int xsize
Definition map_types.h:77
int ysize
Definition map_types.h:77
bool have_resources
Definition map_types.h:107
randseed seed_setting
Definition map_types.h:88
struct civ_map::@41::@43 server
enum map_generator generator
Definition map_types.h:95
Definition colors.h:20
bool established
Definition connection.h:145
struct player * playing
Definition connection.h:156
enum cmdlevel access_level
Definition connection.h:182
struct conn_list * self
Definition connection.h:168
bool observer
Definition connection.h:152
char username[MAX_LEN_NAME]
Definition connection.h:169
enum gui_type client_gui
Definition connection.h:184
struct government * init_government
Definition nation.h:123
struct player * player
Definition nation.h:117
enum borders_mode borders
enum ai_level skill_level
enum phase_mode_type phase_mode
enum ai_level skill_level
Definition player.h:122
char contact_turns_left
Definition player.h:206
int auto_cancel_turn
Definition player.h:208
int first_contact_turn
Definition player.h:203
enum diplstate_type type
Definition player.h:201
char has_reason_to_cancel
Definition player.h:205
int culture
Definition player.h:115
struct vision_site * site
Definition maphand.h:31
struct terrain * terrain
Definition maphand.h:33
struct player * owner
Definition maphand.h:34
bool random_name
Definition player.h:295
struct player_ai ai_common
Definition player.h:288
bool is_male
Definition player.h:257
char username[MAX_LEN_NAME]
Definition player.h:252
bool is_winner
Definition player.h:269
bool is_connected
Definition player.h:296
int nturns_idle
Definition player.h:265
struct connection * current_conn
Definition player.h:297
struct team * team
Definition player.h:261
bool was_created
Definition player.h:294
const struct ai_type * ai
Definition player.h:289
struct unit_list * units
Definition player.h:282
bool is_alive
Definition player.h:268
struct player_score score
Definition player.h:283
struct nation_type * nation
Definition player.h:260
struct nation_style * style
Definition player.h:279
bool is_ready
Definition player.h:262
bool unassigned_user
Definition player.h:253
Tech_type_id researching
Definition research.h:52
Tech_type_id tech_goal
Definition research.h:85
bool got_tech_multi
Definition research.h:69
Tech_type_id researching_saved
Definition research.h:62
bool got_tech
Definition research.h:67
bool metaconnection_persistent
Definition srv_main.h:30
char * bind_addr
Definition srv_main.h:34
enum log_level loglevel
Definition srv_main.h:40
char metaserver_addr[256]
Definition srv_main.h:29
char * scenarios_pathname
Definition srv_main.h:47
char load_filename[512]
Definition srv_main.h:44
char * fcdb_conf
Definition srv_main.h:56
bool auth_allow_guests
Definition srv_main.h:58
char * saves_pathname
Definition srv_main.h:46
char * log_filename
Definition srv_main.h:42
char * ranklog_filename
Definition srv_main.h:43
bool metaserver_no_send
Definition srv_main.h:28
char * bind_meta_addr
Definition srv_main.h:38
bool auth_allow_newusers
Definition srv_main.h:59
char * script_filename
Definition srv_main.h:45
char serverid[256]
Definition srv_main.h:49
char identity_name[256]
Definition srv_main.h:31
char *const value
Definition settings.c:143
Definition tile.h:49
struct unit_list * units
Definition tile.h:57
Definition timing.c:81
Definition unit.h:138
struct vision * vision
Definition unit.h:242
struct tile * tile
Definition unit.h:140
struct unit::@80::@83 server
int identity
Definition vision.h:114
struct player * owner
Definition vision.h:112
v_radius_t radius_sq
Definition vision.h:92
struct civ_map map
struct nation_style * style_by_number(int id)
Definition style.c:88
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:969
#define sz_strlcpy(dest, src)
Definition support.h:167
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
int team_count(void)
Definition team.c:375
const char * team_name_translation(const struct team *pteam)
Definition team.c:420
const struct player_list * team_members(const struct team *pteam)
Definition team.c:456
#define teams_iterate_end
Definition team.h:85
#define teams_iterate(_pteam)
Definition team.h:80
#define A_UNSET
Definition tech.h:48
#define A_UNKNOWN
Definition tech.h:49
void init_tech(struct research *research, bool update)
Definition techtools.c:1070
void choose_tech(struct research *research, Tech_type_id tech)
Definition techtools.c:983
void do_tech_parasite_effect(struct player *pplayer)
Definition techtools.c:143
void send_research_info(const struct research *presearch, const struct conn_list *dest)
Definition techtools.c:273
void choose_random_tech(struct research *research)
Definition techtools.c:968
void update_bulbs(struct player *pplayer, int bulbs, bool check_tech)
Definition techtools.c:643
void give_initial_techs(struct research *presearch, int num_random_techs)
Definition techtools.c:1162
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:552
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
#define tile_worked(_tile)
Definition tile.h:113
known_type
Definition tile.h:34
@ TILE_KNOWN_SEEN
Definition tile.h:37
#define tile_terrain(_tile)
Definition tile.h:109
#define tile_has_extra(ptile, pextra)
Definition tile.h:146
#define tile_owner(_tile)
Definition tile.h:95
struct timer * timer_new(enum timer_timetype type, enum timer_use use)
Definition timing.c:157
void timer_clear(struct timer *t)
Definition timing.c:212
void timer_destroy(struct timer *t)
Definition timing.c:191
void timer_start(struct timer *t)
Definition timing.c:224
double timer_read_seconds(struct timer *t)
Definition timing.c:344
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use)
Definition timing.c:176
@ TIMER_ACTIVE
Definition timing.h:45
@ TIMER_CPU
Definition timing.h:40
@ TIMER_USER
Definition timing.h:41
static int best_value(const void *a, const void *b)
bool is_military_unit(const struct unit *punit)
Definition unit.c:319
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2623
#define unit_tile(_pu)
Definition unit.h:395
#define unit_owner(_pu)
Definition unit.h:394
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_safe(unitlist, _unit)
Definition unitlist.h:39
#define unit_list_iterate_end
Definition unitlist.h:33
#define unit_list_iterate_safe_end
Definition unitlist.h:61
void update_unit_activities(struct player *pplayer)
Definition unittools.c:658
void finalize_unit_phase_beginning(struct player *pplayer)
Definition unittools.c:690
void execute_unit_orders(struct player *pplayer)
Definition unittools.c:668
void wipe_unit(struct unit *punit, enum unit_loss_reason reason, struct player *killer)
Definition unittools.c:2247
void unit_tc_effect_refresh(struct player *pplayer)
Definition unittools.c:680
void player_restore_units(struct player *pplayer)
Definition unittools.c:469
bool unit_can_be_retired(struct unit *punit)
Definition unittools.c:4928
void send_all_known_units(struct conn_list *dest)
Definition unittools.c:2838
struct unit_type * get_role_unit(int role, int role_index)
Definition unittype.c:2301
const char * unstable_message(void)
Definition version.c:160
bool victory_enabled(enum victory_condition_type victory)
Definition victory.c:26
void vision_free(struct vision *vision)
Definition vision.c:50
#define vision_layer_iterate(v)
Definition vision.h:77
#define vision_layer_iterate_end
Definition vision.h:80
void send_updated_vote_totals(struct conn_list *dest)
Definition voting.c:866
void voting_turn(void)
Definition voting.c:718
void clear_all_votes(void)
Definition voting.c:219
void voting_init(void)
Definition voting.c:707
void voting_free(void)
Definition voting.c:734