Freeciv-3.1
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
gamehand.c File Reference
#include <stdio.h>
#include "capability.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "rand.h"
#include "registry.h"
#include "shared.h"
#include "string_vector.h"
#include "support.h"
#include "ai.h"
#include "calendar.h"
#include "events.h"
#include "game.h"
#include "improvement.h"
#include "movement.h"
#include "packets.h"
#include "citytools.h"
#include "connecthand.h"
#include "maphand.h"
#include "notify.h"
#include "plrhand.h"
#include "srv_main.h"
#include "stdinhand.h"
#include "unittools.h"
#include "advdata.h"
#include "gamehand.h"
#include "speclist.h"
#include "specpq.h"

Go to the source code of this file.

Data Structures

struct  team_placement_config
 
struct  team_placement_state
 

Macros

#define CHALLENGE_ROOT   "challenge"
 
#define SPECLIST_TAG   startpos
 
#define SPECLIST_TYPE   struct startpos
 
#define startpos_list_iterate(list, plink, psp)
 
#define startpos_list_iterate_end   LIST_BOTH_ITERATE_END
 
#define SPECPQ_TAG   team_placement
 
#define SPECPQ_DATA_TYPE   struct team_placement_state *
 
#define SPECPQ_PRIORITY_TYPE   long
 
#define team_placement_closest   sq_map_distance
 

Functions

enum unit_role_id crole_to_role_id (char crole)
 
struct unit_typecrole_to_unit_type (char crole, struct player *pplayer)
 
static struct tileplace_starting_unit (struct tile *starttile, struct player *pplayer, struct unit_type *ptype, char crole)
 
static struct tilefind_dispersed_position (struct player *pplayer, struct tile *pcenter)
 
static int team_placement_continent (const struct tile *ptile1, const struct tile *ptile2)
 
static int team_placement_horizontal (const struct tile *ptile1, const struct tile *ptile2)
 
static int team_placement_vertical (const struct tile *ptile1, const struct tile *ptile2)
 
static void team_placement_state_destroy (struct team_placement_state *pstate)
 
static void do_team_placement (const struct team_placement_config *pconfig, struct team_placement_state *pbest_state, int iter_max)
 
void init_new_game (void)
 
void send_year_to_clients (void)
 
void send_game_info (struct conn_list *dest)
 
void send_scenario_info (struct conn_list *dest)
 
void send_scenario_description (struct conn_list *dest)
 
int update_timeout (void)
 
void increase_timeout_because_unit_moved (void)
 
static void gen_challenge_filename (struct connection *pc)
 
static const char * get_challenge_filename (struct connection *pc)
 
static const char * get_challenge_fullname (struct connection *pc)
 
const char * new_challenge_filename (struct connection *pc)
 
static void send_ruleset_choices (struct connection *pc)
 
void handle_single_want_hack_req (struct connection *pc, const struct packet_single_want_hack_req *packet)
 

Macro Definition Documentation

◆ CHALLENGE_ROOT

#define CHALLENGE_ROOT   "challenge"

Definition at line 55 of file gamehand.c.

◆ SPECLIST_TAG

#define SPECLIST_TAG   startpos

Definition at line 57 of file gamehand.c.

◆ SPECLIST_TYPE

#define SPECLIST_TYPE   struct startpos

Definition at line 58 of file gamehand.c.

◆ SPECPQ_DATA_TYPE

#define SPECPQ_DATA_TYPE   struct team_placement_state *

Definition at line 78 of file gamehand.c.

◆ SPECPQ_PRIORITY_TYPE

#define SPECPQ_PRIORITY_TYPE   long

Definition at line 79 of file gamehand.c.

◆ SPECPQ_TAG

#define SPECPQ_TAG   team_placement

Definition at line 77 of file gamehand.c.

◆ startpos_list_iterate

#define startpos_list_iterate (   list,
  plink,
  psp 
)
Value:
TYPED_LIST_BOTH_ITERATE(struct startpos_list_link, struct startpos, \
list, plink, psp)
static struct fc_sockaddr_list * list
Definition clinet.c:102
#define TYPED_LIST_BOTH_ITERATE(TYPE_link, TYPE_data, ARG_list, NAME_link, NAME_data)
Definition speclist.h:698
Definition map.c:41

Definition at line 60 of file gamehand.c.

◆ startpos_list_iterate_end

#define startpos_list_iterate_end   LIST_BOTH_ITERATE_END

Definition at line 63 of file gamehand.c.

◆ team_placement_closest

#define team_placement_closest   sq_map_distance

Definition at line 254 of file gamehand.c.

Function Documentation

◆ crole_to_role_id()

enum unit_role_id crole_to_role_id ( char  crole)

Get role_id for given role character

Definition at line 85 of file gamehand.c.

Referenced by crole_to_unit_type(), and startunits_callback().

◆ crole_to_unit_type()

struct unit_type * crole_to_unit_type ( char  crole,
struct player pplayer 
)

Get unit_type for given role character. If pplayer given, will check also that they don't already have an unique unit.

Definition at line 118 of file gamehand.c.

Referenced by give_midgame_initial_units(), place_starting_unit(), and srv_ready().

◆ do_team_placement()

static void do_team_placement ( const struct team_placement_config pconfig,
struct team_placement_state pbest_state,
int  iter_max 
)
static

Find the best team placement, according to the 'team_placement' setting.

Definition at line 308 of file gamehand.c.

Referenced by init_new_game().

◆ find_dispersed_position()

static struct tile * find_dispersed_position ( struct player pplayer,
struct tile pcenter 
)
static

Find a valid position not far from our starting position.

Definition at line 220 of file gamehand.c.

Referenced by init_new_game().

◆ gen_challenge_filename()

