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

Freeciv-3.3

Loading...
Searching...
No Matches
Functions | Variables
plrhand.c File Reference
`#include <stdarg.h>`
`#include "bitvector.h"`
`#include "fcintl.h"`
`#include "log.h"`
`#include "mem.h"`
`#include "rand.h"`
`#include "shared.h"`
`#include "support.h"`
`#include "citizens.h"`
`#include "culture.h"`
`#include "diptreaty.h"`
`#include "government.h"`
`#include "map.h"`
`#include "movement.h"`
`#include "multipliers.h"`
`#include "nation.h"`
`#include "packets.h"`
`#include "player.h"`
`#include "research.h"`
`#include "rgbcolor.h"`
`#include "specialist.h"`
`#include "tech.h"`
`#include "unitlist.h"`
`#include "luascript_types.h"`
`#include "aiiface.h"`
`#include "barbarian.h"`
`#include "citytools.h"`
`#include "cityturn.h"`
`#include "connecthand.h"`
`#include "diplhand.h"`
`#include "gamehand.h"`
`#include "maphand.h"`
`#include "mood.h"`
`#include "notify.h"`
`#include "plrhand.h"`
`#include "sernet.h"`
`#include "srv_main.h"`
`#include "stdinhand.h"`
`#include "spaceship.h"`
`#include "spacerace.h"`
`#include "techtools.h"`
`#include "unittools.h"`
`#include "voting.h"`
`#include "advdata.h"`
`#include "script_server.h"`
`#include "aitraits.h"`
`#include "difficulty.h"`
`#include "handicaps.h"`

Go to the source code of this file.

## Functions

static void | package_player_common (struct player *plr, struct packet_player_info *packet, struct packet_web_player_info_addition *web_packet)
static void | package_player_diplstate (struct player *plr1, struct player *plr2, struct packet_player_diplstate *packet_ds, struct player *receiver, enum plr_info_level min_info_level)
static void | package_player_info (struct player *plr, struct packet_player_info *packet, struct packet_web_player_info_addition *web_packet, struct player *receiver, enum plr_info_level min_info_level)
static enum plr_info_level | player_info_level (struct player *plr, struct player *receiver)
static void | send_player_remove_info_c (const struct player_slot *pslot, struct conn_list *dest)
static void | send_player_info_c_real (struct player *src, struct conn_list *dest)
static void | send_player_diplstate_c_real (struct player *src, struct conn_list *dest)
static void | send_nation_availability_real (struct conn_list *dest, bool nationset_change)
void | kill_player (struct player *pplayer)
static int | get_player_maxrate (struct player *pplayer)
void | handle_player_rates (struct player *pplayer, int tax, int luxury, int science)
void | government_change (struct player *pplayer, struct government *gov, bool revolution_finished)
void | player_loot_player (struct player *pvictor, struct player *pvictim)
static int | revolentype_length (enum revolen_type rltype, struct government *gov)
int | revolution_length (struct government *gov, struct player *plr)
void | handle_player_change_government (struct player *pplayer, Government_type_id government)
void | update_revolution (struct player *pplayer)
void | update_capital (struct player *pplayer)
void | check_player_max_rates (struct player *pplayer)
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)
static void | maybe_claim_base (struct tile *ptile, struct player *new_owner, struct player *old_owner)
void | enter_war (struct player *pplayer, struct player *pplayer2)
void | player_update_last_war_action (struct player *pplayer)
void | handle_diplomacy_cancel_pact (struct player *pplayer, int other_player_id, enum clause_type clause)
void | player_info_freeze (void)
void | player_info_thaw (void)
void | send_player_all_c (struct player *src, struct conn_list *dest)
void | send_player_info_c (struct player *src, struct conn_list *dest)
void | send_player_diplstate_c (struct player *src, struct conn_list *dest)
struct conn_list * | player_reply_dest (struct player *pplayer)
static void | call_first_contact (struct player *pplayer, struct player *aplayer)
void | server_player_init (struct player *pplayer, bool initmap, bool needs_team)
const struct rgbcolor * | player_preferred_color (struct player *pplayer)
bool | player_color_changeable (const struct player *pplayer, const char **reason)
void | assign_player_colors (void)
void | server_player_set_color (struct player *pplayer, const struct rgbcolor *prgbcolor)
const char * | player_color_ftstr (struct player *pplayer)
void | give_midgame_initial_units (struct player *pplayer, struct tile *ptile)
struct player * | server_create_player (int player_id, const char *ai_tname, struct rgbcolor *prgbcolor, bool allow_ai_type_fallbacking)
void | server_remove_player (struct player *pplayer)
void | player_limit_to_max_rates (struct player *pplayer)
static bool | server_player_name_is_allowed (const struct connection *caller, const struct player *pplayer, const struct nation_type *pnation, const char *name, char *error_buf, size_t error_buf_len)
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)
void | server_player_set_name (struct player *pplayer, const char *name)
static enum diplstate_type | get_default_diplstate (const struct player *pplayer1, const struct player *pplayer2)
void | make_contact (struct player *pplayer1, struct player *pplayer2, struct tile *ptile)
void | maybe_make_contact (struct tile *ptile, struct player *pplayer)
void | shuffle_players (void)
void | set_shuffled_players (int *shuffled_players)
struct player * | shuffled_player (int i)
struct nation_type * | pick_a_nation (const struct nation_list *choices, bool ignore_conflicts, bool needs_startpos, enum barbarian_type barb_type)
static struct nation_set * | current_nationset (void)
bool | nation_is_in_current_set (const struct nation_type *pnation)
void | count_playable_nations (void)
bool | client_can_pick_nation (const struct nation_type *pnation)
void | send_nation_availability (struct conn_list *dest, bool nationset_change)
void | fit_nationset_to_players (void)
void | reset_all_start_commands (bool plrchange)
static struct player * | split_player (struct player *pplayer)
bool | civil_war_possible (struct player *pplayer, bool conquering_city, bool honour_server_option)
bool | civil_war_triggered (struct player *pplayer)
struct player * | civil_war (struct player *pplayer)
void | handle_player_attribute_chunk (struct player *pplayer, const struct packet_player_attribute_chunk *chunk)
void | handle_player_attribute_block (struct player *pplayer)
void | handle_player_phase_done (struct player *pplayer, int turn)
int | barbarian_count (void)
int | normal_player_count (void)
void | player_status_add (struct player *plr, enum player_status pstatus)
bool | player_status_check (struct player *plr, enum player_status pstatus)
void | player_status_reset (struct player *plr)
const char * | player_delegation_get (const struct player *pplayer)
void | player_delegation_set (struct player *pplayer, const char *username)
bool | player_delegation_active (const struct player *pplayer)
void | send_delegation_info (const struct connection *pconn)
struct player * | player_by_user_delegated (const char *name)
void | playercolor_init (void)
void | playercolor_free (void)
void | playercolor_add (struct rgbcolor *prgbcolor)
struct rgbcolor * | playercolor_get (int id)
int | playercolor_count (void)
void | handle_player_multiplier (struct player *pplayer, int count, const int *multipliers)
void | player_set_to_ai_mode (struct player *pplayer, enum ai_level skill_level)
void | player_set_under_human_control (struct player *pplayer)
void | update_national_activities (struct player *pplayer, int old_gold)

