57#define CHALLENGE_ROOT "challenge"
59#define SPECLIST_TAG startpos
60#define SPECLIST_TYPE struct startpos
62#define startpos_list_iterate(list, plink, psp) \
63 TYPED_LIST_BOTH_ITERATE(struct startpos_list_link, struct startpos, \
65#define startpos_list_iterate_end LIST_BOTH_ITERATE_END
79#define SPECPQ_TAG team_placement
80#define SPECPQ_DATA_TYPE struct team_placement_state *
81#define SPECPQ_PRIORITY_TYPE long
134 if (pplayer !=
NULL) {
138 for (
i = 0; utype ==
NULL &&
i < num;
i++) {
207 log_verbose(
"Removed hut on start position for %s",
259#define team_placement_closest sq_map_distance
318 *
pconfig->total_startpos_num);
357 for (
i = 0;
i <
pconfig->usable_startpos_num;
i++) {
364 for (j =
i + 1; j < (
i >=
pconfig->flexible_startpos_num
366 :
pconfig->flexible_startpos_num); j++) {
373 for (k = 0; k <
pconfig->total_startpos_num; k++) {
374 if (k !=
i && t1 ==
pstate->startpos[k]) {
381 for (k = 0; k <
pconfig->total_startpos_num; k++) {
382 if (k !=
i && t1 ==
pstate->startpos[k]) {
390 }
else if (t1 < t2) {
394 for (k = 0; k <
pconfig->total_startpos_num; k++) {
395 if (k !=
i && t1 ==
pstate->startpos[k]) {
397 }
else if (k != j && t2 ==
pstate->startpos[k]) {
405 for (k = 0; k <
pconfig->total_startpos_num; k++) {
406 if (k !=
i && t1 ==
pstate->startpos[k]) {
409 }
else if (k != j && t2 ==
pstate->startpos[k]) {
426 pnew->startpos[
i] = t2;
427 pnew->startpos[j] = t1;
441 log_normal(
_(
"Didn't find optimal solution for team placement "
442 "in %d iterations."),
iter);
463 sizeof(
server.game_identifier));
492 log_verbose(
"Placing players at start positions.");
503 bool removed =
FALSE;
516 if (
NULL != choice) {
525 if (
NULL != choice) {
535 log_verbose(
"Start position (%d, %d) exactly matches player %s (%s).",
566 log_verbose(
"Start position (%d, %d) matches player %s (%s).",
573 log_verbose(
"Start position (%d, %d) cannot be assigned for "
574 "any player, keeping for the moment...",
612 log_verbose(
"Do team placement for %d players, using %s variant.",
618 config.usable_startpos_num =
config.flexible_startpos_num;
625 *
config.total_startpos_num);
631 if (
i <
config.usable_startpos_num) {
637 while (
i <
config.total_startpos_num) {
644 *
config.total_startpos_num);
647 j =
config.usable_startpos_num;
662 config.startpos[j] = ptile;
667 while (
i <
config.usable_startpos_num) {
671 while (j <
config.total_startpos_num) {
680 for (
i = 0;
i <
config.usable_startpos_num;
i++) {
687 log_verbose(
"Start position (%d, %d) assigned to team %d (%s)",
718 if (
i <
config.usable_startpos_num) {
740 log_verbose(
"Assigning unrestricted start positions.");
753 log_verbose(
"Start position (%d, %d) assigned randomly "
770 log_verbose(
"Ignoring nation restrictions on remaining start positions.");
783 log_verbose(
"Start position (%d, %d) assigned to mismatched "
889 pplayer->nturns_idle++;
1004 _(
"The turn timeout has exceeded its maximum value, "
1005 "fixing at its maximum."));
1006 log_debug(
"game.info.timeout exceeded maximum value");
1012 _(
"The turn timeout is smaller than zero, "
1013 "fixing at zero."));
1014 log_debug(
"game.info.timeout less than zero");
1021 log_debug(
"timeout=%d, inc=%d incmult=%d\n "
1022 "int=%d, intinc=%d, turns till next=%d",
1066 fc_snprintf(filename,
sizeof(filename),
"%s_%d_%d",
1114 const char *filename,
void *
data_in)
1120 log_verbose(
"Can't send more than %d ruleset names to client, "
1128 log_verbose(
"Modpack name '%s' too long to send to client, skipped",
1193 log_warn(
"Unexpected ruleset selection packet from client");
1198 log_verbose(
"Attempt to set ruleset from non-hack level connection");
1225 log_error(
"Modpack \"%s\" does not contain ruleset at all",
1242 const char *token =
NULL;
1243 bool you_have_hack =
FALSE;
1247 you_have_hack = (token &&
strcmp(token, packet->
token) == 0);
1255 log_debug(
"Failed to read authentication token");
1258 if (you_have_hack) {
bool adv_data_phase_init(struct player *pplayer, bool is_new_phase)
void adv_data_phase_done(struct player *pplayer)
#define CALL_PLR_AI_FUNC(_func, _player,...)
const char * calendar_text(void)
void send_conn_info(struct conn_list *src, struct conn_list *dest)
void conn_set_access(struct connection *pconn, enum cmdlevel new_level, bool granted)
#define conn_list_iterate(connlist, pconn)
#define conn_list_iterate_end
#define MAX_NUM_UNIT_LIST
const struct ft_color ftc_server
const struct ft_color ftc_any
int current_turn_timeout(void)
static void gen_challenge_filename(struct connection *pc)
static const char * get_challenge_fullname(struct connection *pc)
void send_scenario_description(struct conn_list *dest)
void send_year_to_clients(void)
void send_scenario_info(struct conn_list *dest)
static struct tile * place_starting_unit(struct tile *starttile, struct player *pplayer, struct unit_type *ptype, char crole)
#define team_placement_closest
static int team_placement_vertical(const struct tile *ptile1, const struct tile *ptile2)
void handle_single_want_hack_req(struct connection *pc, const struct packet_single_want_hack_req *packet)
void send_game_info(struct conn_list *dest)
static void send_ruleset_choices(struct connection *pc)
static struct tile * find_dispersed_position(struct player *pplayer, struct tile *pcenter)
#define startpos_list_iterate_end
static void do_team_placement(const struct team_placement_config *pconfig, struct team_placement_state *pbest_state, int iter_max)
static int team_placement_continent(const struct tile *ptile1, const struct tile *ptile2)
static void ruleset_cache_sendclient_cb(const char *mp_name, const char *filename, void *data_in)
#define startpos_list_iterate(list, plink, psp)
enum unit_role_id crole_to_role_id(char crole)
static const char * get_challenge_filename(struct connection *pc)
void increase_timeout_because_unit_moved(void)
void handle_ruleset_select(struct connection *pc, const struct packet_ruleset_select *packet)
struct unit_type * crole_to_unit_type(char crole, struct player *pplayer)
static void team_placement_state_destroy(struct team_placement_state *pstate)
const char * new_challenge_filename(struct connection *pc)
static int team_placement_horizontal(const struct tile *ptile1, const struct tile *ptile2)
void cache_rulesets(void)
#define fc_assert_msg(condition, message,...)
#define log_warn(message,...)
#define log_verbose(message,...)
#define fc_assert(condition)
#define fc_assert_ret_msg(condition, message,...)
#define fc_assert_ret_val(condition, val)
#define fc_assert_action(condition, action)
#define log_debug(message,...)
#define log_normal(message,...)
#define log_error(message,...)
int sq_map_distance(const struct tile *tile0, const struct tile *tile1)
bool startpos_nation_allowed(const struct startpos *psp, const struct nation_type *pnation)
struct tile * startpos_tile(const struct startpos *psp)
bool startpos_allows_all(const struct startpos *psp)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
int map_startpos_count(void)
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
void map_distance_vector(int *dx, int *dy, const struct tile *tile0, const struct tile *tile1)
#define iterate_outward(nmap, start_tile, max_dist, itr_tile)
#define iterate_outward_end
#define map_startpos_iterate(NAME_psp)
#define map_startpos_iterate_end
#define index_to_map_pos(pmap_x, pmap_y, mindex)
void map_show_circle(struct player *pplayer, struct tile *ptile, int radius_sq)
void update_tile_knowledge(struct tile *ptile)
void modpack_ruleset_cache_iterate(mrc_cb cb, void *data)
const char * modpack_file_from_ruleset_cache(const char *name)
const char * modpack_serv_file(struct section_file *sf)
const char * modpack_rulesetdir(struct section_file *sf)
struct fileinfo_list * get_modpacks_list(void)
const char * modpack_cache_ruleset(struct section_file *sf)
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
const char * nation_rule_name(const struct nation_type *pnation)
struct nation_type * nation_of_player(const struct player *pplayer)
void notify_conn(struct conn_list *dest, const struct tile *ptile, enum event_type event, const struct ft_color color, const char *format,...)
void lsend_packet_new_year(struct conn_list *dest, const struct packet_new_year *packet)
int send_packet_scenario_info(struct connection *pc, const struct packet_scenario_info *packet)
int send_packet_ruleset_choices(struct connection *pc, const struct packet_ruleset_choices *packet)
int send_packet_game_info(struct connection *pc, const struct packet_game_info *packet)
int send_packet_calendar_info(struct connection *pc, const struct packet_calendar_info *packet)
int dsend_packet_single_want_hack_reply(struct connection *pc, bool you_have_hack)
int send_packet_scenario_description(struct connection *pc, const struct packet_scenario_description *packet)
int send_packet_timeout_info(struct connection *pc, const struct packet_timeout_info *packet)
int player_slot_count(void)
const char * player_name(const struct player *pplayer)
int player_index(const struct player *pplayer)
#define players_iterate_end
#define players_iterate(_pplayer)
#define player_list_iterate(playerlist, pplayer)
#define player_list_iterate_end
#define shuffled_players_iterate_end
#define shuffled_players_iterate(NAME_pplayer)
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
const char * secfile_error(void)
void secfile_destroy(struct section_file *secfile)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
void randomize_base64url_string(char *s, size_t n)
char * freeciv_storage_dir(void)
#define fileinfo_list_iterate(list, pnode)
#define fileinfo_list_iterate_end
struct server_arguments srvarg
enum server_states server_state(void)
bool read_init_script(struct connection *caller, const char *script_filename, bool from_cmdline, bool check)
bool set_rulesetdir(struct connection *caller, const char *str, bool check, int read_recursion)
char start_units[MAX_LEN_STARTUNIT]
struct packet_scenario_description scenario_desc
struct conn_list * est_connections
struct packet_game_info info
int additional_phase_seconds
struct packet_scenario_info scenario
struct timer * phase_timer
struct civ_game::@32::@36 server
struct packet_timeout_info tinfo
struct packet_calendar_info calendar
enum team_placement team_placement
struct civ_map::@44::@46 server
struct packet_ruleset_choices * packet
struct unit_type * init_units[MAX_NUM_UNIT_LIST]
char rulesets[MAX_NUM_RULESETS][MAX_RULESET_NAME_LENGTH]
char modpack[MAX_RULESET_NAME_LENGTH]
float seconds_to_phasedone
int flexible_startpos_num
int fc_snprintf(char *str, size_t n, const char *format,...)
size_t fc_strlcpy(char *dest, const char *src, size_t n)
struct team * team_by_number(const int team_id)
const char * team_rule_name(const struct team *pteam)
int team_number(const struct team *pteam)
const struct player_list * team_members(const struct team *pteam)
#define teams_iterate_end
#define teams_iterate(_pteam)
#define is_ocean_tile(ptile)
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
#define tile_continent(_tile)
#define tile_has_extra(ptile, pextra)
double timer_read_seconds(struct timer *t)
static bool is_non_allied_unit_tile(const struct tile *ptile, const struct player *pplayer, bool everyone_non_allied)
struct unit_type * first_role_unit_for_player(const struct player *pplayer, int role)
struct unit_type * get_role_unit(int role, int role_index)
int num_role_units(int role)
bool utype_player_already_has_this_unique(const struct player *pplayer, const struct unit_type *putype)
static bool utype_has_flag(const struct unit_type *punittype, int flag)
#define MAP_NATIVE_HEIGHT