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 #ifndef FC__PLRHAND_H
14 #define FC__PLRHAND_H
15 
16 struct connection;
17 struct conn_list;
18 struct nation_type;
19 struct player;
20 struct rgbcolor;
21 struct section_file;
22 struct unit_list;
23 
24 enum plr_info_level { INFO_MINIMUM, INFO_MEETING, INFO_EMBASSY, INFO_FULL };
25 
26 struct player *server_create_player(int player_id, const char *ai_tname,
27                                     struct rgbcolor *prgbcolor,
28                                     bool allow_ai_type_fallbacking);
29 const struct rgbcolor *player_preferred_color(struct player *pplayer);
30 bool player_color_changeable(const struct player *pplayer, const char **reason);
31 void assign_player_colors(void);
32 void server_player_set_color(struct player *pplayer,
33                              const struct rgbcolor *prgbcolor);
34 const char *player_color_ftstr(struct player *pplayer);
35 void server_player_init(struct player *pplayer, bool initmap,
36                         bool needs_team);
37 void give_midgame_initial_units(struct player *pplayer, struct tile *ptile);
38 void server_remove_player(struct player *pplayer);
39 void kill_player(struct player *pplayer);
40 void update_revolution(struct player *pplayer);
41 void government_change(struct player *pplayer, struct government *gov,
42                        bool revolution_finished);
43 int revolution_length(struct government *gov, struct player *plr);
44 
45 struct player_economic player_limit_to_max_rates(struct player *pplayer);
46 
47 void server_player_set_name(struct player *pplayer, const char *name);
48 bool server_player_set_name_full(const struct connection *caller,
49                                  struct player *pplayer,
50                                  const struct nation_type *pnation,
51                                  const char *name,
52                                  char *error_buf, size_t error_buf_len);
53 
54 struct nation_type *pick_a_nation(const struct nation_list *choices,
55                                   bool ignore_conflicts,
56                                   bool needs_startpos,
57                                   enum barbarian_type barb_type);
58 bool nation_is_in_current_set(const struct nation_type *pnation);
59 bool client_can_pick_nation(const struct nation_type *nation);
60 void count_playable_nations(void);
61 void send_nation_availability(struct conn_list *dest, bool nationset_change);
62 void fit_nationset_to_players(void);
63 
64 /* Iterate over nations in the currently selected set.
65  * Does not filter on playability or anything else. */
66 #define allowed_nations_iterate(pnation)                            \
67   nations_iterate(pnation) {                                        \
68     if (nation_is_in_current_set(pnation)) {
69 
70 #define allowed_nations_iterate_end                                 \
71     }                                                               \
72   } nations_iterate_end
73 
74 void check_player_max_rates(struct player *pplayer);
75 void make_contact(struct player *pplayer1, struct player *pplayer2,
76 		  struct tile *ptile);
77 void maybe_make_contact(struct tile *ptile, struct player *pplayer);
78 void enter_war(struct player *pplayer, struct player *pplayer2);
79 void player_update_last_war_action(struct player *pplayer);
80 
81 void player_info_freeze(void);
82 void player_info_thaw(void);
83 
84 void send_player_all_c(struct player *src, struct conn_list *dest);
85 void send_player_info_c(struct player *src, struct conn_list *dest);
86 void send_player_diplstate_c(struct player *src, struct conn_list *dest);
87 
88 struct conn_list *player_reply_dest(struct player *pplayer);
89 
90 void shuffle_players(void);
91 void set_shuffled_players(int *shuffled_players);
92 struct player *shuffled_player(int i);
93 void reset_all_start_commands(bool plrchange);
94 
95 #define shuffled_players_iterate(NAME_pplayer)\
96 do {\
97   int MY_i;\
98   struct player *NAME_pplayer;\
99   log_debug("shuffled_players_iterate @ %s line %d",\
100             __FILE__, __FC_LINE__);\
101   for (MY_i = 0; MY_i < player_slot_count(); MY_i++) {\
102     NAME_pplayer = shuffled_player(MY_i);\
103     if (NAME_pplayer != NULL) {\
104 
105 #define shuffled_players_iterate_end\
106     }\
107   }\
108 } while (0)
109 
110 #define phase_players_iterate(pplayer)\
111 do {\
112   shuffled_players_iterate(pplayer) {\
113     if (is_player_phase(pplayer, game.info.phase)) {
114 
115 #define phase_players_iterate_end\
116     }\
117   } shuffled_players_iterate_end;\
118 } while (FALSE);
119 
120 #define alive_phase_players_iterate(pplayer) \
121 do { \
122   phase_players_iterate(pplayer) { \
123     if (pplayer->is_alive) {
124 
125 #define alive_phase_players_iterate_end \
126     } \
127   } phase_players_iterate_end \
128 } while (FALSE);
129 
130 bool civil_war_possible(struct player *pplayer, bool conquering_city,
131                         bool honour_server_option);
132 bool civil_war_triggered(struct player *pplayer);
133 struct player *civil_war(struct player *pplayer);
134 
135 void update_players_after_alliance_breakup(struct player *pplayer,
136                                            struct player *pplayer2,
137                                            const struct unit_list
138                                                *pplayer_seen_units,
139                                            const struct unit_list
140                                                *pplayer2_seen_units);
141 
142 /* Player counts, total player_count() is in common/player.c */
143 int barbarian_count(void);
144 int normal_player_count(void);
145 
146 void player_status_add(struct player *plr, enum player_status status);
147 bool player_status_check(struct player *plr, enum player_status status);
148 void player_status_reset(struct player *plr);
149 
150 const char *player_delegation_get(const struct player *pplayer);
151 void player_delegation_set(struct player *pplayer, const char *username);
152 bool player_delegation_active(const struct player *pplayer);
153 
154 void send_delegation_info(const struct connection *pconn);
155 
156 struct player *player_by_user_delegated(const char *name);
157 
158 /* player colors */
159 void playercolor_init(void);
160 void playercolor_free(void);
161 
162 int playercolor_count(void);
163 void playercolor_add(struct rgbcolor *prgbcolor);
164 struct rgbcolor *playercolor_get(int id);
165 
166 void player_set_to_ai_mode(struct player *pplayer,
167                            enum ai_level skill_level);
168 void player_set_under_human_control(struct player *pplayer);
169 
170 #endif  /* FC__PLRHAND_H */
171