## Variables

static int | shuffled_order [MAX_NUM_PLAYER_SLOTS]
static int | player_info_frozen_level = 0

## Function Documentation

## ◆ assign_player_colors()

void assign_player_colors | ( | void |  | ) |

Permanently assign colors to any players that don't already have them. First assign preferred colors, then assign the rest randomly, trying to avoid clashes.

Definition at line 1734 of file plrhand.c.

Referenced by create_animals(), create_barbarian_player(), create_command_newcomer(), handle_edit_player_create(), sg_load_players(), sg_load_players(), split_player(), and srv_ready().

## ◆ barbarian_count()

int barbarian_count | ( | void |  | ) |

Return the number of barbarian players.

Definition at line 3203 of file plrhand.c.

## ◆ call_first_contact()

static void call_first_contact | ( | struct player * | pplayer,
|  | struct player * | aplayer
| ) |  |

static

Call first_contact function if such is defined for player

Definition at line 1603 of file plrhand.c.

Referenced by make_contact().

## ◆ check_player_max_rates()

void check_player_max_rates | ( | struct player * | pplayer | ) |

The following checks that government rates are acceptable for the present form of government. Has to be called when switching governments or when toggling from AI to human.

Definition at line 776 of file plrhand.c.

Referenced by adv_best_government(), dai_gov_value(), government_change(), handle_player_change_government(), and player_set_under_human_control().

## ◆ civil_war()

struct player * civil_war | ( | struct player * | pplayer | ) |

Capturing a nation's primary capital is a devastating blow. This function creates a new AI player, and randomly splits the original players city list into two. Of course this results in a real mix up of territory - but since when have civil wars ever been tidy, or civil.

Embassies: All embassies with other players are lost. Other players retain their embassies with pplayer. Units: Units inside cities are assigned to the new owner of the city. Units outside are transferred along with the ownership of their supporting city. If the units are in a unit stack with non rebel units, then whichever units are nearest an allied city are teleported to that city. If the stack is a transport at sea, then all rebel units on the transport are teleported to their nearest allied city.

Cities: Are split randomly into 2. This results in a real mix up of teritory - but since when have civil wars ever been tidy, or for any matter civil?

One caveat, since the spliting of cities is random, you can conceive that this could result in either the original player or the rebel getting 0 cities. To prevent this, the hack below ensures that each side gets roughly half, which ones is still determined randomly.

- Kris Bubendorfer

Definition at line 3010 of file plrhand.c.

Referenced by api_edit_civil_war(), kill_player(), unit_conquer_city(), and unit_do_destroy_city().

## ◆ civil_war_possible()

bool civil_war_possible | ( | struct player * | pplayer,
|  | bool | conquering_city,
|  | bool | honour_server_option
| ) |  |

Check if civil war is possible for a player. If conquering_city is TRUE, one of the cities currently in the empire will shortly not be and shouldn't be considered. honour_server_option controls whether we honour the 'civilwarsize' server option. (If we don't, we still enforce a minimum empire size, to avoid the risk of creating a new player with no cities.)

Definition at line 2913 of file plrhand.c.

