Freeciv21
Develop your civilization from humble roots to a global empire
plrhand.h
Go to the documentation of this file.
1 /*__ ___ ***************************************
2 / \ / \ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3 \_ \ / __/ contributors. This file is part of Freeciv21.
4  _\ \ / /__ Freeciv21 is free software: you can redistribute it
5  \___ \____/ __/ and/or modify it under the terms of the GNU General
6  \_ _/ Public License as published by the Free Software
7  | @ @ \_ Foundation, either version 3 of the License,
8  | or (at your option) any later version.
9  _/ /\ You should have received a copy of the GNU
10  /o) (o/\ \_ General Public License along with Freeciv21.
11  \_____/ / If not, see https://www.gnu.org/licenses/.
12  \____/ ********************************************************/
13 #pragma once
14 
15 struct connection;
16 struct conn_list;
17 struct nation_type;
18 struct player;
19 struct rgbcolor;
20 struct section_file;
21 struct unit_list;
22 
23 struct player *server_create_player(int player_id, const char *ai_tname,
24  struct rgbcolor *prgbcolor,
25  bool allow_ai_type_fallbacking);
26 const struct rgbcolor *player_preferred_color(struct player *pplayer);
27 bool player_color_changeable(const struct player *pplayer,
28  const char **reason);
30 void server_player_set_color(struct player *pplayer,
31  const struct rgbcolor *prgbcolor);
32 const char *player_color_ftstr(struct player *pplayer);
33 void server_player_init(struct player *pplayer, bool initmap,
34  bool needs_team);
35 void give_midgame_initial_units(struct player *pplayer, struct tile *ptile);
36 void server_remove_player(struct player *pplayer);
37 void kill_player(struct player *pplayer);
38 void update_revolution(struct player *pplayer);
39 void government_change(struct player *pplayer, struct government *gov,
40  bool revolution_finished);
41 int revolution_length(struct government *gov, struct player *plr);
42 void update_capital(struct player *pplayer);
43 
44 struct player_economic player_limit_to_max_rates(struct player *pplayer);
45 
46 void server_player_set_name(struct player *pplayer, const char *name);
47 bool server_player_set_name_full(const struct connection *caller,
48  struct player *pplayer,
49  const struct nation_type *pnation,
50  const char *name, char *error_buf,
51  size_t error_buf_len);
52 
53 struct nation_type *pick_a_nation(const struct nation_list *choices,
54  bool ignore_conflicts, bool needs_startpos,
55  enum barbarian_type barb_type);
56 bool nation_is_in_current_set(const struct nation_type *pnation);
57 bool client_can_pick_nation(const struct nation_type *nation);
59 void send_nation_availability(struct conn_list *dest, bool nationset_change);
61 
62 void check_player_max_rates(struct player *pplayer);
63 void make_contact(struct player *pplayer1, struct player *pplayer2,
64  struct tile *ptile);
65 void maybe_make_contact(struct tile *ptile, struct player *pplayer);
66 void enter_war(struct player *pplayer, struct player *pplayer2);
67 void player_update_last_war_action(struct player *pplayer);
68 
69 void player_info_freeze();
70 void player_info_thaw();
71 
72 void send_player_all_c(struct player *src, struct conn_list *dest);
73 void send_player_info_c(struct player *src, struct conn_list *dest);
74 void send_player_diplstate_c(struct player *src, struct conn_list *dest);
75 
76 struct conn_list *player_reply_dest(struct player *pplayer);
77 
78 void shuffle_players();
79 void set_shuffled_players(int *shuffled_players);
80 struct player *shuffled_player(int i);
81 void reset_all_start_commands(bool plrchange);
82 
83 #define shuffled_players_iterate(NAME_pplayer) \
84  do { \
85  int MY_i; \
86  struct player *NAME_pplayer; \
87  log_debug("shuffled_players_iterate @ %s line %d", __FILE__, \
88  __FC_LINE__); \
89  for (MY_i = 0; MY_i < MAX_NUM_PLAYER_SLOTS; MY_i++) { \
90  NAME_pplayer = shuffled_player(MY_i); \
91  if (NAME_pplayer != nullptr) {
92 
93 #define shuffled_players_iterate_end \
94  } \
95  } \
96  } \
97  while (false)
98 
99 #define phase_players_iterate(pplayer) \
100  do { \
101  shuffled_players_iterate(pplayer) \
102  { \
103  if (is_player_phase(pplayer, game.info.phase)) {
104 
105 #define phase_players_iterate_end \
106  } \
107  } \
108  shuffled_players_iterate_end; \
109  } \
110  while (false) \
111  ;
112 
113 #define alive_phase_players_iterate(pplayer) \
114  do { \
115  phase_players_iterate(pplayer) \
116  { \
117  if (pplayer->is_alive) {
118 
119 #define alive_phase_players_iterate_end \
120  } \
121  } \
122  phase_players_iterate_end \
123  } \
124  while (false) \
125  ;
126 
127 bool civil_war_possible(struct player *pplayer, bool conquering_city,
128  bool honour_server_option);
129 bool civil_war_triggered(struct player *pplayer);
130 struct player *civil_war(struct player *pplayer);
131 
133  struct player *pplayer, struct player *pplayer2,
134  const struct unit_list *pplayer_seen_units,
135  const struct unit_list *pplayer2_seen_units);
136 
137 int normal_player_count();
138 
139 void player_status_add(struct player *plr, enum player_status status);
140 bool player_status_check(struct player *plr, enum player_status status);
141 void player_status_reset(struct player *plr);
142 
143 const char *player_delegation_get(const struct player *pplayer);
144 void player_delegation_set(struct player *pplayer, const char *username);
145 bool player_delegation_active(const struct player *pplayer);
146 
147 void send_delegation_info(const struct connection *pconn);
148 
149 struct player *player_by_user_delegated(const char *name);
150 
151 void handle_diplomacy_cancel_pact_explicit(struct player *pplayer,
152  int other_player_id,
153  enum clause_type clause,
154  bool protect_alliances);
155 
156 // player colors
157 void playercolor_init();
158 void playercolor_free();
159 
160 int playercolor_count();
161 void playercolor_add(struct rgbcolor *prgbcolor);
162 struct rgbcolor *playercolor_get(int id);
163 
164 void player_set_to_ai_mode(struct player *pplayer,
165  enum ai_level skill_level);
166 void player_set_under_human_control(struct player *pplayer);
const char * name
Definition: inputfile.cpp:118
struct conn_list * player_reply_dest(struct player *pplayer)
Convenience function to return "reply" destination connection list for player: pplayer->current_conn ...
Definition: plrhand.cpp:1469
void send_nation_availability(struct conn_list *dest, bool nationset_change)
Tell clients which nations can be picked given current server settings.
Definition: plrhand.cpp:2574
void server_player_set_name(struct player *pplayer, const char *name)
Try to set the player name to 'name'.
Definition: plrhand.cpp:2159
void send_player_all_c(struct player *src, struct conn_list *dest)
Send all information about a player (player_info and all player_diplstates) to the given connections.
Definition: plrhand.cpp:1031
bool client_can_pick_nation(const struct nation_type *nation)
Return whether a nation is "pickable" – whether players can select it at game start.
Definition: plrhand.cpp:2546
void player_update_last_war_action(struct player *pplayer)
Update last war action timestamp (affects player mood).
Definition: plrhand.cpp:730
struct player * civil_war(struct player *pplayer)
Capturing a nation's primary capital is a devastating blow.
Definition: plrhand.cpp:2942
void playercolor_init()
Initialise the player colors.
Definition: plrhand.cpp:3269
void player_set_under_human_control(struct player *pplayer)
Toggle player under human control.
Definition: plrhand.cpp:3391
void count_playable_nations()
Update the server's cached number of playable nations.
Definition: plrhand.cpp:2529
bool player_status_check(struct player *plr, enum player_status status)
Check player status flag.
Definition: plrhand.cpp:3153
void playercolor_free()
Free the memory allocated for the player color.
Definition: plrhand.cpp:3278
void give_midgame_initial_units(struct player *pplayer, struct tile *ptile)
Gives units that every player should have.
Definition: plrhand.cpp:1752
struct player * server_create_player(int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
Creates a new, uninitialized, used player slot.
Definition: plrhand.cpp:1776
bool civil_war_triggered(struct player *pplayer)
civil_war_triggered: The capture of a primary capital is not a sure fire way to throw and empire into...
Definition: plrhand.cpp:2890
void server_player_set_color(struct player *pplayer, const struct rgbcolor *prgbcolor)
Set the player's color.
Definition: plrhand.cpp:1706
void player_set_to_ai_mode(struct player *pplayer, enum ai_level skill_level)
Toggle player to AI mode.
Definition: plrhand.cpp:3369
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)
Try to set the player name to 'name'.
Definition: plrhand.cpp:2059
bool player_delegation_active(const struct player *pplayer)
Returns TRUE if a delegation is active.
Definition: plrhand.cpp:3199
struct player * player_by_user_delegated(const char *name)
For a given user, if there is some player that the user originally controlled but is currently delega...
Definition: plrhand.cpp:3252
void assign_player_colors()
Permanently assign colors to any players that don't already have them.
Definition: plrhand.cpp:1608
void maybe_make_contact(struct tile *ptile, struct player *pplayer)
Check if we make contact with anyone.
Definition: plrhand.cpp:2282
struct rgbcolor * playercolor_get(int id)
Get the player color with the index 'id'.
Definition: plrhand.cpp:3309
void check_player_max_rates(struct player *pplayer)
The following checks that government rates are acceptable for the present form of government.
Definition: plrhand.cpp:637
void kill_player(struct player *pplayer)
Murder a player in cold blood.
Definition: plrhand.cpp:103
void send_player_info_c(struct player *src, struct conn_list *dest)
Send information about player slot 'src', or all valid (i.e.
Definition: plrhand.cpp:1048
void set_shuffled_players(int *shuffled_players)
Initialize the shuffled players list (as from a loaded savegame).
Definition: plrhand.cpp:2327
void player_status_reset(struct player *plr)
Reset player status to 'normal'.
Definition: plrhand.cpp:3161
void send_delegation_info(const struct connection *pconn)
Send information about delegations to reconnecting users.
Definition: plrhand.cpp:3207
void update_players_after_alliance_breakup(struct player *pplayer, struct player *pplayer2, const struct unit_list *pplayer_seen_units, const struct unit_list *pplayer2_seen_units)
After the alliance is breaken, we need to do two things:
Definition: plrhand.cpp:665
void handle_diplomacy_cancel_pact_explicit(struct player *pplayer, int other_player_id, enum clause_type clause, bool protect_alliances)
A variant of handle_diplomacy_cancel_pact that allows the caller to explicitely control if war declar...
Definition: plrhand.cpp:761
bool civil_war_possible(struct player *pplayer, bool conquering_city, bool honour_server_option)
Check if civil war is possible for a player.
Definition: plrhand.cpp:2843
void player_delegation_set(struct player *pplayer, const char *username)
Define a delegation.
Definition: plrhand.cpp:3183
void fit_nationset_to_players()
Try to select a nation set that fits the current players' nations, or failing that,...
Definition: plrhand.cpp:2588
struct nation_type * pick_a_nation(const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
This function returns a random-ish nation that is suitable for 'barb_type' and is usable (not already...
Definition: plrhand.cpp:2377
void server_remove_player(struct player *pplayer)
This function does not close any connections attached to this player.
Definition: plrhand.cpp:1825
void player_info_freeze()
Do not compute and send PACKET_PLAYER_INFO or PACKET_NATION_AVAILABILITY until a call to player_info_...
Definition: plrhand.cpp:1005
void government_change(struct player *pplayer, struct government *gov, bool revolution_finished)
Finish the revolution and set the player's government.
Definition: plrhand.cpp:322
void server_player_init(struct player *pplayer, bool initmap, bool needs_team)
Initialize ANY newly-created player on the server.
Definition: plrhand.cpp:1494
int normal_player_count()
Return the number of non-barbarian players.
Definition: plrhand.cpp:3140
void make_contact(struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
Update contact info.
Definition: plrhand.cpp:2197
void player_status_add(struct player *plr, enum player_status status)
Add a status flag to a player.
Definition: plrhand.cpp:3145
void playercolor_add(struct rgbcolor *prgbcolor)
Add a color to the list of all available player colors.
Definition: plrhand.cpp:3299
void update_capital(struct player *pplayer)
Recalculate what city is the named capital.
Definition: plrhand.cpp:590
struct player_economic player_limit_to_max_rates(struct player *pplayer)
The following limits a player's rates to those that are acceptable for the present form of government...
Definition: plrhand.cpp:1942
void player_info_thaw()
If the frozen level is back to 0, send all players' infos, and nation availability,...
Definition: plrhand.cpp:1011
bool player_color_changeable(const struct player *pplayer, const char **reason)
Return whether a player's color can currently be set with the '/playercolor' command.
Definition: plrhand.cpp:1590
void shuffle_players()
Shuffle or reshuffle the player order, storing in static variables above.
Definition: plrhand.cpp:2302
int playercolor_count()
Number of player colors defined.
Definition: plrhand.cpp:3319
struct player * shuffled_player(int i)
Returns the i'th shuffled player, or nullptr.
Definition: plrhand.cpp:2345
const struct rgbcolor * player_preferred_color(struct player *pplayer)
If a player's color will be predictable when colors are assigned (or assignment has already happened)...
Definition: plrhand.cpp:1547
const char * player_delegation_get(const struct player *pplayer)
Returns the username that control of the player is delegated to, if any.
Definition: plrhand.cpp:3170
void send_player_diplstate_c(struct player *src, struct conn_list *dest)
Identical to send_player_info_c(), but sends the diplstate of the player.
Definition: plrhand.cpp:1106
bool nation_is_in_current_set(const struct nation_type *pnation)
Is the nation in the currently selected nationset? If not, it's not allowed to appear in the game.
Definition: plrhand.cpp:2520
void enter_war(struct player *pplayer, struct player *pplayer2)
Two players enter war.
Definition: plrhand.cpp:711
int revolution_length(struct government *gov, struct player *plr)
Get length of a revolution.
Definition: plrhand.cpp:390
const char * player_color_ftstr(struct player *pplayer)
Return the player color as featured text string.
Definition: plrhand.cpp:1726
void reset_all_start_commands(bool plrchange)
Called when something is changed; this resets everyone's readiness.
Definition: plrhand.cpp:2658
void update_revolution(struct player *pplayer)
See if the player has finished their revolution.
Definition: plrhand.cpp:527
enum barbarian_type barb_type
Definition: nation.h:89
Definition: player.h:231
bv_pstatus status
Definition: player.h:306
char username[MAX_LEN_NAME]
Definition: player.h:234
Definition: tile.h:42