static void gen_challenge_filename ( struct connection pc)
static

Generate challenge filename for this connection, cannot fail.

Definition at line 1050 of file gamehand.c.

Referenced by new_challenge_filename().

◆ get_challenge_filename()

static const char * get_challenge_filename ( struct connection pc)
static

Get challenge filename for this connection.

Definition at line 1057 of file gamehand.c.

Referenced by get_challenge_fullname(), and new_challenge_filename().

◆ get_challenge_fullname()

static const char * get_challenge_fullname ( struct connection pc)
static

Get challenge full filename for this connection.

Definition at line 1070 of file gamehand.c.

Referenced by handle_single_want_hack_req().

◆ handle_single_want_hack_req()

void handle_single_want_hack_req ( struct connection pc,
const struct packet_single_want_hack_req packet 
)

Opens a file specified by the packet and compares the packet values with the file values. Sends an answer to the client once it's done.

Definition at line 1137 of file gamehand.c.

Referenced by server_handle_packet().

◆ increase_timeout_because_unit_moved()

void increase_timeout_because_unit_moved ( void  )

adjusts game.seconds_to_turn_done when enemy moves a unit, we see it and the remaining timeout is smaller than the timeoutaddenemymove option.

It's possible to use a similar function to do that per-player. In theory there should be a separate timeout for each player and the added time should only go onto the victim's timer.

Definition at line 1034 of file gamehand.c.

Referenced by unit_move().

◆ init_new_game()

void init_new_game ( void  )

Initialize a new game: place the players' units onto the map, etc.

Definition at line 449 of file gamehand.c.

Referenced by srv_ready().

◆ new_challenge_filename()

const char * new_challenge_filename ( struct connection pc)

Find a file that we can write too, and return it's name.

Definition at line 1094 of file gamehand.c.

Referenced by establish_new_connection().

◆ place_starting_unit()

static struct tile * place_starting_unit ( struct tile starttile,
struct player pplayer,
struct unit_type ptype,
char  crole 
)
static

Place a starting unit for the player. Returns tile where unit was really placed. By default the ptype is used and crole does not matter, but if former is NULL, crole will be used instead.

Definition at line 156 of file gamehand.c.

Referenced by init_new_game().

◆ send_game_info()

void send_game_info ( struct conn_list *  dest)

Send game_info packet; some server options and various stuff... dest == NULL means game.est_connections

It may be sent at any time. It MUST be sent before any player info, as it contains the number of players. To avoid inconsistency, it SHOULD be sent after rulesets and any other server settings.

Definition at line 905 of file gamehand.c.

Referenced by api_edit_create_building(), api_edit_remove_building(), begin_phase(), begin_turn(), city_build_free_buildings(), end_turn(), establish_new_connection(), first_timeout_action(), found_new_tech(), handle_edit_city(), handle_edit_game(), handle_edit_mode(), handle_edit_player(), increase_timeout_because_unit_moved(), load_command(), remove_city(), set_ai_level(), set_command(), timeout_action(), and transfer_city().

◆ send_ruleset_choices()

static void send_ruleset_choices ( struct connection pc)
static

Call this on a connection with HACK access to send it a set of ruleset choices. Probably this should be called immediately when granting HACK access to a connection.

Definition at line 1105 of file gamehand.c.

Referenced by handle_single_want_hack_req().

◆ send_scenario_description()

void send_scenario_description ( struct conn_list *  dest)

Send description of the current scenario. dest NULL causes send to everyone

Definition at line 962 of file gamehand.c.

Referenced by establish_new_connection(), handle_edit_scenario_desc(), and load_command().

◆ send_scenario_info()

void send_scenario_info ( struct conn_list *  dest)

Send current scenario info. dest NULL causes send to everyone

Definition at line 948 of file gamehand.c.

Referenced by establish_new_connection(), handle_edit_game(), and load_command().

◆ send_year_to_clients()

void send_year_to_clients ( void  )

Tell clients the year, and also update turn_done and nturns_idle fields for all players.

Definition at line 879 of file gamehand.c.

Referenced by end_turn().

◆ team_placement_continent()

static int team_placement_continent ( const struct tile ptile1,
const struct tile ptile2 
)
static

Calculate the distance between tiles, according to the 'teamplacement' setting set to 'CONTINENT'.

Definition at line 260 of file gamehand.c.

Referenced by do_team_placement().

◆ team_placement_horizontal()

static int team_placement_horizontal ( const struct tile ptile1,
const struct tile ptile2 
)
static

Calculate the distance between tiles, according to the 'teamplacement' setting set to 'HORIZONTAL'.

Definition at line 272 of file gamehand.c.

Referenced by do_team_placement().

◆ team_placement_state_destroy()

static void team_placement_state_destroy ( struct team_placement_state pstate)
static

Destroys a team_placement_state structure.

Definition at line 299 of file gamehand.c.

Referenced by do_team_placement().

◆ team_placement_vertical()

static int team_placement_vertical ( const struct tile ptile1,
const struct tile ptile2 
)
static

Calculate the distance between tiles, according to the 'teamplacement' setting set to 'VERTICAL'.

Definition at line 286 of file gamehand.c.

Referenced by do_team_placement().

◆ update_timeout()

int update_timeout ( void  )

adjusts game.info.timeout based on various server options

timeoutint: adjust game.info.timeout every timeoutint turns timeoutinc: adjust game.info.timeout by adding timeoutinc to it. timeoutintinc: every time we adjust game.info.timeout, we add timeoutintinc to timeoutint. timeoutincmult: every time we adjust game.info.timeout, we multiply timeoutinc by timeoutincmult

Definition at line 983 of file gamehand.c.

Referenced by end_turn().