Referenced by api_edit_civil_war(), unit_conquer_city(), and unit_do_destroy_city().

## ◆ civil_war_triggered()

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 civil war. Some governments are more susceptible than others, here are the base probabilities: Anarchy 90% Despotism 80% Monarchy 70% Fundamentalism 60% (Only in civ2 ruleset) Communism 50% Republic 40% Democracy 30% In addition each city in disorder adds and each celebrating city subtracts from the probability of a civil war. If you have at least 1 turns notice of the impending loss of your capital, you can hike luxuries up to the hightest value, and by this reduce the chance of a civil war. In fact by hiking the luxuries to 100% under Democracy, it is easy to get massively negative numbers - guaranteeing imunity from civil war. Likewise, 3 cities in disorder under despotism guarantees a civil war. This routine calculates these probabilities and returns true if a civil war is triggered.

- Kris Bubendorfer

Definition at line 2960 of file plrhand.c.

Referenced by api_edit_civil_war(), unit_conquer_city(), and unit_do_destroy_city().

## ◆ client_can_pick_nation()

bool client_can_pick_nation | ( | const struct nation_type * | pnation | ) |

Return whether a nation is "pickable" – whether players can select it at game start. (is_nation_pickable() is the equivalent function on the client.)

Definition at line 2617 of file plrhand.c.

Referenced by generate_players(), handle_nation_select_req(), playernation_command(), and send_nation_availability_real().

## ◆ count_playable_nations()

void count_playable_nations | ( | void |  | ) |

Update the server's cached number of playable nations. Call when the nationset changes.

Definition at line 2602 of file plrhand.c.

Referenced by fit_nationset_to_players(), load_ruleset_nations(), and nationset_action().

## ◆ current_nationset()

static struct nation_set * current_nationset | ( | void |  | ) |

static

Return the nationset currently in effect.

Definition at line 2584 of file plrhand.c.

Referenced by fit_nationset_to_players(), and nation_is_in_current_set().

## ◆ enter_war()

void enter_war | ( | struct player * | pplayer,
|  | struct player * | pplayer2
| ) |  |

Two players enter war.

Definition at line 848 of file plrhand.c.

Referenced by handle_diplomacy_cancel_pact(), and update_diplomatics().

## ◆ fit_nationset_to_players()

void fit_nationset_to_players | ( | void |  | ) |

Try to select a nation set that fits the current players' nations, or failing that, unset the nations of some of the players.

Does not update clients, as is assumed to be called during game setup, and to be followed by sending full game info to clients.

Definition at line 2662 of file plrhand.c.

Referenced by sg_load_players(), and sg_load_players().

## ◆ get_default_diplstate()

static enum diplstate_type get_default_diplstate | ( | const struct player * | pplayer1,
|  | const struct player * | pplayer2
| ) |  |

static

Returns the default diplomatic state between 2 players.

Mainly, this returns DS_WAR, but it can also return DS_PEACE if both players are allied with the same third player.

Definition at line 2285 of file plrhand.c.

Referenced by make_contact().

## ◆ get_player_maxrate()

static int get_player_maxrate | ( | struct player * | pplayer | ) |

static

Return player maxrate in legal range.

Definition at line 269 of file plrhand.c.

Referenced by government_change(), handle_player_rates(), and player_limit_to_max_rates().

## ◆ give_midgame_initial_units()

void give_midgame_initial_units | ( | struct player * | pplayer,
|  | struct tile * | ptile
| ) |  |

Gives units that every player should have. Usually called for players created midgame.

Definition at line 1870 of file plrhand.c.

Referenced by civil_war().

## ◆ government_change()

void government_change | ( | struct player * | pplayer,
|  | struct government * | gov,
|  | bool | revolution_finished
| ) |  |

Finish the revolution and set the player's government. Call this as soon as the player has set a target_government and the revolution_finishes turn has arrived.

Definition at line 336 of file plrhand.c.

Referenced by end_phase(), handle_edit_player(), and update_revolution().

## ◆ handle_diplomacy_cancel_pact()

void handle_diplomacy_cancel_pact | ( | struct player * | pplayer,
|  | int | other_player_id,
|  | enum clause_type | clause
| ) |  |

Handles a player cancelling a "pact" with another player.

packet.id is id of player we want to cancel a pact with packet.val1 is a special value indicating what kind of treaty we want to break. If this is CLAUSE_VISION we break shared vision. If it is a pact treaty type, we break one pact level. If it is CLAUSE_LAST we break all treaties and go straight to war.

Definition at line 880 of file plrhand.c.

Referenced by dai_declare_war(), dai_diplomacy_actions(), handle_diplomacy_cancel_pact(), server_handle_packet(), and update_diplomatics().

## ◆ handle_player_attribute_block()

void handle_player_attribute_block | ( | struct player * | pplayer | ) |

The client request an attribute block.

Definition at line 3175 of file plrhand.c.

Referenced by server_handle_packet().

## ◆ handle_player_attribute_chunk()

void handle_player_attribute_chunk | ( | struct player * | pplayer,
|  | const struct packet_player_attribute_chunk * | chunk
| ) |  |

The client has send as a chunk of the attribute block.

Definition at line 3165 of file plrhand.c.

Referenced by client_handle_packet(), and server_handle_packet().

## ◆ handle_player_change_government()

void handle_player_change_government | ( | struct player * | pplayer,
|  | Government_type_id | government
| ) |  |

Called by the client or AI to change government.

Definition at line 565 of file plrhand.c.

Referenced by dai_go_to_war(), dai_government_change(), research_tech_lost(), server_handle_packet(), and update_city_activity().

## ◆ handle_player_multiplier()

void handle_player_multiplier | ( | struct player * | pplayer,
|  | int | count,
|  | const int * | multipliers
| ) |  |

Sets player's multipliers.

Definition at line 3399 of file plrhand.c.

Referenced by server_handle_packet().

## ◆ handle_player_phase_done()

void handle_player_phase_done | ( | struct player * | pplayer,
|  | int | turn
| ) |  |

(Hmm, how should "turn done" work for multi-connected non-observer players?)

Definition at line 3183 of file plrhand.c.

Referenced by server_handle_packet().

## ◆ handle_player_rates()

void handle_player_rates | ( | struct player * | pplayer,
|  | int | tax,
|  | int | luxury,
|  | int | science
| ) |  |

Handle a client or AI request to change the tax/luxury/science rates. This function does full sanity checking.

Definition at line 285 of file plrhand.c.

Referenced by server_handle_packet().

## ◆ kill_player()

void kill_player | ( | struct player * | pplayer | ) |

Murder a player in cold blood.

Called from srv_main kill_dying_players() and edit packet handler handle_edit_player_remove().

Definition at line 125 of file plrhand.c.

Referenced by handle_edit_player_remove(), and kill_dying_players().

## ◆ make_contact()

void make_contact | ( | struct player * | pplayer1,
|  | struct player * | pplayer2,
|  | struct tile * | ptile
| ) |  |

Update contact info.

Definition at line 2303 of file plrhand.c.

Referenced by do_have_contacts_effect(), and maybe_make_contact().

## ◆ maybe_claim_base()

static void maybe_claim_base | ( | struct tile * | ptile,
|  | struct player * | new_owner,
|  | struct player * | old_owner
| ) |  |

static

If there's any units of new_owner on tile, they claim bases.

Definition at line 823 of file plrhand.c.

Referenced by enter_war().

## ◆ maybe_make_contact()

void maybe_make_contact | ( | struct tile * | ptile,
|  | struct player * | pplayer
| ) |  |

Check if we make contact with anyone.

Definition at line 2362 of file plrhand.c.

Referenced by create_city(), transfer_city(), and unit_make_contact().

## ◆ nation_is_in_current_set()

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 at line 2593 of file plrhand.c.

Referenced by client_can_pick_nation(), create_command_newcomer(), dai_can_requirement_be_met_in_city(), fit_nationset_to_players(), handle_edit_player(), handle_nation_select_req(), nationset_action(), and pick_a_nation().

## ◆ normal_player_count()

int normal_player_count | ( | void |  | ) |

Return the number of non-barbarian players.

Definition at line 3211 of file plrhand.c.

Referenced by adjust_improvement_wants_by_effects(), civil_war(), connection_attach_real(), create_command_newcomer(), create_command_pregame(), dai_effect_value(), dai_gov_value(), dai_tech_effect_values(), is_allowed_to_take(), nationset_action(), send_lanserver_response(), sg_load_sanitycheck(), sg_load_sanitycheck(), srv_ready(), start_command(), take_command(), unit_conquer_city(), and unit_do_destroy_city().

## ◆ package_player_common()

static void package_player_common | ( | struct player * | plr,
|  | struct packet_player_info * | packet,
|  | struct packet_web_player_info_addition * | web_packet
| ) |  |

static

Package player information that is always sent.

Definition at line 1261 of file plrhand.c.

Referenced by send_player_info_c_real().

## ◆ package_player_diplstate()

static void package_player_diplstate | ( | struct player * | plr1,
|  | struct player * | plr2,
|  | struct packet_player_diplstate * | packet_ds,
|  | struct player * | receiver,
|  | enum plr_info_level | min_info_level
| ) |  |

static

Package player diplstate depending on info_level. We send everything to plr's connections, we send almost everything to players with embassy to plr, we send a little to players we are in contact with and almost nothing to everyone else.

Receiver may be nullptr in which cases dummy values are sent for some fields.

Definition at line 1527 of file plrhand.c.

Referenced by send_player_diplstate_c_real().

## ◆ package_player_info()

static void package_player_info | ( | struct player * | plr,
|  | struct packet_player_info * | packet,
|  | struct packet_web_player_info_addition * | web_packet,
|  | struct player * | receiver,
|  | enum plr_info_level | min_info_level
| ) |  |

static

Package player info depending on info_level. We send everything to plr's connections, we send almost everything to players with embassy to plr, we send a little to players we are in contact with and almost nothing to everyone else.

Receiver may be nullptr in which cases dummy values are sent for some fields.

Definition at line 1324 of file plrhand.c.

Referenced by send_player_info_c_real().

## ◆ pick_a_nation()

struct nation_type * pick_a_nation | ( | const struct nation_list * | choices,
|  | bool | ignore_conflicts,
|  | bool | needs_startpos,
|  | enum barbarian_type | barb_type
| ) |  |

This function returns a random-ish nation that is suitable for 'barb_type' and is usable (not already in use by an existing player, and if needs_startpos is set, would not be prohibited from starting on the map by the current scenario – NB this doesn't check that any start position is actually free).

Unless 'ignore_conflicts' is set, this function tries hard to avoid a nation marked as "conflicting with" one already in the game. A conflicting nation will be returned only if the alternative is to return NO_NATION_SELECTED. Such a return indicates that there are no remaining nations which match the above criteria.

If 'choices' is non-nullptr, nations from the supplied list are preferred; but if there are no (non-conflicting) nations on the list that match the criteria, one will be chosen from outside the list (as if the list had not been supplied).

All other things being equal, prefers to pick a nation which returns a high score from nations_match() relative to any nations already in the game.

Definition at line 2456 of file plrhand.c.

Referenced by create_animals(), create_barbarian_player(), create_command_newcomer(), generate_players(), handle_edit_player_create(), sg_load_players(), sg_load_players(), and split_player().

## ◆ player_by_user_delegated()

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 delegated to another user, return that player. See also player_by_user().

Definition at line 3325 of file plrhand.c.

Referenced by establish_new_connection().

## ◆ player_color_changeable()

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. If not, give a reason why not, if 'reason' is not nullptr (need not be freed).

Definition at line 1716 of file plrhand.c.

Referenced by package_player_info(), and playercolor_command().

## ◆ player_color_ftstr()

const char * player_color_ftstr | ( | struct player * | pplayer | ) |

Return the player color as featured text string. (In pregame, this uses the color the player will take, if known, even if not assigned yet.)

Definition at line 1843 of file plrhand.c.

Referenced by playercolor_command(), show_colors(), and show_players().

## ◆ player_delegation_active()

bool player_delegation_active | ( | const struct player * | pplayer | ) |

Returns TRUE if a delegation is active. This means that either the player is controlled by a delegate, or the player has been temporarily 'put aside' by a delegate.

Definition at line 3273 of file plrhand.c.

Referenced by delegate_command(), show_delegations(), and take_command().

## ◆ player_delegation_get()

const char * player_delegation_get | ( | const struct player * | pplayer | ) |

Returns the username that control of the player is delegated to, if any.

Definition at line 3244 of file plrhand.c.

Referenced by delegate_command(), establish_new_connection(), player_by_user_delegated(), send_delegation_info(), sg_save_player_main(), and show_delegations().

## ◆ player_delegation_set()

void player_delegation_set | ( | struct player * | pplayer,
|  | const char * | username
| ) |  |

Define a delegation. nullptr for no delegate.

Definition at line 3257 of file plrhand.c.

Referenced by delegate_command(), sg_load_player_main(), and sg_load_player_main().

## ◆ player_info_freeze()

void player_info_freeze | ( | void |  | ) |

Do not compute and send PACKET_PLAYER_INFO or PACKET_NATION_AVAILABILITY until a call to player_info_thaw(). This is used during savegame load or ruleset (re)load cycles, to avoid sending infos to the client that depend on ruleset data it does not yet have.

Definition at line 1099 of file plrhand.c.

Referenced by load_command(), and set_rulesetdir().

## ◆ player_info_level()

static enum plr_info_level player_info_level | ( | struct player * | plr,
|  | struct player * | receiver
| ) |  |

static

Return level of information player should receive about another.

Definition at line 1570 of file plrhand.c.

Referenced by package_player_diplstate(), and package_player_info().

## ◆ player_info_thaw()

void player_info_thaw | ( | void |  | ) |

If the frozen level is back to 0, send all players' infos, and nation availability, to all connections.

Definition at line 1108 of file plrhand.c.

Referenced by load_command(), and set_rulesetdir().

## ◆ player_limit_to_max_rates()

void player_limit_to_max_rates | ( | struct player * | pplayer | ) |

The following limits a player's rates to those that are presently acceptable. If a rate exceeds current maxrate, it adjusts rates automatically adding the extra to the 2nd highest rate, preferring science to taxes and taxes to luxuries. (It assumes that for maxrate * 3 >= 100 in any situation)

Returns actual max rate used. This function should be called after team information are defined.

Definition at line 2057 of file plrhand.c.

Referenced by check_player_max_rates(), handle_edit_player_create(), server_player_init(), sg_load_sanitycheck(), sg_load_sanitycheck(), split_player(), and srv_ready().

## ◆ player_loot_player()

void player_loot_player | ( | struct player * | pvictor,
|  | struct player * | pvictim
| ) |  |

pvictor gets parts of treasury, map and cities of pvictim. Normally happens when pvictim's gameloss unit is killed. FIXME: Any control over types of the loot? TODO: Proper event types (likely needs a new one). For now ones related to Huts (similar loot) used.

Definition at line 410 of file plrhand.c.

Referenced by api_methods_player_lose(), and wipe_unit_full().

## ◆ player_preferred_color()

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), return that color. Otherwise (if the player's color is yet to be assigned randomly), return nullptr.

Definition at line 1673 of file plrhand.c.

Referenced by assign_player_colors(), package_player_info(), and player_color_ftstr().

## ◆ player_reply_dest()

struct conn_list * player_reply_dest | ( | struct player * | pplayer | ) |

Convenience function to return "reply" destination connection list for player: pplayer->current_conn if set, else pplayer->connections.

Definition at line 1593 of file plrhand.c.

Referenced by handle_unit_sscs_set(), unit_move(), and unit_move_handling().

## ◆ player_set_to_ai_mode()

void player_set_to_ai_mode | ( | struct player * | pplayer,
|  | enum ai_level | skill_level
| ) |  |

Toggle player to AI mode.

Definition at line 3438 of file plrhand.c.

Referenced by away_command(), and toggle_ai_player_direct().

## ◆ player_set_under_human_control()

void player_set_under_human_control | ( | struct player * | pplayer | ) |

Toggle player under human control.

Definition at line 3460 of file plrhand.c.

Referenced by away_command(), and toggle_ai_player_direct().

## ◆ player_status_add()

void player_status_add | ( | struct player * | plr,
|  | enum player_status | pstatus
| ) |  |

Add a status flag to a player.

Definition at line 3219 of file plrhand.c.

Referenced by api_edit_player_victory(), api_methods_player_lose(), kill_dying_players(), player_status_reset(), rank_users(), server_remove_unit_full(), and surrender_command().

## ◆ player_status_check()

bool player_status_check | ( | struct player * | plr,
|  | enum player_status | pstatus
| ) |  |

Check player status flag.

Definition at line 3227 of file plrhand.c.

Referenced by check_for_game_over(), kill_dying_players(), rank_users(), and surrender_command().

## ◆ player_status_reset()

void player_status_reset | ( | struct player * | plr | ) |

Reset player status to 'normal'.

Definition at line 3235 of file plrhand.c.

Referenced by create_barbarian_player(), kill_player(), and server_player_init().

## ◆ player_update_last_war_action()

void player_update_last_war_action | ( | struct player * | pplayer | ) |

Update last war action timestamp (affects player mood).

Definition at line 865 of file plrhand.c.

Referenced by action_give_casus_belli(), handle_diplomacy_cancel_pact(), unit_bombs_unit(), and unit_versus_unit().

## ◆ playercolor_add()

void playercolor_add | ( | struct rgbcolor * | prgbcolor | ) |

Add a color to the list of all available player colors.

Definition at line 3369 of file plrhand.c.

Referenced by load_ruleset_game().

## ◆ playercolor_count()

int playercolor_count | ( | void |  | ) |

Number of player colors defined.

Definition at line 3389 of file plrhand.c.

Referenced by load_ruleset_game(), mapimg_server_plrcolor_count(), and player_preferred_color().

## ◆ playercolor_free()

void playercolor_free | ( | void |  | ) |

Free the memory allocated for the player color.

Definition at line 3350 of file plrhand.c.

Referenced by load_rulesetdir(), and server_game_free().

## ◆ playercolor_get()

struct rgbcolor * playercolor_get | ( | int | id | ) |

Get the player color with the index 'id'.

Definition at line 3379 of file plrhand.c.

Referenced by mapimg_server_plrcolor_get(), and player_preferred_color().

## ◆ playercolor_init()

void playercolor_init | ( | void |  | ) |

Initialise the player colors.

Definition at line 3340 of file plrhand.c.

Referenced by load_rulesetdir(), and server_game_init().

## ◆ reset_all_start_commands()

void reset_all_start_commands | ( | bool | plrchange | ) |

Called when something is changed; this resets everyone's readiness.

Definition at line 2727 of file plrhand.c.

Referenced by connection_detach(), create_command_pregame(), establish_new_connection(), and set_command().

## ◆ revolentype_length()

static int revolentype_length | ( | enum revolen_type | rltype,
|  | struct government * | gov
| ) |  |

static

Get length of a revolution.

Parameters

  rltype | The way to decide revolution length
  gov | Government that the revolution ends to

Returns
  Revolution length in turns

Definition at line 515 of file plrhand.c.

Referenced by revolution_length().

## ◆ revolution_length()

int revolution_length | ( | struct government * | gov,
|  | struct player * | plr
| ) |  |

Get length of a revolution.

Definition at line 549 of file plrhand.c.

Referenced by handle_edit_player(), and handle_player_change_government().

## ◆ send_delegation_info()

void send_delegation_info | ( | const struct connection * | pconn | ) |

Send information about delegations to reconnecting users.

Definition at line 3281 of file plrhand.c.

Referenced by connection_attach_real(), and establish_new_connection().

## ◆ send_nation_availability()

void send_nation_availability | ( | struct conn_list * | dest,
|  | bool | nationset_change
| ) |  |

Tell clients which nations can be picked given current server settings.

Definition at line 2645 of file plrhand.c.

Referenced by nationset_action(), and send_ruleset_nations().

## ◆ send_nation_availability_real()

static void send_nation_availability_real | ( | struct conn_list * | dest,
|  | bool | nationset_change
| ) |  |

static

Helper doing the actual work for send_nation_availability() (q.v.).

Definition at line 2629 of file plrhand.c.

Referenced by player_info_thaw(), and send_nation_availability().

## ◆ send_player_all_c()

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.

Send all players if src is nullptr; send to all connections if dest is nullptr.

This function also sends the diplstate of the player. So take care, that all players are defined in the client and in the server. To create a player without sending the diplstate, use send_player_info_c().

Definition at line 1129 of file plrhand.c.

Referenced by action_consequence_common(), begin_phase(), civil_war(), create_animals(), create_barbarian_player(), diplomat_bribe(), diplomat_get_tech(), diplomat_may_lose_gold(), end_turn(), establish_embassy(), found_new_tech(), handle_diplomacy_accept_treaty_req(), handle_diplomacy_cancel_pact(), handle_edit_player(), handle_edit_player_create(), handle_player_phase_done(), make_contact(), send_all_info(), split_player(), and update_players_after_alliance_breakup().

## ◆ send_player_diplstate_c()

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.

This function solves one problem of using an extra packet for the diplstate. It can only be send if the player exists at the destination. Thus, this function should be called after the player(s) exists on both sides of the connection.

Definition at line 1212 of file plrhand.c.

Referenced by create_command_newcomer(), load_command(), and send_player_all_c().

## ◆ send_player_diplstate_c_real()

static void send_player_diplstate_c_real | ( | struct player * | plr1,
|  | struct conn_list * | dest
| ) |  |

static

Really send information. If 'dest' is nullptr, then it is set to game.est_connections.

Definition at line 1228 of file plrhand.c.

Referenced by send_player_diplstate_c().

## ◆ send_player_info_c()

void send_player_info_c | ( | struct player * | src,
|  | struct conn_list * | dest
| ) |  |

Send information about player slot 'src', or all valid (i.e. used and initialized) players if 'src' is nullptr, to specified clients 'dest'. If 'dest' is nullptr, it is treated as game.est_connections.

Note: package_player_info contains incomplete info if it has nullptr as a dest arg and and info is < INFO_EMBASSY. NB: If 'src' is nullptr (meaning send information about all players) this function will only send info for used players, i.e. player slots with a player defined.

Definition at line 1146 of file plrhand.c.

Referenced by aifill(), announce_player(), api_edit_change_gold(), api_edit_change_infrapoints(), api_edit_create_building(), api_edit_remove_building(), autotoggle_action(), away_command(), city_build_free_buildings(), collect_ransom(), connection_attach_real(), connection_delegate_restore(), connection_detach(), create_city_for_player(), create_command_newcomer(), create_command_pregame(), dai_manage_taxes(), detach_command(), diplomat_incite(), do_unit_establish_trade(), do_unit_upgrade(), establish_new_connection(), give_shared_vision(), government_change(), handle_edit_city(), handle_edit_unit_create(), handle_nation_select_req(), handle_player_change_government(), handle_player_multiplier(), handle_player_place_infra(), handle_player_rates(), handle_player_ready(), handle_unit_type_upgrade(), kill_player(), nationset_action(), player_info_thaw(), player_update_last_war_action(), playernation_command(), plrcol_action(), really_handle_city_buy(), really_handle_city_sell(), remove_city(), remove_obsolete_buildings_city(), remove_shared_vision(), research_tech_lost(), reset_all_start_commands(), send_player_all_c(), server_player_set_color(), set_ai_level(), set_ai_level_direct(), split_player(), spy_steal_gold(), team_command(), toggle_ai_command(), transfer_city(), unit_conquer_city(), unit_do_help_build(), unit_enter_hut(), and update_revolution().

## ◆ send_player_info_c_real()

static void send_player_info_c_real | ( | struct player * | src,
|  | struct conn_list * | dest
| ) |  |

static

Really send information. If 'dest' is nullptr, then it is set to game.est_connections.

Definition at line 1166 of file plrhand.c.

Referenced by send_player_info_c().

## ◆ send_player_remove_info_c()

static void send_player_remove_info_c | ( | const struct player_slot * | pslot,
|  | struct conn_list * | dest
| ) |  |

static

Send information about removed (unused) players.

Definition at line 1079 of file plrhand.c.

Referenced by server_remove_player().

## ◆ server_create_player()

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. You should probably call server_player_init() to initialize it, and send_player_info_c() later to tell clients about it.

May return nullptr if creation was not possible.

Definition at line 1894 of file plrhand.c.

Referenced by aifill(), connection_attach_real(), create_animals(), create_barbarian_player(), create_command_newcomer(), create_command_pregame(), handle_edit_player_create(), sg_load_players_basic(), sg_load_players_basic(), and split_player().

## ◆ server_player_init()

void server_player_init | ( | struct player * | pplayer,
|  | bool | initmap,
|  | bool | needs_team
| ) |  |

Initialize ANY newly-created player on the server.

The initmap option is used because we don't want to initialize the map before the x and y sizes have been determined. This should generally be FALSE in pregame.

The needs_team options should be set for players who should be assigned a team. They will be put on their own newly-created team.

Definition at line 1618 of file plrhand.c.

Referenced by aifill(), connection_attach_real(), create_animals(), create_barbarian_player(), create_command_newcomer(), create_command_pregame(), handle_edit_player_create(), server_create_player(), sg_load_players_basic(), sg_load_players_basic(), and split_player().

## ◆ server_player_name_is_allowed()

static bool server_player_name_is_allowed | ( | const struct connection * | caller,
|  | const struct player * | pplayer,
|  | const struct nation_type * | pnation,
|  | const char * | name,
|  | char * | error_buf,
|  | size_t | error_buf_len
| ) |  |

static

Check if this name is allowed for the player. Fill out the error message (a translated string to be sent to the client) if not.

Definition at line 2106 of file plrhand.c.

Referenced by server_player_set_name_full().

## ◆ server_player_set_color()

void server_player_set_color | ( | struct player * | pplayer,
|  | const struct rgbcolor * | prgbcolor
| ) |  |

Set the player's color. If 'prgbcolor' is not nullptr the caller should free the pointer, as player_set_color() copies the data.

Definition at line 1823 of file plrhand.c.

Referenced by playercolor_command(), and plrcol_action().

## ◆ server_player_set_name()

void server_player_set_name | ( | struct player * | pplayer,
|  | const char * | name
| ) |  |

Try to set the player name to 'name'. Else, find a default name.

Definition at line 2268 of file plrhand.c.

Referenced by aifill(), connection_attach_real(), create_barbarian_player(), create_command_newcomer(), create_command_pregame(), player_nation_defaults(), playernation_command(), sg_load_player_main(), and sg_load_player_main().

## ◆ server_player_set_name_full()

bool server_player_set_name_full | ( | const struct connection * | caller,
|  | struct player * | pplayer,
|  | const struct nation_type * | pnation,
|  | const char * | name,
|  | char * | error_buf,
|  | size_t | error_buf_len
| ) |  |

Try to set the player name to 'name'. Else, find a default name. Returns TRUE on success.

Definition at line 2168 of file plrhand.c.

Referenced by handle_edit_player(), handle_nation_select_req(), playernation_command(), and server_player_set_name().

## ◆ server_remove_player()

void server_remove_player | ( | struct player * | pplayer | ) |

This function does not close any connections attached to this player. The function cut_connection() is used for that. Be sure to send_player_slot_info_c() afterwards to tell clients that the player slot has become unused.

Definition at line 1943 of file plrhand.c.

Referenced by aifill(), connection_detach(), create_command_newcomer(), handle_edit_player_remove(), remove_player_command(), server_game_free(), sg_load_players_basic(), sg_load_players_basic(), and start_command().

## ◆ set_shuffled_players()

void set_shuffled_players | ( | int * | shuffled_players | ) |

Initialize the shuffled players list (as from a loaded savegame).

Definition at line 2406 of file plrhand.c.

Referenced by sg_load_players_basic(), and sg_load_players_basic().

## ◆ shuffle_players()

void shuffle_players | ( | void |  | ) |

Shuffle or reshuffle the player order, storing in static variables above.

Definition at line 2381 of file plrhand.c.

Referenced by begin_turn(), sg_load_players_basic(), sg_load_players_basic(), and srv_ready().

## ◆ shuffled_player()

struct player * shuffled_player | ( | int | i | ) |

Returns the i'th shuffled player, or nullptr.

NB: You should never need to call this function directly.

Definition at line 2424 of file plrhand.c.

## ◆ split_player()

static struct player * split_player | ( | struct player * | pplayer | ) |

static

This function creates a new player and copies all of it's science research etc. Players are both thrown into anarchy and gold is split between both players.

- Kris Bubendorfer

Definition at line 2762 of file plrhand.c.

Referenced by civil_war().

## ◆ update_capital()

void update_capital | ( | struct player * | pplayer | ) |

Recalculate what city is the named capital

Definition at line 731 of file plrhand.c.

Referenced by begin_phase(), and transfer_city().

## ◆ update_national_activities()

void update_national_activities | ( | struct player * | pplayer,
|  | int | old_gold
| ) |  |

National level turn change activities.

Definition at line 3480 of file plrhand.c.

Referenced by end_phase().

## ◆ update_players_after_alliance_breakup()

void update_players_after_alliance_breakup | ( | struct player * | pplayer,
|  | struct player * | pplayer2,
|  | const struct unit_list * | pplayer_seen_units,
|  | const struct unit_list * | pplayer2_seen_units
| ) |  |

After the alliance is breaken, we need to do two things:

- Inform clients that they cannot see units inside the former's ally cities
- Remove units stacked together Note that you shouldn't use the units listed in 'pplayer_seen_units' and 'pplayer2_seen_units' after calling this function because these units might have died during the process.

Definition at line 804 of file plrhand.c.

Referenced by handle_diplomacy_accept_treaty_req(), and handle_diplomacy_cancel_pact().

## ◆ update_revolution()

void update_revolution | ( | struct player * | pplayer | ) |

See if the player has finished their revolution. This function should be called at the beginning of a player's phase.

Definition at line 672 of file plrhand.c.

Referenced by begin_phase().

## Variable Documentation

## ◆ player_info_frozen_level

int player_info_frozen_level = 0

static

Definition at line 117 of file plrhand.c.

Referenced by player_info_freeze(), player_info_thaw(), send_nation_availability(), and send_player_info_c().

## ◆ shuffled_order

int shuffled_order[MAX_NUM_PLAYER_SLOTS]

static

Definition at line 114 of file plrhand.c.

Referenced by set_shuffled_players(), shuffle_players(), and shuffled_player().