mirror of https://github.com/tstellar/bygfoot.git
Finished loading of leagues and cups and generating of teams.
This commit is contained in:
parent
ba51e1a908
commit
be3b94742f
|
@ -35,3 +35,6 @@ doc:
|
|||
|
||||
doc-verbose:
|
||||
doxygen Doxyfile
|
||||
|
||||
doc-clean:
|
||||
rm -rf docs/*
|
||||
|
|
4
TODO
4
TODO
|
@ -1,6 +1,6 @@
|
|||
gyözö
|
||||
|
||||
working on: loading of countries, leagues and cups from xml files.
|
||||
working on: generating the fixtures at the beginning of a season.
|
||||
|
||||
current tasks:
|
||||
implement a function 'file_check_home_dir' in file.c that checks whether
|
||||
|
@ -17,4 +17,4 @@ list of files:
|
|||
$HOME/.bygfoot/definitions/{any xml files found in the support_files/definitions directory}
|
||||
$HOME/.bygfoot/names/{any files found in the support_files/names directory}
|
||||
|
||||
the function should get called in bygfoot_init in main.c.
|
||||
the function should get called in main_init in main.c.
|
||||
|
|
|
@ -11,13 +11,14 @@ bin_PROGRAMS = bygfoot
|
|||
bygfoot_SOURCES = \
|
||||
callback_func.c callback_func.h \
|
||||
callbacks.c callbacks.h \
|
||||
cup.c cup.h free.h maths.h misc.h team.h variables.h xml_league.h \
|
||||
editor_callback_func.c editor_callback_func.h \
|
||||
editor_callbacks.c editor_callbacks.h \
|
||||
editor_interface.c editor_interface.h \
|
||||
file.c file.h \
|
||||
file.c file.h free.h misc.h support.h \
|
||||
finance.c finance.h \
|
||||
fixture.c fixture.h \
|
||||
free.c free.h \
|
||||
free.c cup.h fixture.h free.h league.h player.h variables.h \
|
||||
game.c game.h \
|
||||
game_gui.c game_gui.h \
|
||||
generation.c generation.h \
|
||||
|
@ -25,32 +26,32 @@ bygfoot_SOURCES = \
|
|||
gui.c gui.h \
|
||||
history.c history.h \
|
||||
interface.c callbacks.h interface.h support.h \
|
||||
league.c league.h \
|
||||
league.c league.h team.h variables.h \
|
||||
load_save.c load_save.h \
|
||||
main.c main.h \
|
||||
maths.c maths.h \
|
||||
misc.c misc.h \
|
||||
misc_callbacks.c misc_callbacks.h \
|
||||
misc_callback_func.c misc_callback_func.h \
|
||||
main.c file.h free.h main.h variables.h window.h \
|
||||
maths.c maths.h misc.h variables.h \
|
||||
misc.c free.h misc.h \
|
||||
misc_callbacks.c free.h misc_callback_func.h misc_callbacks.h \
|
||||
misc_callback_func.c misc_callback_func.h start_end.h support.h treeview.h variables.h xml_country.h \
|
||||
misc_interface.c misc_interface.h misc_callbacks.h support.h \
|
||||
misc2_callbacks.c misc2_callbacks.h \
|
||||
misc2_interface.c misc2_interface.h misc2_callbacks.h support.h \
|
||||
option.c option.h \
|
||||
options_callbacks.c options_callbacks.h \
|
||||
options_interface.c options_interface.h options_callbacks.h support.h \
|
||||
player.c player.h \
|
||||
startup.c startup.h \
|
||||
player.c free.h league.h maths.h player.h team.h variables.h \
|
||||
start_end.c cup.h fixture.h league.h maths.h player.h start_end.h team.h transfer.h variables.h xml_name.h \
|
||||
support.c support.h \
|
||||
team.c team.h \
|
||||
team.c cup.h free.h league.h maths.h player.h team.h variables.h \
|
||||
transfer.c transfer.h \
|
||||
treeview.c treeview.h \
|
||||
treeview.c gui.h league.h support.h team.h treeview.h variables.h \
|
||||
treeview_cell.c treeview_cell.h \
|
||||
window.c window.h \
|
||||
xml_fixtures.c xml_fixtures.h \
|
||||
xml_country.c xml_country.h \
|
||||
xml_cup.c xml_cup.h \
|
||||
window.c misc_interface.h file.h free.h support.h window.h \
|
||||
xml_cup.c cup.h file.h misc.h variables.h xml_cup.h \
|
||||
xml_country.c file.h free.h league.h misc.h variables.h xml_cup.h xml_country.h xml_league.h \
|
||||
xml_general.c xml_general.h \
|
||||
xml_league.c xml_league.h \
|
||||
xml_league.c file.h league.h misc.h team.h variables.h xml_league.h \
|
||||
xml_name.c file.h free.h maths.h variables.h xml_name.h \
|
||||
xml_teams.c xml_teams.h \
|
||||
xml.c xml.h
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#include "gettext_macros.h"
|
||||
|
||||
/**
|
||||
* Program version number.
|
||||
|
@ -30,24 +30,42 @@
|
|||
enum ExitCodes
|
||||
{
|
||||
EXIT_OK = 0, /**< Normal exit. */
|
||||
EXIT_DIR_OPEN, /**< Exit when the $HOME/.bygfoot/definitions directory can't be opened. */
|
||||
EXIT_DIR_OPEN_FAILED, /**< Exit when the $HOME/.bygfoot/definitions directory can't be opened. */
|
||||
EXIT_FILE_OPEN_FAILED,
|
||||
EXIT_PRINT_ERROR, /**< Exit when the print_error function is called on a set error.*/
|
||||
EXIT_NO_LEAGUES,
|
||||
EXIT_CHOOSE_TEAM_ERROR,
|
||||
EXIT_END
|
||||
};
|
||||
|
||||
/** Scout and physio qualities. */
|
||||
enum Quality
|
||||
{
|
||||
QUALITY_BEST = 1,
|
||||
QUALITY_GOOD,
|
||||
QUALITY_AVERAGE,
|
||||
QUALITY_BAD,
|
||||
QUALITY_END
|
||||
};
|
||||
|
||||
/** Starting numbers of league, cup and supercup numerical ids. */
|
||||
#define ID_LEAGUE_START 1000
|
||||
#define ID_CUP_START 2000
|
||||
|
||||
/** The player names file. */
|
||||
#define PLAYER_NAMES_FILE "player_names.xml"
|
||||
|
||||
/**
|
||||
* A struct representing a country.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GString *name, /**< Name of the country. */
|
||||
*symbol, /**< Symbol of the country, e.g. a flag pixmap. */
|
||||
*id; /**< Id of the country, e.g. 'england'. */
|
||||
*symbol, /**< Symbol of the country, eg a flag pixmap. */
|
||||
*sid; /**< Id of the country, eg 'england'. */
|
||||
|
||||
/** Leagues, cups and supercups arrays. */
|
||||
GArray *leagues,
|
||||
*cups,
|
||||
*supercups;
|
||||
/** Leagues and cups arrays. */
|
||||
GArray *leagues, *cups;
|
||||
} Country;
|
||||
|
||||
/** Convenience abbreviation. */
|
||||
|
@ -60,11 +78,7 @@ typedef struct
|
|||
/** Convenience abbreviation. */
|
||||
#define cp(i) g_array_index(country.cups, Cup, i)
|
||||
|
||||
gint my_team;
|
||||
/** The font used in treeviews. */
|
||||
GString *font_name;
|
||||
|
||||
/** The pointer to the main window of the game. */
|
||||
GtkWidget *main_window;
|
||||
/** Convenience abbreviation. */
|
||||
#define player_name(i) ((GString*)g_ptr_array_index(player_names, i))->str;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "bygfoot.h"
|
||||
|
||||
#include "interface.h"
|
||||
#include "support.h"
|
||||
|
|
263
src/cup.c
263
src/cup.c
|
@ -1 +1,264 @@
|
|||
#include "cup.h"
|
||||
#include "free.h"
|
||||
#include "main.h"
|
||||
#include "maths.h"
|
||||
#include "misc.h"
|
||||
#include "team.h"
|
||||
#include "variables.h"
|
||||
#include "xml_league.h"
|
||||
|
||||
/**
|
||||
Create and return a new cup with default values.
|
||||
@return The new cup.
|
||||
@see #Cup
|
||||
*/
|
||||
Cup
|
||||
cup_new(void)
|
||||
{
|
||||
Cup new;
|
||||
|
||||
new.name = g_string_new("");
|
||||
new.short_name = g_string_new("");
|
||||
new.symbol = g_string_new("");
|
||||
new.sid = g_string_new("");
|
||||
|
||||
new.id = cup_new_id();
|
||||
new.type = CUP_TYPE_NATIONAL;
|
||||
new.last_week = new.week_gap = -1;
|
||||
new.yellow_red = 1000;
|
||||
new.skill_diff = 0;
|
||||
new.average_capacity = -1;
|
||||
|
||||
new.choose_teams = g_array_new(FALSE, FALSE, sizeof(CupChooseTeam));
|
||||
new.choose_team_user = cup_choose_team_new();
|
||||
new.rounds = g_array_new(FALSE, FALSE, sizeof(CupRound));
|
||||
new.teams = g_array_new(FALSE, FALSE, sizeof(Team));
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
/** Return a new numerical id for a cup.
|
||||
We browse through the existing cups and take the
|
||||
first free id.
|
||||
*/
|
||||
gint
|
||||
cup_new_id(void)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
if(cps == NULL)
|
||||
return ID_CUP_START;
|
||||
|
||||
for(i=ID_CUP_START;i<ID_CUP_START+1000;i++)
|
||||
{
|
||||
for(j=0;j<cps->len;j++)
|
||||
if(cp(j).id == i)
|
||||
break;
|
||||
|
||||
if(j == cps->len)
|
||||
return i;
|
||||
}
|
||||
|
||||
g_warning("cup_new_id: didn't find a free numerical id.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Return a CupChooseTeam with default values. */
|
||||
CupChooseTeam
|
||||
cup_choose_team_new(void)
|
||||
{
|
||||
CupChooseTeam new;
|
||||
|
||||
new.sid = g_string_new("");
|
||||
new.number_of_teams = -1;
|
||||
new.start_idx = new.end_idx = -1;
|
||||
new.randomly = FALSE;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
/** Return a CupRound with default values. */
|
||||
CupRound
|
||||
cup_round_new(void)
|
||||
{
|
||||
CupRound new;
|
||||
|
||||
new.home_away = TRUE;
|
||||
new.replay = 0;
|
||||
new.neutral = FALSE;
|
||||
new.round_robin_number_of_groups = 0;
|
||||
new.round_robin_number_of_advance = -1;
|
||||
new.round_robin_number_of_best_advance = 0;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
/** Fill the teams array of a cup with teams according to the choose_teams of
|
||||
the cup. Only called for international cups.
|
||||
@param cup The pointer to the cup. */
|
||||
void
|
||||
cup_load_choose_teams(Cup *cup)
|
||||
{
|
||||
gint i, j, k, number_of_teams, end_idx = -1;
|
||||
CupChooseTeam *choose_team = NULL;
|
||||
GArray *teams = NULL;
|
||||
GArray *leagues = NULL;
|
||||
GPtrArray *sids = NULL;
|
||||
|
||||
for(i=0;i<cup->choose_teams->len;i++)
|
||||
{
|
||||
choose_team = &g_array_index(cup->choose_teams, CupChooseTeam, i);
|
||||
leagues = g_array_new(FALSE, FALSE, sizeof(League));
|
||||
teams = g_array_new(FALSE, FALSE, sizeof(Team));
|
||||
sids = misc_separate_strings(choose_team->sid->str);
|
||||
|
||||
for(j=0;j<sids->len;j++)
|
||||
{
|
||||
xml_league_read(((GString*)g_ptr_array_index(sids, j))->str, leagues);
|
||||
for(k=0;k<g_array_index(leagues, League, leagues->len - 1).teams->len;k++)
|
||||
team_append_to_array(
|
||||
&g_array_index(g_array_index(leagues, League, leagues->len - 1).teams, Team, k),
|
||||
teams);
|
||||
}
|
||||
|
||||
gint permutation[teams->len];
|
||||
for(j=0;j<teams->len;j++)
|
||||
permutation[j] = j;
|
||||
|
||||
if(choose_team->randomly)
|
||||
{
|
||||
if(choose_team->start_idx == -1)
|
||||
math_generate_permutation(permutation, 0, teams->len - 1);
|
||||
else
|
||||
math_generate_permutation(permutation,
|
||||
choose_team->start_idx - 1,
|
||||
choose_team->end_idx - 1);
|
||||
}
|
||||
|
||||
number_of_teams = 0;
|
||||
if(choose_team->start_idx == -1)
|
||||
end_idx = teams->len;
|
||||
else
|
||||
end_idx = choose_team->end_idx -
|
||||
choose_team->start_idx + 1;
|
||||
|
||||
if(teams->len < end_idx)
|
||||
cup_choose_team_abort(cup, choose_team, FALSE);
|
||||
|
||||
for(j = 0; j < end_idx; j++)
|
||||
{
|
||||
if(!is_in_international_cups(&g_array_index(teams, Team, permutation[j])))
|
||||
{
|
||||
team_append_to_array_with_ids(&g_array_index(teams, Team, permutation[j]), cup->teams,
|
||||
cup->id, cup->teams->len);
|
||||
team_generate_players(&g_array_index(cup->teams, Team, cup->teams->len - 1));
|
||||
number_of_teams++;
|
||||
}
|
||||
|
||||
if(number_of_teams == choose_team->number_of_teams)
|
||||
break;
|
||||
}
|
||||
|
||||
if(number_of_teams != choose_team->number_of_teams)
|
||||
cup_choose_team_abort(cup, choose_team, FALSE);
|
||||
|
||||
free_g_string_array(&sids);
|
||||
free_teams_array(&teams);
|
||||
free_leagues_array(&leagues);
|
||||
}
|
||||
|
||||
/*d*/
|
||||
/* printf("\n%s\n", cup->name->str); */
|
||||
/* for(i=0;i<cup->teams->len;i++) */
|
||||
/* printf("%d %s\n", i, g_array_index(cup->teams, Team, i).name->str); */
|
||||
}
|
||||
|
||||
/** Add the teams specified by the choose_team_user rule to the teams
|
||||
array of the cup.
|
||||
@param cup The pointer to the cup. */
|
||||
void
|
||||
cup_load_choose_team_user(Cup *cup)
|
||||
{
|
||||
gint i;
|
||||
gchar type[SMALL];
|
||||
gint number, number_of_teams = 0;
|
||||
CupChooseTeam *choose_team = &cup->choose_team_user;
|
||||
|
||||
sscanf(choose_team->sid->str, "%[^0-9]%d", type, &number);
|
||||
|
||||
|
||||
if(strcmp(type, "league") == 0)
|
||||
{
|
||||
if(ligs->len < number ||
|
||||
lig(number - 1).teams->len < choose_team->end_idx)
|
||||
cup_choose_team_abort(cup, choose_team, TRUE);
|
||||
|
||||
for(i = choose_team->start_idx - 1; i <= choose_team->end_idx - 1; i++)
|
||||
{
|
||||
if(!is_in_international_cups(&g_array_index(lig(number - 1).teams, Team, i)))
|
||||
{
|
||||
team_append_to_array(&g_array_index(lig(number - 1).teams, Team, i),
|
||||
cup->teams);
|
||||
number_of_teams++;
|
||||
}
|
||||
|
||||
if(number_of_teams == choose_team->number_of_teams)
|
||||
break;
|
||||
}
|
||||
|
||||
if(number_of_teams != choose_team->number_of_teams)
|
||||
cup_choose_team_abort(cup, choose_team, TRUE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(type, "cup") == 0)
|
||||
{
|
||||
if(season == 1)
|
||||
{
|
||||
if(lig(0).teams->len < choose_team->number_of_teams)
|
||||
cup_choose_team_abort(cup, choose_team, TRUE);
|
||||
|
||||
gint permutation[lig(0).teams->len];
|
||||
math_generate_permutation(permutation, 0, lig(0).teams->len - 1);
|
||||
|
||||
for(i = choose_team->start_idx - 1; i < choose_team->end_idx - 1; i++)
|
||||
{
|
||||
if(!is_in_international_cups(&g_array_index(lig(number - 1).teams, Team, permutation[i])))
|
||||
{
|
||||
team_append_to_array(&g_array_index(lig(number - 1).teams,
|
||||
Team, permutation[i - choose_team->start_idx + 1]),
|
||||
cup->teams);
|
||||
number_of_teams++;
|
||||
}
|
||||
|
||||
if(number_of_teams == choose_team->number_of_teams)
|
||||
break;
|
||||
}
|
||||
|
||||
if(number_of_teams != choose_team->number_of_teams)
|
||||
cup_choose_team_abort(cup, choose_team, TRUE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** todo: load teams from a cup */
|
||||
}
|
||||
}
|
||||
|
||||
/** Print an error and exit the program if there's a problem loading
|
||||
the CupChooseTeam.
|
||||
@param *cup The cup the choose_team is from.
|
||||
@param choose_team The choose_team that caused the error.
|
||||
@param user Whether the function is called from cup_load_choose_team_user()
|
||||
or cup_load_choose_teams(). */
|
||||
void
|
||||
cup_choose_team_abort(const Cup *cup, const CupChooseTeam *choose_team, gboolean user)
|
||||
{
|
||||
if(user)
|
||||
g_warning("cup_load_choose_team_user: there was an error loading choose_team %s from cup %s. maybe there aren't enough teams in the specified league or cup.\n", choose_team->sid->str, cup->sid->str);
|
||||
else
|
||||
g_warning("cup_load_choose_teams: there was an error loading choose_team %s from cup %s. maybe there aren't enough teams in the specified league or cup.\n", choose_team->sid->str, cup->sid->str);
|
||||
|
||||
main_exit_program(EXIT_CHOOSE_TEAM_ERROR);
|
||||
}
|
||||
|
|
109
src/cup.h
109
src/cup.h
|
@ -2,100 +2,27 @@
|
|||
#define CUP_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "cup_struct.h"
|
||||
|
||||
/**
|
||||
There are only two cup types currently,
|
||||
national and international cups.
|
||||
*/
|
||||
enum CupType
|
||||
{
|
||||
CUP_TYPE_NATIONAL = 0,
|
||||
CUP_TYPE_INTERNATIONAL,
|
||||
CUP_TYPE_END
|
||||
};
|
||||
Cup
|
||||
cup_new(void);
|
||||
|
||||
/** Rules for a round of a cup.
|
||||
Cups consist of rounds, e.g. the final counts as
|
||||
a round or the round robin games. */
|
||||
typedef struct
|
||||
{
|
||||
/** Whether there are home and away games or only one leg.
|
||||
Default: TRUE. */
|
||||
gboolean home_away;
|
||||
/** How many times a match gets repeated if there's a draw.
|
||||
Default: 0. */
|
||||
gint replay;
|
||||
/** Whether the matches are on neutral ground.
|
||||
Default: FALSE. */
|
||||
gboolean neutral;
|
||||
/** How many round robin groups there are.
|
||||
Default: 0 (ie. no round robin). */
|
||||
gint round_robin_number_of_groups;
|
||||
/** How many teams advance from each group.
|
||||
Default: -1. */
|
||||
gint round_robin_number_of_advance;
|
||||
/** How many teams advance apart from those that
|
||||
are specified already (e.g. the first two advance
|
||||
and additionally the best 3 from all the groups.
|
||||
Default: -1. */
|
||||
gint round_robin_number_of_best_advance;
|
||||
|
||||
} CupRound;
|
||||
gint
|
||||
cup_new_id(void);
|
||||
|
||||
/**
|
||||
Rules for choosing teams from the league files.
|
||||
This could tell us to select the first three teams
|
||||
from the league 'Italy 1' to participate in the cup.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** The string id of the league we choose from.
|
||||
Default: "". */
|
||||
GString *id;
|
||||
/** The number of teams chosen.
|
||||
Default: -1 (ie. all teams are chosen). */
|
||||
gint number_of_teams;
|
||||
/** The range from which the teams are chosen,
|
||||
e.g. 2 and 5 means the teams from 2 to 5 are chosen
|
||||
(given that 'number_of_teams' is 4).
|
||||
Defaults: -1. */
|
||||
gint start_idx, end_idx;
|
||||
/** Whether the teams are chosen randomly,
|
||||
ie. 3 random teams from the range 1-20.
|
||||
Default: FALSE. */
|
||||
gboolean randomly;
|
||||
} CupChooseTeam;
|
||||
CupChooseTeam
|
||||
cup_choose_team_new(void);
|
||||
|
||||
/**
|
||||
Structure representing a cup.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Name and short name of the cup, a pixmap path,
|
||||
and the string id (e.g. england_fa or so). */
|
||||
GString *name, *short_name, *symbol, *id;
|
||||
/** Numerical id.*/
|
||||
gint nid;
|
||||
/** The cup type. @see #CupType*/
|
||||
gint cup_type;
|
||||
/** Last week (typically the week the final
|
||||
takes place) and weeks between matchdays. */
|
||||
gint last_week, week_gap;
|
||||
/** Number of yellow cards that lead to a missed match. */
|
||||
gint yellow_red;
|
||||
/** These are only read if it's an international cup. */
|
||||
gint average_skill, average_talent;
|
||||
/** Array with rules how teams are chosen.
|
||||
@see #CupChooseTeam */
|
||||
GArray *choose_teams;
|
||||
/** The ChooseTeam rule according to which
|
||||
the participant from the user's league is chosen.
|
||||
This is irrelevant for national cups.
|
||||
@see #CupChooseTeam */
|
||||
CupChooseTeam user;
|
||||
/** The rounds of the cup.
|
||||
@see #CupRound*/
|
||||
GArray *rounds;
|
||||
} Cup;
|
||||
CupRound
|
||||
cup_round_new(void);
|
||||
|
||||
void
|
||||
cup_load_choose_teams(Cup *cup);
|
||||
|
||||
void
|
||||
cup_load_choose_team_user(Cup *cup);
|
||||
|
||||
void
|
||||
cup_choose_team_abort(const Cup *cup, const CupChooseTeam *choose_team, gboolean user);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
#ifndef CUP_STRUCT_H
|
||||
#define CUP_STRUCT_H
|
||||
|
||||
#include "table_struct.h"
|
||||
|
||||
/** Types for cups. */
|
||||
enum CupType
|
||||
{
|
||||
CUP_TYPE_NATIONAL = 0,
|
||||
CUP_TYPE_INTERNATIONAL,
|
||||
CUP_TYPE_SUPERCUP,
|
||||
CUP_TYPE_END
|
||||
};
|
||||
|
||||
/** Rules for a round of a cup.
|
||||
Cups consist of rounds, e.g. the final counts as
|
||||
a round or the round robin games. */
|
||||
typedef struct
|
||||
{
|
||||
/** Whether there are home and away games or only one leg.
|
||||
Default: TRUE. */
|
||||
gboolean home_away;
|
||||
/** How many times a match gets repeated if there's a draw.
|
||||
Default: 0. */
|
||||
gint replay;
|
||||
/** Whether the matches are on neutral ground.
|
||||
Default: FALSE. */
|
||||
gboolean neutral;
|
||||
/** How many round robin groups there are.
|
||||
Default: 0 (ie. no round robin). */
|
||||
gint round_robin_number_of_groups;
|
||||
/** How many teams advance from each group.
|
||||
Default: -1. */
|
||||
gint round_robin_number_of_advance;
|
||||
/** How many teams advance apart from those that
|
||||
are specified already (e.g. the first two advance
|
||||
and additionally the best 3 from all the groups.
|
||||
Default: 0. */
|
||||
gint round_robin_number_of_best_advance;
|
||||
|
||||
} CupRound;
|
||||
|
||||
/**
|
||||
Rules for choosing teams from the league files.
|
||||
This could tell us to select the first three teams
|
||||
from the league 'Italy 1' to participate in the cup.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** The string id of the league we choose from.
|
||||
Default: "". */
|
||||
GString *sid;
|
||||
/** The number of teams chosen.
|
||||
Default: -1 (ie. all teams are chosen). */
|
||||
gint number_of_teams;
|
||||
/** The range from which the teams are chosen,
|
||||
e.g. 2 and 5 means the teams from 2 to 5 are chosen
|
||||
(given that 'number_of_teams' is 4).
|
||||
Defaults: -1 (ie. the teams are chosen from the whole
|
||||
range of teams in the league). */
|
||||
gint start_idx, end_idx;
|
||||
/** Whether the teams are chosen randomly,
|
||||
ie. 3 random teams from the range 1-20.
|
||||
Default: FALSE. */
|
||||
gboolean randomly;
|
||||
} CupChooseTeam;
|
||||
|
||||
/** Structure representing a cup. */
|
||||
typedef struct
|
||||
{
|
||||
/** Name and short name of the cup, a pixmap path,
|
||||
and the string id (e.g. england_fa or so).
|
||||
Default: "". */
|
||||
GString *name, *short_name, *symbol, *sid;
|
||||
/** Numerical id. */
|
||||
gint id;
|
||||
/** The cup type. Default: CUP_TYPE_NATIONAL.
|
||||
@see #CupType */
|
||||
gint type;
|
||||
/** Last week (typically the week the final
|
||||
takes place) and weeks between matchdays.
|
||||
Default: -1. */
|
||||
gint last_week, week_gap;
|
||||
/** Number of yellow cards that lead to a missed match.
|
||||
Default: 1000 (off). */
|
||||
gint yellow_red;
|
||||
/** Difference of the average skill for the cup teams compared to
|
||||
the league with highest average skill.
|
||||
Default: 0. */
|
||||
gint skill_diff;
|
||||
/** Average stadium capacity. Default: -1. */
|
||||
gint average_capacity;
|
||||
/** Array with rules how teams are chosen.
|
||||
@see #CupChooseTeam */
|
||||
GArray *choose_teams;
|
||||
/** The ChooseTeam rule according to which
|
||||
the participant from the user's league is chosen.
|
||||
This is irrelevant for national cups.
|
||||
@see #CupChooseTeam */
|
||||
CupChooseTeam choose_team_user;
|
||||
/** The rounds of the cup.
|
||||
@see #CupRound*/
|
||||
GArray *rounds;
|
||||
/** The teams belonging to the cup.
|
||||
Relevant only if it's an international one. */
|
||||
GArray *teams;
|
||||
} Cup;
|
||||
|
||||
#endif
|
140
src/file.c
140
src/file.c
|
@ -1,4 +1,126 @@
|
|||
#include "file.h"
|
||||
#include "free.h"
|
||||
#include "main.h"
|
||||
#include "misc.h"
|
||||
#include "support.h"
|
||||
|
||||
/**
|
||||
The list of directories the file_find_support_file() function
|
||||
searches for support files (e.g. pixmaps or text files).
|
||||
@see file_find_support_file()
|
||||
@see file_add_support_directory_recursive()
|
||||
*/
|
||||
static GList *support_directories = NULL;
|
||||
|
||||
/**
|
||||
Add the specified directory to the list of directories file_find_support_file()
|
||||
searches for support files.
|
||||
Any subdirectories are added recursively.
|
||||
@param directory The full path of the directory to be added.
|
||||
@see file_find_support_file()
|
||||
@see #support_directories
|
||||
*/
|
||||
void
|
||||
file_add_support_directory_recursive (const gchar *directory)
|
||||
{
|
||||
GDir *newdir =
|
||||
g_dir_open(directory, 0, NULL);
|
||||
const gchar *file;
|
||||
gchar *fullpath;
|
||||
|
||||
if(newdir == NULL)
|
||||
return;
|
||||
|
||||
add_pixmap_directory(directory);
|
||||
support_directories = g_list_prepend (support_directories,
|
||||
g_strdup (directory));
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
file = g_dir_read_name(newdir);
|
||||
|
||||
if(file == NULL)
|
||||
break;
|
||||
|
||||
fullpath = g_strdup_printf ("%s%s%s", directory,
|
||||
G_DIR_SEPARATOR_S, file);
|
||||
|
||||
if(g_file_test(fullpath, G_FILE_TEST_IS_DIR))
|
||||
file_add_support_directory_recursive(fullpath);
|
||||
|
||||
g_free(fullpath);
|
||||
}
|
||||
|
||||
g_dir_close(newdir);
|
||||
}
|
||||
|
||||
/**
|
||||
Search the list of support directories for a given file and return
|
||||
the full path name.
|
||||
The return value must be freed.
|
||||
@param filename The name of the file we look for (without path).
|
||||
@return A pointer to the full path string of the file or NULL if
|
||||
we didn't find the file. The gchar* must be freed.
|
||||
@see #support_directories
|
||||
@see file_add_support_directory_recursive()
|
||||
*/
|
||||
gchar*
|
||||
file_find_support_file (const gchar *filename)
|
||||
{
|
||||
GList *elem;
|
||||
|
||||
/* We step through each of the pixmaps directory to find it. */
|
||||
elem = support_directories;
|
||||
while (elem)
|
||||
{
|
||||
gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
|
||||
G_DIR_SEPARATOR_S, filename);
|
||||
if (g_file_test (pathname, G_FILE_TEST_EXISTS))
|
||||
return pathname;
|
||||
|
||||
g_free (pathname);
|
||||
elem = elem->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** A custom function opening files.
|
||||
@param filename The full path to the file or a file name from the support files.
|
||||
@param bits The mode we use, e.g. "r" or "w". @see fopen()
|
||||
@param fil The file pointer that will point to the opened stream.
|
||||
@param abort_program Whether to abort the program if we encounter an error.
|
||||
@return TRUE on success, FALSE otherwise. */
|
||||
gboolean
|
||||
my_fopen(const gchar *filename, gchar *bits, FILE **fil, gboolean abort_program)
|
||||
{
|
||||
gchar buf[SMALL];
|
||||
gchar *support_file = file_find_support_file(filename);
|
||||
*fil = fopen(filename, bits);
|
||||
|
||||
if(*fil != NULL)
|
||||
{
|
||||
g_free(support_file);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
*fil = fopen(support_file, bits);
|
||||
if(*fil != NULL)
|
||||
{
|
||||
g_free(support_file);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
sprintf(buf, "Could not open file '%s' in mode '%s'.\n", filename, bits);
|
||||
|
||||
g_warning(buf);
|
||||
/*d*/
|
||||
/* show_popup_window(buf, NULL); */
|
||||
|
||||
if(abort_program)
|
||||
main_exit_program(EXIT_FILE_OPEN_FAILED);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
Retrieve those files in the given directory
|
||||
|
@ -43,21 +165,3 @@ file_dir_get_contents(const gchar *dir_name, const gchar *prefix)
|
|||
|
||||
return contents;
|
||||
}
|
||||
|
||||
/**
|
||||
Free a GPtrArray containing GStrings.
|
||||
@param dir_contents The array to be freed.
|
||||
*/
|
||||
void
|
||||
file_dir_free_contents(GPtrArray *dir_contents)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if(dir_contents == NULL)
|
||||
return;
|
||||
|
||||
for(i=0;i<dir_contents->len;i++)
|
||||
g_string_free((GString*)g_ptr_array_index(dir_contents, i), TRUE);
|
||||
|
||||
g_ptr_array_free(dir_contents, TRUE);
|
||||
}
|
||||
|
|
15
src/file.h
15
src/file.h
|
@ -2,12 +2,23 @@
|
|||
#define FILE_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "misc.h"
|
||||
|
||||
void
|
||||
file_add_support_directory_recursive (const gchar *directory);
|
||||
|
||||
gchar*
|
||||
file_find_support_file (const gchar *filename);
|
||||
|
||||
gboolean
|
||||
file_get_next_line(FILE *fil, gchar *buf);
|
||||
|
||||
GPtrArray*
|
||||
file_dir_get_contents(const gchar *dir_name, const gchar *prefix);
|
||||
|
||||
void
|
||||
file_dir_free_contents(GPtrArray *dir_contents);
|
||||
file_get_player_names(gint number_of_names);
|
||||
|
||||
gboolean
|
||||
my_fopen(const gchar *filename, gchar *bits, FILE **fil, gboolean abort_program);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
#include "fixture.h"
|
|
@ -0,0 +1,68 @@
|
|||
#ifndef FIXTURE_H
|
||||
#define FIXTURE_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
|
||||
/** Possible goal types. */
|
||||
enum GoalType
|
||||
{
|
||||
GOAL_TYPE_REGULAR= 0,
|
||||
GOAL_TYPE_OWN,
|
||||
GOAL_TYPE_PENALTY,
|
||||
GOAL_TYPE_PENALTY_MISSED,
|
||||
GOAL_TYPE_PENALTY_SAVE,
|
||||
GOAL_TYPE_PENALTY_POST,
|
||||
GOAL_TYPE_PENALTY_CROSS,
|
||||
GOAL_TYPE_END
|
||||
};
|
||||
|
||||
/** Possible goal times. */
|
||||
enum GoalTime
|
||||
{
|
||||
/** In regulation. */
|
||||
GOAL_TIME_REGULATION = 0,
|
||||
/** In extra time. */
|
||||
GOAL_TIME_EXTRA,
|
||||
/** In penalty shoot-out. */
|
||||
GOAL_TIME_PENALTY,
|
||||
GOAL_TIME_END
|
||||
};
|
||||
|
||||
/** Structure representing a goal. */
|
||||
typedef struct
|
||||
{
|
||||
gint minute, /**< The minute it happened. */
|
||||
team_number, /**< The team that scored (0 or 1). */
|
||||
time, /**< Whether it was in regulation, extra time or penalties. */
|
||||
type; /** What kind of goal it was (e.g. penalty). */
|
||||
|
||||
/** Name of the scorer. */
|
||||
GString *scorer_name;
|
||||
} Goal;
|
||||
|
||||
/** Structure representing a fixture, or, in other words,
|
||||
a match. */
|
||||
typedef struct
|
||||
{
|
||||
/** The cup or league the fixture belongs to. */
|
||||
gint clid;
|
||||
/** The round (in a cup) the fixture belongs to. */
|
||||
gint round;
|
||||
/** When it takes place. */
|
||||
gint week_number, week_round_number;
|
||||
/** The teams involved. */
|
||||
gint team_clid[2], team_id[2];
|
||||
/** The number of goals for each team in
|
||||
regulation, extra time and penalty shoot-out. */
|
||||
gint result[2][3];
|
||||
/** Whether there's home advantage, this is second leg,
|
||||
or the game has to be decided. */
|
||||
gboolean home_advantage, second_leg, decisive;
|
||||
/** How many people attended and whether there were
|
||||
special events. */
|
||||
gint attendance, stadium_event;
|
||||
/** The goals that were scored. */
|
||||
GArray *goals;
|
||||
} Fixture;
|
||||
|
||||
#endif
|
258
src/free.c
258
src/free.c
|
@ -1,4 +1,36 @@
|
|||
#include "cup.h"
|
||||
#include "fixture.h"
|
||||
#include "free.h"
|
||||
#include "league.h"
|
||||
#include "player.h"
|
||||
#include "variables.h"
|
||||
|
||||
|
||||
/** Free a GString if it isn't NULL.
|
||||
@param string The string to be freed. */
|
||||
void
|
||||
free_g_string(GString **string)
|
||||
{
|
||||
if(*string == NULL)
|
||||
return;
|
||||
|
||||
g_string_free(*string, TRUE);
|
||||
|
||||
*string = NULL;
|
||||
}
|
||||
|
||||
/** Free a GArray if it isn't NULL.
|
||||
@param array The array to be freed. */
|
||||
void
|
||||
free_g_array(GArray **array)
|
||||
{
|
||||
if(*array == NULL)
|
||||
return;
|
||||
|
||||
g_array_free(*array, TRUE);
|
||||
|
||||
*array = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
Free all memory allocated by the program.
|
||||
|
@ -7,12 +39,9 @@
|
|||
void
|
||||
free_memory(void)
|
||||
{
|
||||
free_variables();
|
||||
free_country();
|
||||
if(font_name != NULL)
|
||||
{
|
||||
g_string_free(font_name, TRUE);
|
||||
font_name = NULL;
|
||||
}
|
||||
free_g_string(&font_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,31 +52,32 @@ free_country(void)
|
|||
{
|
||||
gint i;
|
||||
GString **strings[3] =
|
||||
{&country.name, &country.symbol, &country.id};
|
||||
GArray **arrays[3] =
|
||||
{&ligs, &cps, &country.supercups};
|
||||
{&country.name, &country.symbol, &country.sid};
|
||||
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
if(*strings[i] != NULL)
|
||||
{
|
||||
g_string_free(*strings[i], TRUE);
|
||||
*strings[i] = NULL;
|
||||
}
|
||||
}
|
||||
free_g_string(strings[i]);
|
||||
|
||||
if(ligs != NULL)
|
||||
for(i=0;i<ligs->len;i++)
|
||||
free_league(&(g_array_index(ligs, League, i)));
|
||||
free_leagues_array(&ligs);
|
||||
|
||||
for(i=0;i<3;i++)
|
||||
{
|
||||
if(*arrays[i] != NULL)
|
||||
{
|
||||
g_array_free(*arrays[i], TRUE);
|
||||
*arrays[i] = NULL;
|
||||
}
|
||||
}
|
||||
free_cups_array(&cps);
|
||||
}
|
||||
|
||||
/**
|
||||
Free the memory occupied by a leagues array.
|
||||
@param leagues The pointer to the array we free.
|
||||
*/
|
||||
void
|
||||
free_leagues_array(GArray **leagues)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if(*leagues == NULL)
|
||||
return;
|
||||
|
||||
for(i=0;i<(*leagues)->len;i++)
|
||||
free_league(&g_array_index(*leagues, League, i));
|
||||
|
||||
free_g_array(leagues);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,49 +88,177 @@ void
|
|||
free_league(League *league)
|
||||
{
|
||||
gint i;
|
||||
GString **strings[8] =
|
||||
GString **strings[7] =
|
||||
{&league->name,
|
||||
&league->short_name,
|
||||
&league->symbol,
|
||||
&league->id,
|
||||
&league->prom_rel.prom_games_cup_id,
|
||||
&league->prom_rel.prom_games_dest_id,
|
||||
&league->table.name,
|
||||
&league->table.league_id};
|
||||
&league->sid,
|
||||
&league->prom_rel.prom_games_cup_sid,
|
||||
&league->prom_rel.prom_games_dest_sid,
|
||||
&league->table.name};
|
||||
GArray **arrays[3] =
|
||||
{&league->teams,
|
||||
&league->prom_rel.elements,
|
||||
&league->table.elements};
|
||||
|
||||
for(i=0;i<8;i++)
|
||||
if(*strings[i] != NULL)
|
||||
{
|
||||
g_string_free(*strings[i], TRUE);
|
||||
*strings[i] = NULL;
|
||||
}
|
||||
for(i=0;i<7;i++)
|
||||
free_g_string(strings[i]);
|
||||
|
||||
if(league->teams != NULL)
|
||||
for(i=0;i<league->teams->len;i++)
|
||||
free_team(&(g_array_index(league->teams, Team, i)));
|
||||
free_teams_array(&league->teams);
|
||||
|
||||
for(i=0;i<3;i++)
|
||||
if(*arrays[i] != NULL)
|
||||
{
|
||||
g_array_free(*arrays[i], TRUE);
|
||||
*arrays[i] = NULL;
|
||||
}
|
||||
free_g_array(arrays[i]);
|
||||
}
|
||||
|
||||
/** Free the memory occupied by a teams array.
|
||||
@param teams The pointer to the array we free. */
|
||||
void
|
||||
free_teams_array(GArray **teams)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if(*teams == NULL)
|
||||
return;
|
||||
|
||||
for(i=0;i<(*teams)->len;i++)
|
||||
free_team(&g_array_index(*teams, Team, i));
|
||||
|
||||
free_g_array(teams);
|
||||
}
|
||||
|
||||
/**
|
||||
Free the memory occupied by a team.
|
||||
@param team The pointer to the team we free.
|
||||
@param tm The pointer to the team we free.
|
||||
*/
|
||||
void
|
||||
free_team(Team *team)
|
||||
free_team(Team *tm)
|
||||
{
|
||||
if(team->name != NULL)
|
||||
gint i;
|
||||
|
||||
free_g_string(&tm->name);
|
||||
|
||||
if(tm->players != NULL)
|
||||
{
|
||||
g_string_free(team->name, TRUE);
|
||||
team->name = NULL;
|
||||
for(i=0;i<tm->players->len;i++)
|
||||
free_player(&g_array_index(tm->players, Player, i));
|
||||
|
||||
free_g_array(&tm->players);
|
||||
}
|
||||
}
|
||||
|
||||
/** Free the memory occupied by a player.
|
||||
@param pl The pointer to the player we free. */
|
||||
void
|
||||
free_player(Player *pl)
|
||||
{
|
||||
free_g_string(&pl->name);
|
||||
|
||||
free_g_array(&pl->cards);
|
||||
|
||||
/* todo: free history */
|
||||
}
|
||||
|
||||
/**
|
||||
Free the memory occupied by a cups array.
|
||||
@param cups The pointer to the array we free.
|
||||
*/
|
||||
void
|
||||
free_cups_array(GArray **cups)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if(*cups == NULL)
|
||||
return;
|
||||
|
||||
for(i=0;i<(*cups)->len;i++)
|
||||
free_cup(&g_array_index(*cups, Cup, i));
|
||||
|
||||
free_g_array(cups);
|
||||
}
|
||||
|
||||
/**
|
||||
Free the memory occupied by a cup.
|
||||
@param cup The pointer to the cup we free.
|
||||
*/
|
||||
void
|
||||
free_cup(Cup *cup)
|
||||
{
|
||||
gint i;
|
||||
GString **strings[4] =
|
||||
{&cup->name,
|
||||
&cup->short_name,
|
||||
&cup->symbol,
|
||||
&cup->sid};
|
||||
GArray **arrays[3] =
|
||||
{&cup->choose_teams,
|
||||
&cup->rounds,
|
||||
&cup->teams};
|
||||
|
||||
for(i=0;i<4;i++)
|
||||
free_g_string(strings[i]);
|
||||
|
||||
if(cup->choose_teams != NULL)
|
||||
for(i=0;i<cup->choose_teams->len;i++)
|
||||
free_cup_choose_team(&g_array_index(cup->choose_teams, CupChooseTeam, i));
|
||||
free_cup_choose_team(&cup->choose_team_user);
|
||||
|
||||
if(cup->teams != NULL)
|
||||
for(i=0;i<cup->teams->len;i++)
|
||||
free_team(&g_array_index(cup->teams, Team, i));
|
||||
|
||||
for(i=0;i<3;i++)
|
||||
free_g_array(arrays[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
Free the memory occupied by a CupChooseTeam.
|
||||
@param cup_choose_team The pointer to the team we free.
|
||||
*/
|
||||
void
|
||||
free_cup_choose_team(CupChooseTeam *cup_choose_team)
|
||||
{
|
||||
free_g_string(&cup_choose_team->sid);
|
||||
}
|
||||
|
||||
/** Free some global variables (except for the country variable). */
|
||||
void
|
||||
free_variables(void)
|
||||
{
|
||||
gint i, j;
|
||||
GArray **arrays[2] =
|
||||
{&transfer_list,
|
||||
&fixtures};
|
||||
|
||||
free_g_string_array(&player_names);
|
||||
|
||||
if(fixtures != NULL)
|
||||
for(i=0;i<fixtures->len;i++)
|
||||
for(j=0;j<g_array_index(fixtures, Fixture, i).goals->len;j++)
|
||||
free_g_string(&g_array_index(
|
||||
g_array_index(
|
||||
fixtures, Fixture, i).goals, Goal, j).scorer_name);
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
free_g_array(arrays[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
Free a GPtrArray containing GStrings.
|
||||
@param array The array to be freed.
|
||||
*/
|
||||
void
|
||||
free_g_string_array(GPtrArray **array)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if(*array == NULL)
|
||||
return;
|
||||
|
||||
for(i=0;i<(*array)->len;i++)
|
||||
free_g_string((GString**)&g_ptr_array_index(*array, i));
|
||||
|
||||
g_ptr_array_free(*array, TRUE);
|
||||
|
||||
*array = NULL;
|
||||
}
|
||||
|
|
36
src/free.h
36
src/free.h
|
@ -2,8 +2,16 @@
|
|||
#define FREE_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "league.h"
|
||||
#include "variables.h"
|
||||
#include "cup_struct.h"
|
||||
#include "league_struct.h"
|
||||
#include "player_struct.h"
|
||||
#include "team_struct.h"
|
||||
|
||||
void
|
||||
free_g_array(GArray **array);
|
||||
|
||||
void
|
||||
free_g_string(GString **string);
|
||||
|
||||
void
|
||||
free_memory(void);
|
||||
|
@ -11,10 +19,34 @@ free_memory(void);
|
|||
void
|
||||
free_country(void);
|
||||
|
||||
void
|
||||
free_leagues_array(GArray **leagues);
|
||||
|
||||
void
|
||||
free_league(League *league);
|
||||
|
||||
void
|
||||
free_teams_array(GArray **teams);
|
||||
|
||||
void
|
||||
free_team(Team *team);
|
||||
|
||||
void
|
||||
free_cups_array(GArray **cups);
|
||||
|
||||
void
|
||||
free_cup(Cup *cup);
|
||||
|
||||
void
|
||||
free_cup_choose_team(CupChooseTeam *cup_choose_team);
|
||||
|
||||
void
|
||||
free_variables(void);
|
||||
|
||||
void
|
||||
free_g_string_array(GPtrArray **array);
|
||||
|
||||
void
|
||||
free_player(Player *pl);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* Standard gettext macros.
|
||||
*/
|
||||
#ifdef ENABLE_NLS
|
||||
# include <libintl.h>
|
||||
# undef _
|
||||
# define _(String) dgettext (PACKAGE, String)
|
||||
# ifdef gettext_noop
|
||||
# define N_(String) gettext_noop (String)
|
||||
# else
|
||||
# define N_(String) (String)
|
||||
# endif
|
||||
#else
|
||||
# define textdomain(String) (String)
|
||||
# define gettext(String) (String)
|
||||
# define dgettext(Domain,Message) (Message)
|
||||
# define dcgettext(Domain,Message,Type) (Message)
|
||||
# define bindtextdomain(Domain,Directory) (Domain)
|
||||
# define _(String) (String)
|
||||
# define N_(String) (String)
|
||||
#endif
|
||||
|
79
src/gui.c
79
src/gui.c
|
@ -1,81 +1,2 @@
|
|||
#include "gui.h"
|
||||
|
||||
/**
|
||||
The list of directories the find_support_file() function
|
||||
searches for support files (e.g. pixmaps or text files).
|
||||
@see find_support_file()
|
||||
@see add_support_directory_recursive()
|
||||
*/
|
||||
static GList *support_directories = NULL;
|
||||
|
||||
/**
|
||||
Add the specified directory to the list of directories find_support_file()
|
||||
searches for support files.
|
||||
Any subdirectories are added recursively.
|
||||
@param directory The full path of the directory to be added.
|
||||
@see find_support_file()
|
||||
@see #support_directories
|
||||
*/
|
||||
void
|
||||
add_support_directory_recursive (const gchar *directory)
|
||||
{
|
||||
GDir *newdir =
|
||||
g_dir_open(directory, 0, NULL);
|
||||
const gchar *file;
|
||||
gchar *fullpath;
|
||||
|
||||
if(newdir == NULL)
|
||||
return;
|
||||
|
||||
add_pixmap_directory(directory);
|
||||
support_directories = g_list_prepend (support_directories,
|
||||
g_strdup (directory));
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
file = g_dir_read_name(newdir);
|
||||
|
||||
if(file == NULL)
|
||||
break;
|
||||
|
||||
fullpath = g_strdup_printf ("%s%s%s", directory,
|
||||
G_DIR_SEPARATOR_S, file);
|
||||
|
||||
if(g_file_test(fullpath, G_FILE_TEST_IS_DIR))
|
||||
add_support_directory_recursive(fullpath);
|
||||
|
||||
g_free(fullpath);
|
||||
}
|
||||
|
||||
g_dir_close(newdir);
|
||||
}
|
||||
|
||||
/**
|
||||
Search the list of support directories for a given file and return
|
||||
the full path name.
|
||||
The return value must be freed.
|
||||
@param filename The name of the file we look for (without path).
|
||||
@return A pointer to the full path string of the file or NULL if
|
||||
we didn't find the file. The gchar* must be freed.
|
||||
@see #support_directories
|
||||
@see add_support_directory_recursive()
|
||||
*/
|
||||
gchar*
|
||||
find_support_file (const gchar *filename)
|
||||
{
|
||||
GList *elem;
|
||||
|
||||
/* We step through each of the pixmaps directory to find it. */
|
||||
elem = support_directories;
|
||||
while (elem)
|
||||
{
|
||||
gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
|
||||
G_DIR_SEPARATOR_S, filename);
|
||||
if (g_file_test (pathname, G_FILE_TEST_EXISTS))
|
||||
return pathname;
|
||||
|
||||
g_free (pathname);
|
||||
elem = elem->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,5 @@
|
|||
#define GUI_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "support.h"
|
||||
|
||||
void
|
||||
add_support_directory_recursive (const gchar *directory);
|
||||
|
||||
gchar*
|
||||
find_support_file (const gchar *filename);
|
||||
|
||||
#endif
|
||||
|
|
42
src/league.c
42
src/league.c
|
@ -1,4 +1,6 @@
|
|||
#include "league.h"
|
||||
#include "team.h"
|
||||
#include "variables.h"
|
||||
|
||||
/**
|
||||
Create a new league with some default values.
|
||||
|
@ -11,18 +13,22 @@ league_new(void)
|
|||
League new;
|
||||
|
||||
new.name = g_string_new("");
|
||||
new.id = g_string_new("");
|
||||
new.sid = g_string_new("");
|
||||
new.short_name = g_string_new("");
|
||||
new.symbol = g_string_new("");
|
||||
|
||||
new.prom_rel.prom_games_dest_id = g_string_new("");
|
||||
new.prom_rel.prom_games_cup_id = g_string_new("");
|
||||
new.id = league_new_id();
|
||||
|
||||
new.average_skill = new.average_capacity = -1;
|
||||
|
||||
new.prom_rel.prom_games_dest_sid = g_string_new("");
|
||||
new.prom_rel.prom_games_cup_sid = g_string_new("");
|
||||
new.prom_rel.elements = g_array_new(FALSE, FALSE, sizeof(PromRelElement));
|
||||
|
||||
new.teams = g_array_new(FALSE, FALSE, sizeof(Team));
|
||||
|
||||
new.table.name = g_string_new("");
|
||||
new.table.league_id = g_string_new("");
|
||||
new.table.league_id = new.id;
|
||||
new.table.elements = g_array_new(FALSE, FALSE, sizeof(TableElement));
|
||||
|
||||
new.first_week = new.week_gap = 1;
|
||||
|
@ -42,7 +48,33 @@ prom_rel_element_new(void)
|
|||
PromRelElement new;
|
||||
|
||||
new.ranks[0] = new.ranks[1] = 0;
|
||||
new.dest_id = g_string_new("");
|
||||
new.dest_sid = g_string_new("");
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
/** Return a new numerical id for a league.
|
||||
We browse through the existing leagues and take the
|
||||
first free nid.
|
||||
*/
|
||||
gint
|
||||
league_new_id(void)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
if(ligs == NULL)
|
||||
return ID_LEAGUE_START;
|
||||
|
||||
for(i=ID_LEAGUE_START;i<ID_LEAGUE_START+1000;i++)
|
||||
{
|
||||
for(j=0;j<ligs->len;j++)
|
||||
if(lig(j).id == i)
|
||||
break;
|
||||
|
||||
if(j == ligs->len)
|
||||
return i;
|
||||
}
|
||||
|
||||
g_warning("league_new_id: didn't find a free numerical id.");
|
||||
return -1;
|
||||
}
|
||||
|
|
113
src/league.h
113
src/league.h
|
@ -1,112 +1,8 @@
|
|||
#ifndef LEAUGUE_H
|
||||
#define LEAUGUE_H
|
||||
#ifndef LEAGUE_H
|
||||
#define LEAGUE_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "team.h"
|
||||
|
||||
/**
|
||||
Table element values.
|
||||
@see TableElement
|
||||
@see Table
|
||||
*/
|
||||
enum TableElementValues
|
||||
{
|
||||
TABLE_PLAYED = 0,
|
||||
TABLE_WON,
|
||||
TABLE_DRAW,
|
||||
TABLE_LOST,
|
||||
TABLE_GF,
|
||||
TABLE_GA,
|
||||
TABLE_PTS,
|
||||
TABLE_END
|
||||
};
|
||||
|
||||
/**
|
||||
An element representing a team in the tables.
|
||||
@see Table
|
||||
@see #TableElementValues
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
gint team_id;
|
||||
gint values[TABLE_END];
|
||||
} TableElement;
|
||||
|
||||
/**
|
||||
A table belonging to a league or a cup with round robin.
|
||||
@see TableElement
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GString *name;
|
||||
GString *league_id;
|
||||
GArray *elements;
|
||||
} Table;
|
||||
|
||||
/**
|
||||
An element representing a promotion or relegation rule.
|
||||
This means, a PromRelElement specifies a range of teams
|
||||
that get promoted or relegated to a given league.
|
||||
@see PromRel
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
gint ranks[2]; /**< The range of teams; default 0 and 0 */
|
||||
GString *dest_id; /**< The id of the destination league. Default "" */
|
||||
} PromRelElement;
|
||||
|
||||
/**
|
||||
This structure specifies how promotion and relegation is handled in a league.
|
||||
It contains promotion and relegation rules in an array and possibly also
|
||||
a rule about promotion games to be played.
|
||||
@see PromRelElement
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** The id of the league the promotion games winner gets promoted to. Default "" */
|
||||
GString *prom_games_dest_id;
|
||||
/** The id of the cup that specifies the promotion games format.
|
||||
We regard the promotion games as a national cup like any other cup.
|
||||
@see Cup
|
||||
*/
|
||||
GString *prom_games_cup_id; /* "" */
|
||||
|
||||
/** Array with promotion/relegation rules.
|
||||
@see PromRelElement
|
||||
*/
|
||||
GArray *elements;
|
||||
} PromRel;
|
||||
|
||||
/**
|
||||
Representation of a league.
|
||||
@see PromRel
|
||||
@see Table
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Default value "" */
|
||||
GString *name, *short_name, *id, *symbol;
|
||||
/** @see PromRel */
|
||||
PromRel prom_rel;
|
||||
/** Numerical id, as opposed to the string id. */
|
||||
gint nid;
|
||||
/** The first week games are played. Default 1. */
|
||||
gint first_week;
|
||||
/** Weeks between two matchdays. Default 1. */
|
||||
gint week_gap;
|
||||
/** Number of yellow cards until a player gets banned.
|
||||
Default 1000 (which means 'off', basically). */
|
||||
gint yellow_red;
|
||||
/** Average skill and talent values for the first season. */
|
||||
gint average_skill, average_talent;
|
||||
/** Array of teams in the league.
|
||||
@see Team */
|
||||
GArray *teams;
|
||||
/** League table.
|
||||
@see Table */
|
||||
Table table;
|
||||
} League;
|
||||
|
||||
#include "league_struct.h"
|
||||
|
||||
League
|
||||
league_new(void);
|
||||
|
@ -114,4 +10,7 @@ league_new(void);
|
|||
PromRelElement
|
||||
prom_rel_element_new(void);
|
||||
|
||||
gint
|
||||
league_new_id(void);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
#ifndef LEAGUE_STRUCT_H
|
||||
#define LEAGUE_STRUCT_H
|
||||
|
||||
#include "table_struct.h"
|
||||
|
||||
/**
|
||||
An element representing a promotion or relegation rule.
|
||||
This means, a PromRelElement specifies a range of teams
|
||||
that get promoted or relegated to a given league.
|
||||
@see PromRel
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
gint ranks[2]; /**< The range of teams; default 0 and 0 */
|
||||
GString *dest_sid; /**< The id of the destination league. Default "" */
|
||||
} PromRelElement;
|
||||
|
||||
/**
|
||||
This structure specifies how promotion and relegation is handled in a league.
|
||||
It contains promotion and relegation rules in an array and possibly also
|
||||
a rule about promotion games to be played.
|
||||
@see PromRelElement
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** The id of the league the promotion games winner gets promoted to. Default "" */
|
||||
GString *prom_games_dest_sid;
|
||||
/** The id of the cup that specifies the promotion games format.
|
||||
We regard the promotion games as a national cup like any other cup.
|
||||
@see Cup
|
||||
*/
|
||||
GString *prom_games_cup_sid; /* "" */
|
||||
|
||||
/** Array with promotion/relegation rules.
|
||||
@see PromRelElement
|
||||
*/
|
||||
GArray *elements;
|
||||
} PromRel;
|
||||
|
||||
/**
|
||||
Representation of a league.
|
||||
@see PromRel
|
||||
@see Table
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Default value "" */
|
||||
GString *name, *short_name, *sid, *symbol;
|
||||
/** @see PromRel */
|
||||
PromRel prom_rel;
|
||||
/** Numerical id, as opposed to the string id 'sid'. */
|
||||
gint id;
|
||||
/** The first week games are played. Default 1. */
|
||||
gint first_week;
|
||||
/** Weeks between two matchdays. Default 1. */
|
||||
gint week_gap;
|
||||
/** Number of yellow cards until a player gets banned.
|
||||
Default 1000 (which means 'off', basically). */
|
||||
gint yellow_red;
|
||||
/** Average skill for the first season. Default: -1. */
|
||||
gint average_skill;
|
||||
/** Average stadium capacity. Default: -1. */
|
||||
gint average_capacity;
|
||||
/** Array of teams in the league.
|
||||
@see Team */
|
||||
GArray *teams;
|
||||
/** League table.
|
||||
@see Table */
|
||||
Table table;
|
||||
} League;
|
||||
|
||||
#endif
|
47
src/main.c
47
src/main.c
|
@ -3,16 +3,27 @@
|
|||
* Glade will not overwrite this file.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/*d*/
|
||||
#include "file.h"
|
||||
#include "free.h"
|
||||
#include "main.h"
|
||||
#include "variables.h"
|
||||
#include "window.h"
|
||||
|
||||
|
||||
/**
|
||||
Initialize some global variables. Most of them get nullified.
|
||||
*/
|
||||
void
|
||||
set_variables(void)
|
||||
main_init_variables(void)
|
||||
{
|
||||
ligs = cps = country.supercups = NULL;
|
||||
country.name = country.symbol = country.id = NULL;
|
||||
ligs = cps = NULL;
|
||||
country.name = country.symbol = country.sid = NULL;
|
||||
fixtures = NULL;
|
||||
transfer_list = NULL;
|
||||
player_names = NULL;
|
||||
|
||||
font_name = g_string_new("0");
|
||||
}
|
||||
|
@ -25,7 +36,7 @@ set_variables(void)
|
|||
@param argv Command line arguments array.
|
||||
*/
|
||||
void
|
||||
bygfoot_init(gint argc, gchar *argv[])
|
||||
main_init(gint argc, gchar *argv[])
|
||||
{
|
||||
gchar buf[SMALL];
|
||||
gchar *pwd = g_get_current_dir();
|
||||
|
@ -33,15 +44,14 @@ bygfoot_init(gint argc, gchar *argv[])
|
|||
/* initialize the random nr generator */
|
||||
srandom((unsigned)time(NULL));
|
||||
|
||||
add_support_directory_recursive(PACKAGE_DATA_DIR "/" PACKAGE "/support_files");
|
||||
file_add_support_directory_recursive(PACKAGE_DATA_DIR "/" PACKAGE "/support_files");
|
||||
sprintf(buf, "%s/support_files", pwd);
|
||||
g_free(pwd);
|
||||
add_support_directory_recursive(buf);
|
||||
file_add_support_directory_recursive(buf);
|
||||
sprintf(buf, "%s/.bygfoot", g_get_home_dir());
|
||||
add_support_directory_recursive(buf);
|
||||
|
||||
set_variables();
|
||||
file_add_support_directory_recursive(buf);
|
||||
|
||||
main_init_variables();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,12 +73,27 @@ main (gint argc, gchar *argv[])
|
|||
gtk_set_locale ();
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
bygfoot_init(argc, argv);
|
||||
main_init(argc, argv);
|
||||
|
||||
window_show_startup();
|
||||
|
||||
gtk_main ();
|
||||
|
||||
free_memory();
|
||||
main_exit_program(EXIT_OK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Exit the program with the given exit code. Try to
|
||||
destroy all widgets and free all memory first.
|
||||
@param exit_code The number we return to the shell.
|
||||
@return The exit code of the program. */
|
||||
void
|
||||
main_exit_program(gint exit_code)
|
||||
{
|
||||
if(gtk_main_level() > 0)
|
||||
gtk_main_quit();
|
||||
|
||||
free_memory();
|
||||
exit(exit_code);
|
||||
}
|
||||
|
|
13
src/main.h
13
src/main.h
|
@ -1,18 +1,15 @@
|
|||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
/*d*/
|
||||
#include "bygfoot.h"
|
||||
#include "gui.h"
|
||||
#include "support.h"
|
||||
#include "time.h"
|
||||
#include "variables.h"
|
||||
#include "window.h"
|
||||
|
||||
void
|
||||
bygfoot_init(gint argc, gchar *argv[]);
|
||||
main_init(gint argc, gchar *argv[]);
|
||||
|
||||
void
|
||||
set_variables(void);
|
||||
main_init_variables(void);
|
||||
|
||||
void
|
||||
main_exit_program(gint exit_code);
|
||||
|
||||
#endif
|
||||
|
|
32
src/maths.c
32
src/maths.c
|
@ -1,4 +1,7 @@
|
|||
#include "maths.h"
|
||||
#include "misc.h"
|
||||
#include "variables.h"
|
||||
|
||||
|
||||
/**
|
||||
Generate a Gauss-distributed (pseudo)random number.
|
||||
|
@ -6,7 +9,7 @@
|
|||
@return A Gauss-distributed random number.
|
||||
*/
|
||||
gfloat
|
||||
gaussrand(void)
|
||||
math_gaussrand(void)
|
||||
{
|
||||
static gfloat V1, V2, S;
|
||||
static gint phase = 0;
|
||||
|
@ -33,7 +36,7 @@ gaussrand(void)
|
|||
|
||||
/**
|
||||
Generate a Gauss-distributed random number within given boundaries
|
||||
using gaussrand().
|
||||
using math_gaussrand().
|
||||
Expectation value of the distribution is (upper + lower) / 2,
|
||||
the variance is so that the number is between the boundaries with probability
|
||||
99,7 %. If the number isn't between the boundaries, we cut off.
|
||||
|
@ -42,11 +45,11 @@ gaussrand(void)
|
|||
@return A Gauss-distributed number
|
||||
*/
|
||||
gfloat
|
||||
gauss_dist(gfloat lower, gfloat upper)
|
||||
math_gauss_dist(gfloat lower, gfloat upper)
|
||||
{
|
||||
gfloat result;
|
||||
|
||||
result = (gfloat)(upper - lower) / 6 * gaussrand()
|
||||
result = (gfloat)(upper - lower) / 6 * math_gaussrand()
|
||||
+ (gfloat)(upper + lower) / 2;
|
||||
|
||||
if(result < lower)
|
||||
|
@ -78,7 +81,7 @@ gauss_dist(gfloat lower, gfloat upper)
|
|||
@return A part of the integer 'value'.
|
||||
*/
|
||||
gint
|
||||
get_place(gint value, gint place)
|
||||
math_get_place(gint value, gint place)
|
||||
{
|
||||
if(place < 10)
|
||||
return (value % (gint)powf(10, place) -
|
||||
|
@ -112,7 +115,7 @@ get_place(gint value, gint place)
|
|||
@return The rounded integer.
|
||||
*/
|
||||
gint
|
||||
round_integer(gint number, gint places)
|
||||
math_round_integer(gint number, gint places)
|
||||
{
|
||||
gint length = 0;
|
||||
gfloat copy = (gfloat)number;
|
||||
|
@ -130,3 +133,20 @@ round_integer(gint number, gint places)
|
|||
return (gint)rint( (gfloat)number / powf(10, length + places) ) *
|
||||
powf(10, length + places);
|
||||
}
|
||||
|
||||
/** Generate a permutation of integers and write it to 'array'.
|
||||
@param array The integer array we store the permutation in.
|
||||
It must have size at least end - start - 1.
|
||||
@param start The integer to start with.
|
||||
@param end The integer to end with. */
|
||||
void
|
||||
math_generate_permutation(gint *array, gint start, gint end)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for(i = start; i < end + 1; i++)
|
||||
array[i - start] = i;
|
||||
|
||||
for(i=0;i<end - start;i++)
|
||||
misc_swap_int(&array[i], &array[math_rndi(i, end - start)]);
|
||||
}
|
||||
|
|
24
src/maths.h
24
src/maths.h
|
@ -1,26 +1,30 @@
|
|||
#ifndef MATH_H
|
||||
#define MATH_H
|
||||
#ifndef MATHS_H
|
||||
#define MATHS_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "variables.h"
|
||||
|
||||
/**
|
||||
Macros for random number generation (#rnd for float and #rndi for integer).
|
||||
Macros for random number generation (#rnd for float, #rndi and #gauss_disti for integer).
|
||||
*/
|
||||
#define rnd(lower,upper) ((gfloat)random()/(gfloat)0x7fffffff*((upper)-(lower))+(lower))
|
||||
#define rndi(lower,upper) ((gint)rint( rnd((gfloat)(lower) - 0.499, (gfloat)(upper) + 0.499) ))
|
||||
#define math_rnd(lower,upper) ((gfloat)random()/(gfloat)0x7fffffff*((upper)-(lower))+(lower))
|
||||
#define math_rndi(lower,upper) ((gint)rint( math_rnd((gfloat)(lower) - 0.499, (gfloat)(upper) + 0.499) ))
|
||||
#define math_gauss_disti(lower, upper) ((gint)rint( math_gauss_dist((gfloat)lower - 0.499, (gfloat)upper + 0.499)))
|
||||
|
||||
gfloat
|
||||
gaussrand(void);
|
||||
math_gaussrand(void);
|
||||
|
||||
gfloat
|
||||
gauss_dist(gfloat lower, gfloat upper);
|
||||
math_gauss_dist(gfloat lower, gfloat upper);
|
||||
|
||||
gint
|
||||
get_place(gint value, gint place);
|
||||
math_get_place(gint value, gint place);
|
||||
|
||||
gint
|
||||
round_integer(gint number, gint places);
|
||||
math_round_integer(gint number, gint places);
|
||||
|
||||
void
|
||||
math_generate_permutation(gint *array, gint start, gint end);
|
||||
|
||||
#endif
|
||||
|
|
67
src/misc.c
67
src/misc.c
|
@ -1,3 +1,5 @@
|
|||
#include "free.h"
|
||||
#include "main.h"
|
||||
#include "misc.h"
|
||||
|
||||
/**
|
||||
|
@ -23,12 +25,61 @@ misc_print_error(GError *error, gboolean abort_program)
|
|||
g_error_free(error);
|
||||
|
||||
if(abort_program)
|
||||
{
|
||||
free_memory();
|
||||
|
||||
if(gtk_main_level() > 0)
|
||||
gtk_main_quit();
|
||||
|
||||
exit(EXIT_PRINT_ERROR);
|
||||
}
|
||||
main_exit_program(EXIT_PRINT_ERROR);
|
||||
}
|
||||
|
||||
/** Swap two integers.
|
||||
@param first The first integer.
|
||||
@param second The second integer. */
|
||||
void
|
||||
misc_swap_int(gint *first, gint *second)
|
||||
{
|
||||
gint swap = *first;
|
||||
|
||||
*first = *second;
|
||||
*second = swap;
|
||||
}
|
||||
|
||||
/** Transform a string containing white spaces into an array of strings without
|
||||
white spaces.
|
||||
@param string The string containing white spaces.
|
||||
@return A GPtrArray containing all the strings without white spaces that were part of the original string.
|
||||
This array must be freed with free_g_string_array(). */
|
||||
GPtrArray*
|
||||
misc_separate_strings(gchar *string)
|
||||
{
|
||||
gint i, cnt = 0, start = 0;
|
||||
gchar buf[BIG];
|
||||
GPtrArray *string_array = g_ptr_array_new();
|
||||
GString *new_string = NULL;
|
||||
|
||||
for(i=0;i<strlen(string);i++)
|
||||
if(g_ascii_isspace(string[i]))
|
||||
start++;
|
||||
else
|
||||
break;
|
||||
|
||||
if(start == strlen(string))
|
||||
{
|
||||
g_warning("misc_separate_strings: input string contains only white spaces\n");
|
||||
return string_array;
|
||||
}
|
||||
|
||||
for(i=start;i<strlen(string) + 1;i++)
|
||||
{
|
||||
if(i < strlen(string) && !g_ascii_isspace(string[i]))
|
||||
buf[cnt++] = string[i];
|
||||
else
|
||||
{
|
||||
buf[cnt] = '\0';
|
||||
cnt = 0;
|
||||
if(strlen(buf) > 0)
|
||||
{
|
||||
new_string = g_string_new(buf);
|
||||
g_ptr_array_add(string_array, (gpointer)new_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return string_array;
|
||||
}
|
||||
|
|
|
@ -2,9 +2,14 @@
|
|||
#define MISC_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "free.h"
|
||||
|
||||
void
|
||||
misc_print_error(GError *error, gboolean abort_program);
|
||||
|
||||
void
|
||||
misc_swap_int(gint *first, gint *second);
|
||||
|
||||
GPtrArray*
|
||||
misc_separate_strings(gchar *string);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,14 +1,64 @@
|
|||
#include "misc_callback_func.h"
|
||||
#include "start_end.h"
|
||||
#include "support.h"
|
||||
#include "treeview.h"
|
||||
#include "variables.h"
|
||||
#include "xml_country.h"
|
||||
|
||||
|
||||
/* show the teams from the leagues in the country in
|
||||
the startup window */
|
||||
void
|
||||
misc_callback_show_team_list(GtkWidget *widget, const gchar *country_file)
|
||||
{
|
||||
gint i,j;
|
||||
GtkWidget *treeview_startup =
|
||||
lookup_widget(widget, "treeview_startup");
|
||||
|
||||
xml_country_read(country_file);
|
||||
|
||||
treeview_show_team_list(GTK_TREE_VIEW(treeview_startup), FALSE);
|
||||
|
||||
/*d*/
|
||||
/* for(i=0;i<cps->len;i++) */
|
||||
/* { */
|
||||
/* printf("** %d **\n", i); */
|
||||
/* printf("name %s short_name %s symbol %s id %s\n", cp(i).name->str, cp(i).short_name->str, cp(i).symbol->str, cp(i).sid->str); */
|
||||
/* printf("nid %d type %d last %d gap %d skilldiff %d cap %d\n", cp(i).id, cp(i).type, cp(i).last_week, cp(i).week_gap, cp(i).skill_diff, cp(i).average_capacity); */
|
||||
|
||||
/* for(j=0;j<cp(i).rounds->len;j++) */
|
||||
/* printf("%d homeaway %d repl %d neutr %d groups %d adv %d best %d\n", j, */
|
||||
/* g_array_index(cp(i).rounds, CupRound, j).home_away, */
|
||||
/* g_array_index(cp(i).rounds, CupRound, j).replay, */
|
||||
/* g_array_index(cp(i).rounds, CupRound, j).neutral, */
|
||||
/* g_array_index(cp(i).rounds, CupRound, j).round_robin_number_of_groups, */
|
||||
/* g_array_index(cp(i).rounds, CupRound, j).round_robin_number_of_advance, */
|
||||
/* g_array_index(cp(i).rounds, CupRound, j).round_robin_number_of_best_advance); */
|
||||
|
||||
/* printf("\n"); */
|
||||
/* for(j=0;j<cp(i).choose_teams->len;j++) */
|
||||
/* printf("%d id %s num %d start %d end %d rand %d\n", j, */
|
||||
/* g_array_index(cp(i).choose_teams, CupChooseTeam, j).sid->str, */
|
||||
/* g_array_index(cp(i).choose_teams, CupChooseTeam, j).number_of_teams, */
|
||||
/* g_array_index(cp(i).choose_teams, CupChooseTeam, j).start_idx, */
|
||||
/* g_array_index(cp(i).choose_teams, CupChooseTeam, j).end_idx, */
|
||||
/* g_array_index(cp(i).choose_teams, CupChooseTeam, j).randomly); */
|
||||
|
||||
/* printf("\n"); */
|
||||
/* } */
|
||||
}
|
||||
|
||||
/** Start a new game after the user's selected a team.
|
||||
@param widget A widget from the startup window that enables us
|
||||
to get the row in the team list the user has selected. */
|
||||
void
|
||||
misc_callback_start_game(GtkWidget *widget)
|
||||
{
|
||||
GtkTreeView *treeview =
|
||||
GTK_TREE_VIEW(lookup_widget(widget, "treeview_startup"));
|
||||
|
||||
my_team_clid = treeview_get_index(treeview, 0);
|
||||
my_team_id = treeview_get_index(treeview, 1);
|
||||
|
||||
start_new_game();
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#define MISC_CALLBACK_FUNC_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "support.h"
|
||||
#include "treeview.h"
|
||||
#include "xml_country.h"
|
||||
|
||||
void
|
||||
misc_callback_start_game(GtkWidget *widget);
|
||||
|
||||
void
|
||||
misc_callback_show_team_list(GtkWidget *widget, const gchar *country_file);
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
#include <string.h>
|
||||
|
||||
|
||||
#include "free.h"
|
||||
#include "misc_callback_func.h"
|
||||
#include "misc_callbacks.h"
|
||||
|
||||
void
|
||||
|
@ -15,7 +20,7 @@ on_team_selection_tv_row_activated (GtkTreeView *treeview,
|
|||
GtkTreeViewColumn *column,
|
||||
gpointer user_data)
|
||||
{
|
||||
|
||||
misc_callback_start_game(GTK_WIDGET(treeview));
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,6 +69,8 @@ on_team_selection_ok_clicked (GtkButton *button,
|
|||
gpointer user_data)
|
||||
{
|
||||
|
||||
misc_callback_start_game(GTK_WIDGET(button));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "misc_callback_func.h"
|
||||
#include "bygfoot.h"
|
||||
#include "misc_interface.h"
|
||||
#include "support.h"
|
||||
|
||||
|
|
269
src/player.c
269
src/player.c
|
@ -1,2 +1,271 @@
|
|||
#include "free.h"
|
||||
#include "league.h"
|
||||
#include "maths.h"
|
||||
#include "player.h"
|
||||
#include "team.h"
|
||||
#include "variables.h"
|
||||
|
||||
/** How much a player's skill can deviate from
|
||||
the average skill in his team. */
|
||||
#define CONSTANT_PLAYER_AVERAGE_SKILL_VARIANCE 0.1
|
||||
/** Lower limit for player ages. */
|
||||
#define CONSTANT_PLAYER_AGE_LOWER (18 * 52)
|
||||
/** Upper limit for player ages. */
|
||||
#define CONSTANT_PLAYER_AGE_UPPER (36 * 52)
|
||||
/** Lower limit for player peak ages. */
|
||||
#define CONSTANT_PLAYER_PEAK_AGE_LOWER (30 * 52)
|
||||
/** Upper limit for player peak ages. */
|
||||
#define CONSTANT_PLAYER_PEAK_AGE_UPPER (33 * 52)
|
||||
/** By how many weeks the peak age of goalies is
|
||||
greater. */
|
||||
#define CONSTANT_PLAYER_PEAK_AGE_GOALIE_ADDITION (2 * 52)
|
||||
/** Limits for initial fitness. */
|
||||
#define CONSTANT_PLAYER_FITNESS_LOWER 85
|
||||
/** Limits for initial fitness. */
|
||||
#define CONSTANT_PLAYER_FITNESS_UPPER 100
|
||||
|
||||
/** The bounds determining the player positions in a newly created
|
||||
team for players 13 to CONSTANT_TEAM_MAX_PLAYERS.
|
||||
Player 11 is always the second goalie. */
|
||||
#define CONSTANT_PLAYER_POS_BOUND1 15
|
||||
#define CONSTANT_PLAYER_POS_BOUND2 17
|
||||
|
||||
/** Bounds for the contract time at player generation. */
|
||||
#define CONSTANT_PLAYER_CONTRACT_LOWER 52
|
||||
#define CONSTANT_PLAYER_CONTRACT_UPPER 4 * 52
|
||||
|
||||
/** Bounds for the last skill update at player generation. */
|
||||
#define CONSTANT_PLAYER_LSU_LOWER 2
|
||||
#define CONSTANT_PLAYER_LSU_UPPER 10
|
||||
|
||||
/** These determine the value calculation of players.
|
||||
Value is a function of skill and talent involving
|
||||
a power.
|
||||
@see player_assign_value()*/
|
||||
#define CONSTANT_PLAYER_VALUE_SKILL_WEIGHT 0.65
|
||||
#define CONSTANT_PLAYER_VALUE_POWER 3.5
|
||||
|
||||
/** These determine the wage calculation of players.
|
||||
Wage depends on the value and a random factor near 1.
|
||||
@see player_assign_wage() */
|
||||
#define CONSTANT_PLAYER_WAGE_VALUE_FACTOR 0.01
|
||||
#define CONSTANT_PLAYER_WAGE_RANDOM_DEV 0.15
|
||||
|
||||
/** This determines the accuracy of the scout's
|
||||
talent estimate. The smaller the better. */
|
||||
#define CONSTANT_PLAYER_ETAL_SCOUT_FACTOR 7
|
||||
|
||||
/** Create and return a new player.
|
||||
@param tm The team the player will belong to.
|
||||
@param average_skill The average skill of the team.
|
||||
The player's skill can deviate from this value by #CONSTANT_PLAYER_AVERAGE_SKILL_VARIANCE %
|
||||
@return A newly created player. */
|
||||
Player
|
||||
player_new(const Team *tm, gint average_skill)
|
||||
{
|
||||
gfloat skill_factor =
|
||||
math_rnd(1 - CONSTANT_PLAYER_AVERAGE_SKILL_VARIANCE,
|
||||
1 + CONSTANT_PLAYER_AVERAGE_SKILL_VARIANCE);
|
||||
Player new;
|
||||
|
||||
new.name =
|
||||
g_string_new(((GString*)g_ptr_array_index(player_names, math_rndi(0, player_names->len - 1)))->str);
|
||||
new.clid = tm->clid;
|
||||
new.team_id = tm->id;
|
||||
new.id = player_new_id(tm->players);
|
||||
new.pos = player_get_position_from_structure(tm->structure, tm->players->len);
|
||||
new.cpos = new.pos;
|
||||
new.skill = CLAMP((gint)rint((gfloat)average_skill * skill_factor), 0, CONSTANT_PLAYER_MAX_SKILL);
|
||||
new.cskill = new.skill;
|
||||
new.age = math_gauss_disti(CONSTANT_PLAYER_AGE_LOWER,
|
||||
CONSTANT_PLAYER_AGE_UPPER);
|
||||
new.peak_age =
|
||||
math_rndi(CONSTANT_PLAYER_PEAK_AGE_LOWER +
|
||||
(new.pos == PLAYER_POS_GOALIE) * CONSTANT_PLAYER_PEAK_AGE_GOALIE_ADDITION,
|
||||
CONSTANT_PLAYER_PEAK_AGE_UPPER +
|
||||
(new.pos == PLAYER_POS_GOALIE) * CONSTANT_PLAYER_PEAK_AGE_GOALIE_ADDITION);
|
||||
new.talent = player_new_talent(new.skill);
|
||||
new.etal = player_estimate_talent(&new);
|
||||
new.fitness = math_rndi(CONSTANT_PLAYER_FITNESS_LOWER, CONSTANT_PLAYER_FITNESS_UPPER);
|
||||
new.health = new.recovery = new.goals = new.games = 0;
|
||||
new.value = player_assign_value(&new);
|
||||
new.wage = player_assign_wage(&new);
|
||||
new.contract = math_rndi(CONSTANT_PLAYER_CONTRACT_LOWER, CONSTANT_PLAYER_CONTRACT_UPPER);
|
||||
new.lsu = math_rndi(CONSTANT_PLAYER_LSU_LOWER, CONSTANT_PLAYER_LSU_UPPER);
|
||||
new.cards = g_array_new(FALSE, FALSE, sizeof(PlayerCard));
|
||||
/* todo: make player history struct. */
|
||||
new.history = NULL;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
/** Return a player id that's not yet 'occupied'.
|
||||
@param players The player array the new player will belong to.
|
||||
@return A new id that none of the other players has. */
|
||||
gint
|
||||
player_new_id(const GArray *players)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
for(i=0;i<CONSTANT_TEAM_MAX_PLAYERS;i++)
|
||||
{
|
||||
for(j=0;j<players->len;j++)
|
||||
if(g_array_index(players, Player, j).id == i)
|
||||
break;
|
||||
|
||||
if(j == players->len)
|
||||
return j;
|
||||
}
|
||||
|
||||
g_warning("player_new_id: didn't find id for a new player.\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Return the appropriate position for the player with the given number.
|
||||
The position depends on the team structure if the player number is < 11
|
||||
and on some constants otherwise.
|
||||
@param structure The team structure, something like 442 or 352.
|
||||
@param player_number The number of the player within the team.
|
||||
@return A new position for the player. */
|
||||
gint
|
||||
player_get_position_from_structure(gint structure, gint player_number)
|
||||
{
|
||||
gint position = -1;
|
||||
gint bound[2] =
|
||||
{math_get_place(structure, 3) + 1,
|
||||
math_get_place(structure, 3) +
|
||||
math_get_place(structure, 2) + 1};
|
||||
|
||||
if(player_number % 11 == 0)
|
||||
position = PLAYER_POS_GOALIE;
|
||||
else if(player_number < bound[0] ||
|
||||
(player_number > 10 && player_number < CONSTANT_PLAYER_POS_BOUND1))
|
||||
position = PLAYER_POS_DEFENDER;
|
||||
else if(player_number < bound[1] ||
|
||||
(player_number > 10 && player_number < CONSTANT_PLAYER_POS_BOUND2))
|
||||
position = PLAYER_POS_MIDFIELDER;
|
||||
else
|
||||
position = PLAYER_POS_FORWARD;
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
/** Calculate the talent value of the player based on his skill.
|
||||
@param skill The player's skill.
|
||||
@return The new talent value. */
|
||||
gint
|
||||
player_new_talent(gint skill)
|
||||
{
|
||||
gint talent = math_gauss_disti(2 * skill - CONSTANT_PLAYER_MAX_SKILL,
|
||||
CONSTANT_PLAYER_MAX_SKILL);
|
||||
if(talent < skill)
|
||||
talent = 2 * skill - talent;
|
||||
|
||||
return talent;
|
||||
}
|
||||
|
||||
/** Estimate a player's talent. The quality of the estimate
|
||||
depends on the quality of the scout.
|
||||
@param pl The player of which we'd like to estimate the talent.
|
||||
@return A talent estimate. */
|
||||
gint
|
||||
player_estimate_talent(const Player *pl)
|
||||
{
|
||||
gint i;
|
||||
|
||||
/* the maximal deviance in both directions */
|
||||
gint deviance_bound[2] =
|
||||
{pl->talent - pl->skill, CONSTANT_PLAYER_MAX_SKILL - pl->talent};
|
||||
|
||||
/* the scout's maximal deviance */
|
||||
gfloat scout_deviance = (scout % 10) * CONSTANT_PLAYER_ETAL_SCOUT_FACTOR;
|
||||
|
||||
/* adjust deviance_bounds with regard to the scout's
|
||||
deviance */
|
||||
for(i=0;i<2;i++)
|
||||
deviance_bound[i] = MIN(deviance_bound[i], scout_deviance);
|
||||
|
||||
return math_rndi(pl->talent - deviance_bound[0],
|
||||
pl->talent + deviance_bound[1]);
|
||||
}
|
||||
|
||||
/** Assign a (transfer) value to a player. The value depends on skill,
|
||||
talent and age.
|
||||
@param pl The player we examine.
|
||||
@return The value of the player. */
|
||||
gint
|
||||
player_assign_value(const Player *pl)
|
||||
{
|
||||
gint value;
|
||||
|
||||
value = (gint)powf((CONSTANT_PLAYER_VALUE_SKILL_WEIGHT * (gfloat)pl->skill
|
||||
+ (1 - CONSTANT_PLAYER_VALUE_SKILL_WEIGHT) * (gfloat)pl->talent * 0.7),
|
||||
CONSTANT_PLAYER_VALUE_POWER);
|
||||
|
||||
if(pl->age <= CONSTANT_PLAYER_AGE_LOWER + 2 * 52)
|
||||
value = (gint)((gfloat)value * 1.05);
|
||||
else if(pl->age <= CONSTANT_PLAYER_AGE_LOWER + 4 * 52)
|
||||
value = (gint)((gfloat)value * 1.1);
|
||||
else if(pl->age >= CONSTANT_PLAYER_AGE_UPPER - 4 * 52)
|
||||
value = (gint)((gfloat)value * 0.95);
|
||||
else if(pl->age >= CONSTANT_PLAYER_AGE_UPPER - 2 * 52)
|
||||
value = (gint)((gfloat)value * 0.9);
|
||||
|
||||
value = math_round_integer(value, 2);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/** Assign a value to a player. The value depends on skill,
|
||||
talent and age.
|
||||
@param pl The player we examine.
|
||||
@return The wage of the player. */
|
||||
gint
|
||||
player_assign_wage(const Player *pl)
|
||||
{
|
||||
gfloat wage;
|
||||
|
||||
wage = rint(((gfloat)pl->value * CONSTANT_PLAYER_WAGE_VALUE_FACTOR) *
|
||||
math_rnd(1 - CONSTANT_PLAYER_WAGE_RANDOM_DEV,
|
||||
1 + CONSTANT_PLAYER_WAGE_RANDOM_DEV) );
|
||||
|
||||
return math_round_integer((gint)wage, 1);
|
||||
}
|
||||
|
||||
/** Copy a player to another player. The destination player
|
||||
has to be a fully allocated player (because he gets
|
||||
freed before we copy).
|
||||
@param source The player we copy.
|
||||
@param dest The player we overwrite. */
|
||||
void
|
||||
player_copy(const Player *source, Player *dest)
|
||||
{
|
||||
gint i;
|
||||
|
||||
free_player(dest);
|
||||
|
||||
*dest = *source;
|
||||
dest->name = g_string_new(source->name->str);
|
||||
dest->cards = g_array_new(FALSE, FALSE, sizeof(PlayerCard));
|
||||
dest->history = NULL;
|
||||
|
||||
for(i=0;i<source->cards->len;i++)
|
||||
g_array_append_val(dest->cards,
|
||||
g_array_index(source->cards, PlayerCard, i));
|
||||
}
|
||||
|
||||
/** Copy a player into a team in a way that allows us to
|
||||
free the player afterwards.
|
||||
@param pl The player we copy.
|
||||
@param tm The team we copy the player to.
|
||||
@see player_copy() */
|
||||
void
|
||||
player_append_to_array(const Player *pl, Team *tm)
|
||||
{
|
||||
Player new_player = player_new(tm, CONSTANT_PLAYER_MAX_SKILL);
|
||||
|
||||
player_copy(pl, &new_player);
|
||||
|
||||
g_array_append_val(tm->players, new_player);
|
||||
}
|
||||
|
|
81
src/player.h
81
src/player.h
|
@ -1,61 +1,38 @@
|
|||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include "variables.h"
|
||||
#include "bygfoot.h"
|
||||
#include "player_struct.h"
|
||||
#include "team_struct.h"
|
||||
|
||||
/**
|
||||
Player attribute indices.
|
||||
*/
|
||||
enum PlayerAttributes
|
||||
{
|
||||
PLAYER_POS = 0, /**< Position. 0 Goalie, 1 Defender, 2 Midfielder, 3 Forward. */
|
||||
PLAYER_CPOS, /**< Current position. */
|
||||
PLAYER_SKILL, /**< Skill. Between 0 and 99. */
|
||||
PLAYER_CSKILL, /**< Current Skill. */
|
||||
PLAYER_AGE, /**< Age in weeks */
|
||||
PLAYER_PEAK_AGE, /**< Age at which the player reaches his peak ability. */
|
||||
PLAYER_TALENT, /**< Talent. The peak ability (which isn't always reached). */
|
||||
PLAYER_ETAL, /**< Estimated talent (the user never sees the actual talent). */
|
||||
PLAYER_FITNESS, /**< Fitness. Between 0 and 99. */
|
||||
PLAYER_HEALTH, /**< Health. An integer signifying an injury or good health. */
|
||||
PLAYER_RECOVERY, /**< Weeks until the player gets healthy. */
|
||||
PLAYER_TEAMID, /**< Id of the player's team. */
|
||||
PLAYER_VALUE, /**< Value of the player. */
|
||||
PLAYER_WAGE, /**< Wage of the player. */
|
||||
PLAYER_LSU, /**< Last skill update. Number of weeks since the player skill was last updated. */
|
||||
PLAYER_GOALS, /**< Number of goals (scored for field players or conceded for goalies). */
|
||||
PLAYER_GAMES, /**< Number of games the player played. */
|
||||
PLAYER_END
|
||||
};
|
||||
/** Highest skill and talent a player can have. */
|
||||
#define CONSTANT_PLAYER_MAX_SKILL 99
|
||||
|
||||
/**
|
||||
Representation of a player.
|
||||
@see #PlayerAttributes
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GString *name;
|
||||
gint values[PLAYER_END];
|
||||
/** Array of cards; one item per league and cup.
|
||||
@see PlayerCard*/
|
||||
GArray *cards;
|
||||
/** Player history. To be specified. */
|
||||
GArray *history;
|
||||
} Player;
|
||||
Player
|
||||
player_new(const Team *tm, gint average_skill);
|
||||
|
||||
/**
|
||||
Cards in different cups are counted separately for players;
|
||||
for each league or cup the cards are stored in such a struct.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Numerical id of the league or cup. */
|
||||
gint league_cup_id;
|
||||
/** Number of yellow cards. */
|
||||
gint yellow;
|
||||
/** Number of weeks the player is banned. */
|
||||
gint red;
|
||||
} PlayerCard;
|
||||
gint
|
||||
player_new_id(const GArray *players);
|
||||
|
||||
gint
|
||||
player_get_position_from_structure(gint structure, gint player_number);
|
||||
|
||||
gint
|
||||
player_new_talent(gint skill);
|
||||
|
||||
gint
|
||||
player_estimate_talent(const Player *pl);
|
||||
|
||||
gint
|
||||
player_assign_value(const Player *pl);
|
||||
|
||||
gint
|
||||
player_assign_wage(const Player *pl);
|
||||
|
||||
void
|
||||
player_copy(const Player *source, Player *dest);
|
||||
|
||||
void
|
||||
player_append_to_array(const Player *pl, Team *tm);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef PLAYER_STRUCT_H
|
||||
#define PLAYER_STRUCT_H
|
||||
|
||||
/**
|
||||
Player attribute indices.
|
||||
*/
|
||||
enum PlayerPos
|
||||
{
|
||||
PLAYER_POS_GOALIE = 0,
|
||||
PLAYER_POS_DEFENDER,
|
||||
PLAYER_POS_MIDFIELDER,
|
||||
PLAYER_POS_FORWARD,
|
||||
PLAYER_POS_END
|
||||
};
|
||||
|
||||
/**
|
||||
Cards in different cups are counted separately for players;
|
||||
for each league or cup the cards are stored in such a struct.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/** Numerical id of the league or cup. */
|
||||
gint league_cup_id;
|
||||
/** Number of yellow cards. */
|
||||
gint yellow;
|
||||
/** Number of weeks the player is banned. */
|
||||
gint red;
|
||||
} PlayerCard;
|
||||
|
||||
/**
|
||||
Representation of a player.
|
||||
@see #PlayerAttributes
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GString *name;
|
||||
|
||||
gint pos, /**< Position. @see #PlayerPos */
|
||||
cpos, /**< Current position. @see #PlayerPos */
|
||||
skill, /**< Skill. Between 0 and CONSTANT_PLAYER_MAX_SKILL. */
|
||||
cskill, /**< Current Skill. */
|
||||
age, /**< Age in weeks */
|
||||
peak_age, /**< Age at which the player reaches his peak ability. */
|
||||
talent, /**< Talent. The peak ability (which isn't always reached). */
|
||||
etal, /**< Estimated talent (the user never sees the actual talent). */
|
||||
fitness, /**< Fitness. Between 0 and 99. */
|
||||
health, /**< Health. An integer signifying an injury or good health. */
|
||||
recovery, /**< Weeks until the player gets healthy. */
|
||||
clid, /**< Cup or league id of the player's team. */
|
||||
team_id, /**< Id of the player's team. */
|
||||
id, /**< Id of the player within the team. */
|
||||
value, /**< Value of the player. */
|
||||
wage, /**< Wage of the player. */
|
||||
contract, /**< The number of weeks until the player's contract expires. */
|
||||
lsu, /**< Last skill update. Number of weeks since the player skill was last updated. */
|
||||
goals, /**< Number of goals (scored for field players or conceded for goalies). */
|
||||
games; /**< Number of games the player played. */
|
||||
|
||||
/** array of cards; one item per league and cup.
|
||||
@see PlayerCard*/
|
||||
GArray *cards;
|
||||
/** Player history. To be specified. */
|
||||
GArray *history;
|
||||
} Player;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,99 @@
|
|||
#include "cup.h"
|
||||
#include "fixture.h"
|
||||
#include "league.h"
|
||||
#include "main.h"
|
||||
#include "maths.h"
|
||||
#include "player.h"
|
||||
#include "start_end.h"
|
||||
#include "team.h"
|
||||
#include "transfer.h"
|
||||
#include "variables.h"
|
||||
#include "xml_name.h"
|
||||
|
||||
|
||||
/** Generate the teams etc. */
|
||||
void
|
||||
start_new_game(void)
|
||||
{
|
||||
start_write_variables();
|
||||
xml_name_read(PLAYER_NAMES_FILE, -1);
|
||||
start_generate_league_teams();
|
||||
start_new_season();
|
||||
xml_name_read(PLAYER_NAMES_FILE, 1000);
|
||||
}
|
||||
|
||||
/** Make new fixtures, nullify things etc. */
|
||||
void
|
||||
start_new_season(void)
|
||||
{
|
||||
start_load_cup_teams();
|
||||
}
|
||||
|
||||
/** Fill some global variables with default values at the
|
||||
beginning of a new game. */
|
||||
void
|
||||
start_write_variables(void)
|
||||
{
|
||||
season = week = week_round = 1;
|
||||
scout = physio = QUALITY_AVERAGE;
|
||||
|
||||
fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture));
|
||||
transfer_list = g_array_new(FALSE, FALSE, sizeof(TransferPlayer));
|
||||
}
|
||||
|
||||
/** Generate the teams in the leagues. */
|
||||
void
|
||||
start_generate_league_teams(void)
|
||||
{
|
||||
gint i, j;
|
||||
Team *tm;
|
||||
|
||||
if(ligs->len == 0)
|
||||
{
|
||||
g_warning("start_generate_league_teams: no leagues found. there must be at least one league in the game.\n");
|
||||
main_exit_program(EXIT_NO_LEAGUES);
|
||||
}
|
||||
|
||||
for(i=0;i<ligs->len;i++)
|
||||
{
|
||||
for(j=0;j<lig(i).teams->len;j++)
|
||||
{
|
||||
tm = &g_array_index(lig(i).teams, Team, j);
|
||||
tm->stadium.capacity =
|
||||
math_gauss_disti((gint)(lig(i).average_capacity * 0.66),
|
||||
(gint)(lig(i).average_capacity * 1.33));
|
||||
|
||||
team_generate_players(tm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Load the names from the xml files for the cups
|
||||
and generate the teams. */
|
||||
void
|
||||
start_load_cup_teams(void)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
for(i=0;i<cps->len;i++)
|
||||
if(cp(i).type == CUP_TYPE_INTERNATIONAL)
|
||||
{
|
||||
cup_load_choose_teams(&cp(i));
|
||||
cup_load_choose_team_user(&cp(i));
|
||||
|
||||
for(j=0;j<cp(i).teams->len;j++)
|
||||
{
|
||||
printf("%d %s clid %d id %d\n", j,
|
||||
g_array_index(cp(i).teams, Team, j).name->str,
|
||||
g_array_index(cp(i).teams, Team, j).clid,
|
||||
g_array_index(cp(i).teams, Team, j).id);
|
||||
printf("%s %d %d\n",
|
||||
g_array_index(g_array_index(cp(i).teams, Team, j).players,
|
||||
Player, 0).name->str,
|
||||
g_array_index(g_array_index(cp(i).teams, Team, j).players,
|
||||
Player, 0).skill,
|
||||
g_array_index(g_array_index(cp(i).teams, Team, j).players,
|
||||
Player, 0).talent);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef START_END_H
|
||||
#define START_END_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
|
||||
void
|
||||
start_new_game(void);
|
||||
|
||||
void
|
||||
start_new_season(void);
|
||||
|
||||
void
|
||||
start_write_variables(void);
|
||||
|
||||
void
|
||||
start_generate_league_teams(void);
|
||||
|
||||
void
|
||||
start_load_cup_teams(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef TABLE_STRUCT_H
|
||||
#define TABLE_STRUCT_H
|
||||
|
||||
/**
|
||||
Table element values.
|
||||
@see TableElement
|
||||
@see Table
|
||||
*/
|
||||
enum TableElementValues
|
||||
{
|
||||
TABLE_PLAYED = 0,
|
||||
TABLE_WON,
|
||||
TABLE_DRAW,
|
||||
TABLE_LOST,
|
||||
TABLE_GF,
|
||||
TABLE_GA,
|
||||
TABLE_PTS,
|
||||
TABLE_END
|
||||
};
|
||||
|
||||
/**
|
||||
An element representing a team in the tables.
|
||||
@see Table
|
||||
@see #TableElementValues
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
gint team_id;
|
||||
gint values[TABLE_END];
|
||||
} TableElement;
|
||||
|
||||
/**
|
||||
A table belonging to a league or a cup with round robin.
|
||||
@see TableElement
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GString *name;
|
||||
gint league_id;
|
||||
GArray *elements;
|
||||
} Table;
|
||||
|
||||
#endif
|
277
src/team.c
277
src/team.c
|
@ -1,38 +1,35 @@
|
|||
#include "cup.h"
|
||||
#include "free.h"
|
||||
#include "league.h"
|
||||
#include "maths.h"
|
||||
#include "player.h"
|
||||
#include "team.h"
|
||||
|
||||
/**
|
||||
Playing styles for teams.
|
||||
@see The match result calculating functions.
|
||||
*/
|
||||
enum TeamPlayingStyle
|
||||
{
|
||||
PLAYING_STYLE_ALL_OUT_DEFEND = -2,
|
||||
PLAYING_STYLE_DEFEND,
|
||||
PLAYING_STYLE_BALANCED,
|
||||
PLAYING_STYLE_ATTACK,
|
||||
PLAYING_STYLE_ALL_OUT_ATTACK,
|
||||
PLAYING_STYLE_END
|
||||
};
|
||||
#include "variables.h"
|
||||
|
||||
/**
|
||||
Constants determining the probabilities for
|
||||
the playing styles of CPU teams.
|
||||
@see team_assign_playing_style().
|
||||
*/
|
||||
#define CONSTANT_PLAYING_STYLE_PROB1 0.1
|
||||
#define CONSTANT_PLAYING_STYLE_PROB2 0.25
|
||||
#define CONSTANT_PLAYING_STYLE_PROB3 0.75
|
||||
#define CONSTANT_PLAYING_STYLE_PROB4 0.9
|
||||
#define CONSTANT_TEAM_PLAYING_STYLE_PROB1 0.1
|
||||
#define CONSTANT_TEAM_PLAYING_STYLE_PROB2 0.25
|
||||
#define CONSTANT_TEAM_PLAYING_STYLE_PROB3 0.75
|
||||
#define CONSTANT_TEAM_PLAYING_STYLE_PROB4 0.9
|
||||
|
||||
/**
|
||||
Constants determining the probabilities for
|
||||
the playing structures of CPU teams.
|
||||
@see team_assign_playing_structure().
|
||||
*/
|
||||
#define CONSTANT_PLAYING_STRUCTURE_PROB1 0.15
|
||||
#define CONSTANT_PLAYING_STRUCTURE_PROB2 0.5
|
||||
#define CONSTANT_PLAYING_STRUCTURE_PROB3 0.7
|
||||
#define CONSTANT_PLAYING_STRUCTURE_PROB4 0.85
|
||||
#define CONSTANT_TEAM_PLAYING_STRUCTURE_PROB1 0.15
|
||||
#define CONSTANT_TEAM_PLAYING_STRUCTURE_PROB2 0.5
|
||||
#define CONSTANT_TEAM_PLAYING_STRUCTURE_PROB3 0.7
|
||||
#define CONSTANT_TEAM_PLAYING_STRUCTURE_PROB4 0.85
|
||||
|
||||
/** Kinda hard to explain.
|
||||
@see team_generate_players()
|
||||
@see player_generate() */
|
||||
#define CONSTANT_TEAM_SKILL_VARIANCE 0.075
|
||||
|
||||
/**
|
||||
Generate a team with default values, e.g.
|
||||
|
@ -46,12 +43,13 @@ team_new(void)
|
|||
Team new;
|
||||
|
||||
new.name = g_string_new("");
|
||||
new.league_cup_id = -1;
|
||||
|
||||
new.nid = -1;
|
||||
new.clid = new.id = -1;
|
||||
new.structure = team_assign_playing_structure();
|
||||
new.style = team_assign_playing_style();
|
||||
|
||||
new.stadium = team_stadium_new();
|
||||
|
||||
new.players = g_array_new(FALSE, FALSE, sizeof(Player));
|
||||
|
||||
return new;
|
||||
|
@ -60,26 +58,26 @@ team_new(void)
|
|||
/**
|
||||
Return a random playing style.
|
||||
@see The #TeamPlayingStyle enumeration.
|
||||
@see The #CONSTANT_PLAYING_STYLE_PROB1 define.
|
||||
@see The #CONSTANT_TEAM_PLAYING_STYLE_PROB1 define.
|
||||
*/
|
||||
gint
|
||||
team_assign_playing_style(void)
|
||||
{
|
||||
gfloat rndom;
|
||||
|
||||
rndom = rnd(0,1);
|
||||
rndom = math_rnd(0,1);
|
||||
|
||||
/* all out defend */
|
||||
if(rndom < CONSTANT_PLAYING_STYLE_PROB1)
|
||||
if(rndom < CONSTANT_TEAM_PLAYING_STYLE_PROB1)
|
||||
return -2;
|
||||
/* defend */
|
||||
else if(rndom < CONSTANT_PLAYING_STYLE_PROB2)
|
||||
else if(rndom < CONSTANT_TEAM_PLAYING_STYLE_PROB2)
|
||||
return -1;
|
||||
/* balanced */
|
||||
else if(rndom < CONSTANT_PLAYING_STYLE_PROB3)
|
||||
else if(rndom < CONSTANT_TEAM_PLAYING_STYLE_PROB3)
|
||||
return 0;
|
||||
/* attack */
|
||||
else if(rndom < CONSTANT_PLAYING_STYLE_PROB4)
|
||||
else if(rndom < CONSTANT_TEAM_PLAYING_STYLE_PROB4)
|
||||
return 1;
|
||||
|
||||
/* all out attack */
|
||||
|
@ -88,21 +86,228 @@ team_assign_playing_style(void)
|
|||
|
||||
/**
|
||||
Return a random playing structure.
|
||||
@see The #CONSTANT_PLAYING_STRUCTURE_PROB1 define.
|
||||
@see The #CONSTANT_TEAM_PLAYING_STRUCTURE_PROB1 define.
|
||||
*/
|
||||
gint
|
||||
team_assign_playing_structure(void)
|
||||
{
|
||||
gfloat rndom = rnd(0,1);
|
||||
gfloat rndom = math_rnd(0,1);
|
||||
|
||||
if(rndom < CONSTANT_PLAYING_STRUCTURE_PROB1)
|
||||
if(rndom < CONSTANT_TEAM_PLAYING_STRUCTURE_PROB1)
|
||||
return 532;
|
||||
else if(rndom < CONSTANT_PLAYING_STRUCTURE_PROB2)
|
||||
else if(rndom < CONSTANT_TEAM_PLAYING_STRUCTURE_PROB2)
|
||||
return 442;
|
||||
else if(rndom < CONSTANT_PLAYING_STRUCTURE_PROB3)
|
||||
else if(rndom < CONSTANT_TEAM_PLAYING_STRUCTURE_PROB3)
|
||||
return 352;
|
||||
else if(rndom < CONSTANT_PLAYING_STRUCTURE_PROB4)
|
||||
else if(rndom < CONSTANT_TEAM_PLAYING_STRUCTURE_PROB4)
|
||||
return 433;
|
||||
|
||||
return 343;
|
||||
}
|
||||
|
||||
/** Return a stadium struct with default values. */
|
||||
Stadium
|
||||
team_stadium_new(void)
|
||||
{
|
||||
Stadium new;
|
||||
|
||||
new.capacity = -1;
|
||||
new.safety = math_gauss_disti(80, 100);
|
||||
new.average_attendance =
|
||||
new.possible_attendance =
|
||||
new.games = 0;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
/** Decide whether the team specified is the user's team.
|
||||
@param tm The team we check
|
||||
@return TRUE if the team is the user's team, FALSE otherwise. */
|
||||
gboolean
|
||||
is_my_team(const Team *tm)
|
||||
{
|
||||
return (tm->clid == my_team_clid && tm->id == my_team_id);
|
||||
}
|
||||
|
||||
/* Fill the players array of the team.
|
||||
@param tm The team that gets filled. */
|
||||
void
|
||||
team_generate_players(Team *tm)
|
||||
{
|
||||
/*d*/
|
||||
Player pl;
|
||||
gint i;
|
||||
gfloat skill_factor = math_rnd(1 - CONSTANT_TEAM_SKILL_VARIANCE,
|
||||
1 + CONSTANT_TEAM_SKILL_VARIANCE);
|
||||
Player new;
|
||||
gint average_skill;
|
||||
|
||||
if(tm->clid < ID_CUP_START)
|
||||
average_skill =
|
||||
(gint)rint((gfloat)team_return_league_cup_value_int(tm, LEAGUE_CUP_VALUE_AVERAGE_SKILL) *
|
||||
skill_factor);
|
||||
else
|
||||
average_skill =
|
||||
(gint)rint((gfloat)lig(0).average_skill +
|
||||
(gfloat)team_return_league_cup_value_int(tm, LEAGUE_CUP_VALUE_SKILL_DIFF)) *
|
||||
skill_factor;
|
||||
|
||||
average_skill = CLAMP(average_skill, 0, CONSTANT_PLAYER_MAX_SKILL);
|
||||
|
||||
for(i=0;i<CONSTANT_TEAM_MAX_PLAYERS;i++)
|
||||
{
|
||||
new = player_new(tm, average_skill);
|
||||
g_array_append_val(tm->players, new);
|
||||
}
|
||||
|
||||
/*d*/
|
||||
/* if(tm->id == 0) */
|
||||
/* { */
|
||||
/* printf("%s %p\n\n", tm->name->str, tm); */
|
||||
/* for(i=0;i<tm->players->len;i++) */
|
||||
/* { */
|
||||
/* pl = g_array_index(tm->players, Player, i); */
|
||||
/* printf("%d %s sk %d tal %d etal %d\n", i, */
|
||||
/* pl.name->str, pl.skill, pl.talent, pl.etal); */
|
||||
/* printf("fit %d val %d wag %d con %.1f lsu %d goa %d gam %d\n", */
|
||||
/* pl.fitness, pl.value, */
|
||||
/* pl.wage, (gfloat)pl.contract / 52, pl.lsu, pl.goals, pl.games); */
|
||||
/* } */
|
||||
/* printf("\n");printf("\n"); */
|
||||
/* } */
|
||||
}
|
||||
|
||||
/** Return a certain value from the league or cup struct
|
||||
the team belongs to.
|
||||
@param tm The team we examine.
|
||||
@param value_type This tells us which value to return.
|
||||
@see #LeagueCupValue */
|
||||
gint
|
||||
team_return_league_cup_value_int(const Team *tm, gint value_type)
|
||||
{
|
||||
gint idx = tm->clid % 1000;
|
||||
|
||||
if(tm->clid >= ID_CUP_START)
|
||||
switch(value_type)
|
||||
{
|
||||
case LEAGUE_CUP_VALUE_ID:
|
||||
return cp(idx).id;
|
||||
case LEAGUE_CUP_VALUE_LAST_WEEK:
|
||||
return cp(idx).last_week;
|
||||
case LEAGUE_CUP_VALUE_WEEK_GAP:
|
||||
return cp(idx).week_gap;
|
||||
case LEAGUE_CUP_VALUE_YELLOW_RED:
|
||||
return cp(idx).yellow_red;
|
||||
case LEAGUE_CUP_VALUE_AVERAGE_CAPACITY:
|
||||
return cp(idx).average_capacity;
|
||||
case LEAGUE_CUP_VALUE_CUP_TYPE:
|
||||
return cp(idx).type;
|
||||
case LEAGUE_CUP_VALUE_SKILL_DIFF:
|
||||
return cp(idx).skill_diff;
|
||||
default:
|
||||
g_warning("team_return_league_cup_value_int: unknown value_type for cups: %d\n",
|
||||
value_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch(value_type)
|
||||
{
|
||||
case LEAGUE_CUP_VALUE_ID:
|
||||
return lig(idx).id;
|
||||
case LEAGUE_CUP_VALUE_FIRST_WEEK:
|
||||
return lig(idx).first_week;
|
||||
case LEAGUE_CUP_VALUE_WEEK_GAP:
|
||||
return lig(idx).week_gap;
|
||||
case LEAGUE_CUP_VALUE_YELLOW_RED:
|
||||
return lig(idx).yellow_red;
|
||||
case LEAGUE_CUP_VALUE_AVERAGE_SKILL:
|
||||
return lig(idx).average_skill;
|
||||
case LEAGUE_CUP_VALUE_AVERAGE_CAPACITY:
|
||||
return lig(idx).average_capacity;
|
||||
default:
|
||||
g_warning("team_return_league_cup_value_int: unknown value_type for leagues: %d\n",
|
||||
value_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Copy a team to another team. The destination team
|
||||
has to be a fully allocated team (because it gets
|
||||
freed before we copy).
|
||||
@param source The team we copy.
|
||||
@param dest The team we overwrite. */
|
||||
void
|
||||
team_copy(const Team *source, Team *dest)
|
||||
{
|
||||
gint i;
|
||||
Player new_player;
|
||||
|
||||
free_team(dest);
|
||||
|
||||
*dest = *source;
|
||||
|
||||
dest->name = g_string_new(source->name->str);
|
||||
|
||||
dest->players = g_array_new(FALSE, FALSE, sizeof(Player));
|
||||
|
||||
for(i=0;i<source->players->len;i++)
|
||||
{
|
||||
new_player = player_new(dest, CONSTANT_PLAYER_MAX_SKILL);
|
||||
free_player(&new_player);
|
||||
player_copy(&g_array_index(source->players, Player, i),
|
||||
&new_player);
|
||||
g_array_append_val(dest->players, new_player);
|
||||
}
|
||||
}
|
||||
|
||||
/** Copy a team to an array in a way that allows us to
|
||||
free the team afterwards.
|
||||
@param tm The team we copy.
|
||||
@param teams_array The array of teams we copy the team to.
|
||||
@see team_copy() */
|
||||
void
|
||||
team_append_to_array(const Team *tm, GArray *teams_array)
|
||||
{
|
||||
Team new_team = team_new();
|
||||
|
||||
team_copy(tm, &new_team);
|
||||
|
||||
g_array_append_val(teams_array, new_team);
|
||||
}
|
||||
|
||||
/** Copy a team to an array and assign new ids.
|
||||
@param tm The team we copy.
|
||||
@param teams_array The array of teams we copy the team to.
|
||||
@param clid The cup/league id we assign.
|
||||
@param id The team id we assign.
|
||||
*/
|
||||
void
|
||||
team_append_to_array_with_ids(const Team *tm, GArray *teams_array, gint clid, gint id)
|
||||
{
|
||||
team_append_to_array(tm, teams_array);
|
||||
|
||||
g_array_index(teams_array, Team, teams_array->len - 1).clid = clid;
|
||||
g_array_index(teams_array, Team, teams_array->len - 1).id = id;
|
||||
}
|
||||
|
||||
/** Check whether the team is already part of an
|
||||
international cup. We'd like to avoid having Real Madrid
|
||||
both in the Champions' League and in the CWC.
|
||||
@param tm The team we check (by comparing names).
|
||||
@return TRUE if the team's already participating in a cup,
|
||||
FALSE otherwise. */
|
||||
gboolean
|
||||
is_in_international_cups(const Team *tm)
|
||||
{
|
||||
gint i, j;
|
||||
|
||||
for(i=0;i<cps->len;i++)
|
||||
for(j=0;j<cp(i).teams->len;j++)
|
||||
if(cp(i).type == CUP_TYPE_INTERNATIONAL &&
|
||||
strcmp(tm->name->str, g_array_index(cp(i).teams, Team, j).name->str) == 0)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
|
55
src/team.h
55
src/team.h
|
@ -2,35 +2,10 @@
|
|||
#define TEAM_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "maths.h"
|
||||
#include "player.h"
|
||||
#include "team_struct.h"
|
||||
|
||||
/**
|
||||
Structure representing a team.
|
||||
@see Player
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
GString *name;
|
||||
/**
|
||||
Numerical id of the league or cup the team belongs to.
|
||||
*/
|
||||
gint league_cup_id;
|
||||
|
||||
|
||||
gint nid, /**< Id of the team. */
|
||||
structure, /**< Playing structure. @see team_assign_playing_structure() */
|
||||
style; /**< Playing style. @see team_assign_playing_style() */
|
||||
|
||||
/* i'm not sure whether we should not have only one global
|
||||
variable 'stadium' representing the stadium of the user's team.
|
||||
cpu teams don't really need a stadium */
|
||||
/* Stadium stadium; */
|
||||
/**
|
||||
Array of players.
|
||||
*/
|
||||
GArray *players;
|
||||
} Team;
|
||||
/** Maximum number of players in a team. */
|
||||
#define CONSTANT_TEAM_MAX_PLAYERS 20
|
||||
|
||||
Team
|
||||
team_new(void);
|
||||
|
@ -41,4 +16,28 @@ team_assign_playing_structure(void);
|
|||
gint
|
||||
team_assign_playing_style(void);
|
||||
|
||||
Stadium
|
||||
team_stadium_new(void);
|
||||
|
||||
gboolean
|
||||
is_my_team(const Team *tm);
|
||||
|
||||
void
|
||||
team_generate_players(Team *tm);
|
||||
|
||||
gint
|
||||
team_return_league_cup_value_int(const Team *tm, gint value_type);
|
||||
|
||||
void
|
||||
team_copy(const Team *source, Team *dest);
|
||||
|
||||
void
|
||||
team_append_to_array(const Team *tm, GArray *teams_array);
|
||||
|
||||
void
|
||||
team_append_to_array_with_ids(const Team *tm, GArray *teams_array, gint clid, gint id);
|
||||
|
||||
gboolean
|
||||
is_in_international_cups(const Team *tm);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
#ifndef TEAM_STRUCT_H
|
||||
#define TEAM_STRUCT_H
|
||||
|
||||
/**
|
||||
Playing styles for teams.
|
||||
@see The match result calculating functions.
|
||||
*/
|
||||
enum TeamPlayingStyle
|
||||
{
|
||||
PLAYING_STYLE_ALL_OUT_DEFEND = -2,
|
||||
PLAYING_STYLE_DEFEND,
|
||||
PLAYING_STYLE_BALANCED,
|
||||
PLAYING_STYLE_ATTACK,
|
||||
PLAYING_STYLE_ALL_OUT_ATTACK,
|
||||
PLAYING_STYLE_END
|
||||
};
|
||||
|
||||
/** @see team_return_league_cup_value_int() */
|
||||
enum LeagueCupValue
|
||||
{
|
||||
LEAGUE_CUP_VALUE_NAME = 0,
|
||||
LEAGUE_CUP_VALUE_SHORT_NAME,
|
||||
LEAGUE_CUP_VALUE_SID,
|
||||
LEAGUE_CUP_VALUE_SYMBOL,
|
||||
LEAGUE_CUP_VALUE_ID,
|
||||
LEAGUE_CUP_VALUE_FIRST_WEEK,
|
||||
LEAGUE_CUP_VALUE_LAST_WEEK,
|
||||
LEAGUE_CUP_VALUE_WEEK_GAP,
|
||||
LEAGUE_CUP_VALUE_YELLOW_RED,
|
||||
LEAGUE_CUP_VALUE_AVERAGE_SKILL,
|
||||
LEAGUE_CUP_VALUE_AVERAGE_CAPACITY,
|
||||
LEAGUE_CUP_VALUE_CUP_TYPE,
|
||||
LEAGUE_CUP_VALUE_SKILL_DIFF,
|
||||
LEAGUE_CUP_VALUE_END
|
||||
};
|
||||
|
||||
/** The stadium of a team. */
|
||||
typedef struct
|
||||
{
|
||||
gint capacity, /**< How many people fit in. Default: -1 (depends on league). */
|
||||
safety, /**< Safety percentage between 0 and 100. Default: randomized. */
|
||||
average_attendance, /**< How many people watched on average. Default: 0. */
|
||||
possible_attendance, /**< How many people would've watched if every game had been
|
||||
sold out. We need this only to compute the average attendance in percentage
|
||||
of the capacity. Default: 0. */
|
||||
games; /**< Number of games. Default: 0. */
|
||||
} Stadium;
|
||||
|
||||
/** Structure representing a team.
|
||||
@see Player */
|
||||
typedef struct
|
||||
{
|
||||
GString *name;
|
||||
|
||||
gint clid, /**< Numerical id of the league or cup the team belongs to. */
|
||||
id, /**< Id of the team. */
|
||||
structure, /**< Playing structure. @see team_assign_playing_structure() */
|
||||
style; /**< Playing style. @see team_assign_playing_style() */
|
||||
|
||||
Stadium stadium;
|
||||
/**
|
||||
Array of players.
|
||||
*/
|
||||
GArray *players;
|
||||
} Team;
|
||||
|
||||
#endif
|
|
@ -0,0 +1 @@
|
|||
#include "transfer.h"
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef TRANSFER_H
|
||||
#define TRANSFER_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "team.h"
|
||||
|
||||
#define CONSTANT_TRANSFER_MAX_PLAYERS 20
|
||||
#define CONSTANT_TRANSFER_DEADLINE 35
|
||||
|
||||
/** Structure representing a player on the transfer list. */
|
||||
typedef struct
|
||||
{
|
||||
/** Cup or league id, team id, player id.*/
|
||||
gint clid, team_nid, id;
|
||||
/** Estimated wage and value. */
|
||||
gint ewage, evalue;
|
||||
/** Time until player gets removed from the list. */
|
||||
gint time;
|
||||
} TransferPlayer;
|
||||
|
||||
#endif
|
|
@ -1,4 +1,33 @@
|
|||
#include "gui.h"
|
||||
#include "league.h"
|
||||
#include "support.h"
|
||||
#include "team.h"
|
||||
#include "treeview.h"
|
||||
#include "variables.h"
|
||||
|
||||
|
||||
/** Return the number in the 'column'th column of the currently
|
||||
selected row of the treeview.
|
||||
@param treeview The treeview argument.
|
||||
@param column The column we'd like to get the contents of.
|
||||
@return The number in the given column of the selected row.
|
||||
*/
|
||||
gint
|
||||
treeview_get_index(GtkTreeView *treeview, gint column)
|
||||
{
|
||||
gint value;
|
||||
GtkTreeSelection *selection =
|
||||
gtk_tree_view_get_selection(treeview);
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
|
||||
gtk_tree_selection_get_selected(selection, &model, &iter);
|
||||
|
||||
gtk_tree_model_get(model, &iter, column,
|
||||
&value, -1);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all columns from a GTK treeview. I didn't find a better way
|
||||
|
@ -41,14 +70,15 @@ treeview_clear(GtkTreeView *treeview)
|
|||
GtkTreeModel*
|
||||
treeview_create_team_selection_list(gboolean show_cup_teams)
|
||||
{
|
||||
gint i, j, counter = 1;
|
||||
gint i, j;
|
||||
GtkListStore *liststore;
|
||||
GtkTreeIter iter;
|
||||
|
||||
liststore = gtk_list_store_new(3,
|
||||
liststore = gtk_list_store_new(4,
|
||||
G_TYPE_INT,
|
||||
G_TYPE_INT,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING);
|
||||
G_TYPE_STRING);
|
||||
|
||||
for(i=0;i<ligs->len;i++)
|
||||
{
|
||||
|
@ -56,9 +86,10 @@ treeview_create_team_selection_list(gboolean show_cup_teams)
|
|||
{
|
||||
gtk_list_store_append(liststore, &iter);
|
||||
gtk_list_store_set(liststore, &iter,
|
||||
0, counter++,
|
||||
1, g_array_index(lig(i).teams, Team, j).name->str,
|
||||
2, lig(i).name->str,
|
||||
0, lig(i).id,
|
||||
1, g_array_index(lig(i).teams, Team, j).id,
|
||||
2, g_array_index(lig(i).teams, Team, j).name->str,
|
||||
3, lig(i).name->str,
|
||||
-1);
|
||||
}
|
||||
}
|
||||
|
@ -83,8 +114,9 @@ treeview_set_up_team_selection_treeview (GtkTreeView *treeview)
|
|||
|
||||
gtk_tree_view_set_rules_hint(treeview, TRUE);
|
||||
|
||||
/* number the teams */
|
||||
/* League id column */
|
||||
col = gtk_tree_view_column_new();
|
||||
gtk_tree_view_column_set_title(col, _("LID"));
|
||||
gtk_tree_view_append_column(treeview, col);
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
||||
|
@ -93,9 +125,9 @@ treeview_set_up_team_selection_treeview (GtkTreeView *treeview)
|
|||
if(strcmp(font_name->str, "0") != 0)
|
||||
g_object_set(renderer, "font", font_name->str, NULL);
|
||||
|
||||
/* set up team name column */
|
||||
/* Team id column */
|
||||
col = gtk_tree_view_column_new();
|
||||
gtk_tree_view_column_set_title(col, _("Team"));
|
||||
gtk_tree_view_column_set_title(col, _("TID"));
|
||||
gtk_tree_view_append_column(treeview, col);
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
||||
|
@ -104,14 +136,25 @@ treeview_set_up_team_selection_treeview (GtkTreeView *treeview)
|
|||
if(strcmp(font_name->str, "0") != 0)
|
||||
g_object_set(renderer, "font", font_name->str, NULL);
|
||||
|
||||
/* league column */
|
||||
/* Team name column */
|
||||
col = gtk_tree_view_column_new();
|
||||
gtk_tree_view_column_set_title(col, _("League"));
|
||||
gtk_tree_view_column_set_title(col, _("Team name"));
|
||||
gtk_tree_view_append_column(treeview, col);
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
||||
gtk_tree_view_column_add_attribute(col, renderer,
|
||||
"text", 2);
|
||||
if(strcmp(font_name->str, "0") != 0)
|
||||
g_object_set(renderer, "font", font_name->str, NULL);
|
||||
|
||||
/* league column */
|
||||
col = gtk_tree_view_column_new();
|
||||
gtk_tree_view_column_set_title(col, _("League name"));
|
||||
gtk_tree_view_append_column(treeview, col);
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
gtk_tree_view_column_pack_start(col, renderer, TRUE);
|
||||
gtk_tree_view_column_add_attribute(col, renderer,
|
||||
"text", 3);
|
||||
}
|
||||
|
||||
/** Shows the list of teams in the game.
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
#define TREEVIEW_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "gui.h"
|
||||
#include "league.h"
|
||||
#include "team.h"
|
||||
#include "variables.h"
|
||||
|
||||
gint
|
||||
treeview_get_index(GtkTreeView *treeview, gint column);
|
||||
|
||||
void
|
||||
treeview_clear(GtkTreeView *treeview);
|
||||
|
|
|
@ -2,6 +2,39 @@
|
|||
|
||||
/**
|
||||
* The main variable of the game.
|
||||
* @see _Country
|
||||
* @see Country
|
||||
*/
|
||||
Country country;
|
||||
|
||||
/** The id of the league or cup of the user's team and its numerical id. */
|
||||
gint my_team_clid, my_team_id;
|
||||
|
||||
/** The season, week and week round numbers.
|
||||
We keep track of the time in the game with these variables. */
|
||||
gint season, week, week_round;
|
||||
|
||||
/** The user's scout and physio qualities.
|
||||
@see #Quality */
|
||||
gint scout, physio;
|
||||
|
||||
/** The array containing the fixtures.
|
||||
@see Fixture */
|
||||
GArray *fixtures;
|
||||
|
||||
/** The array containing players to be transfered.
|
||||
@see TransferPlayer */
|
||||
GArray *transfer_list;
|
||||
|
||||
/** The font used in treeviews. */
|
||||
GString *font_name;
|
||||
|
||||
/** An array of player names that we keep in memory. */
|
||||
GPtrArray *player_names;
|
||||
|
||||
/** The pointer to the main window of the game. */
|
||||
GtkWidget *main_window;
|
||||
|
||||
/** All the open windows in the game.
|
||||
@see window_create()
|
||||
@see window_destroy() */
|
||||
GList *windows;
|
||||
|
|
55
src/window.c
55
src/window.c
|
@ -1,4 +1,19 @@
|
|||
#include "window.h"
|
||||
#include "interface.h"
|
||||
#include "main.h"
|
||||
#include "misc_interface.h"
|
||||
#include "file.h"
|
||||
#include "free.h"
|
||||
#include "support.h"
|
||||
|
||||
/** These are used to keep track of open windows.
|
||||
@see window_create() */
|
||||
enum Windows
|
||||
{
|
||||
WINDOW_MAIN = 0,
|
||||
WINDOW_STARTUP,
|
||||
WINDOW_END
|
||||
};
|
||||
|
||||
/**
|
||||
Show the country selection window. All files with prefix
|
||||
|
@ -8,7 +23,7 @@ void
|
|||
window_show_startup(void)
|
||||
{
|
||||
GtkWidget *window_startup =
|
||||
create_window_startup();
|
||||
window_create(WINDOW_STARTUP);
|
||||
GtkWidget *combo_country =
|
||||
lookup_widget(window_startup, "combo_country");
|
||||
gchar country_dir[SMALL];
|
||||
|
@ -16,16 +31,12 @@ window_show_startup(void)
|
|||
GList *combo_strings = NULL;
|
||||
gint i;
|
||||
|
||||
set_version(window_startup);
|
||||
|
||||
sprintf(country_dir, "%s/.bygfoot/definitions/", g_get_home_dir());
|
||||
|
||||
dir_contents = file_dir_get_contents((const gchar*)country_dir, "country_");
|
||||
|
||||
if(dir_contents == NULL)
|
||||
{
|
||||
exit(EXIT_DIR_OPEN);
|
||||
}
|
||||
main_exit_program(EXIT_DIR_OPEN_FAILED);
|
||||
|
||||
for(i=0;i<dir_contents->len;i++)
|
||||
combo_strings = g_list_append(combo_strings,
|
||||
|
@ -33,16 +44,14 @@ window_show_startup(void)
|
|||
|
||||
gtk_combo_set_popdown_strings(GTK_COMBO(combo_country), combo_strings);
|
||||
|
||||
file_dir_free_contents(dir_contents);
|
||||
|
||||
gtk_widget_show(window_startup);
|
||||
free_g_string_array(&dir_contents);
|
||||
}
|
||||
|
||||
/** Set 'Bygfoot x.y.z' into the title of a window.
|
||||
@param window The window widget pointer.
|
||||
@see #VERS */
|
||||
GtkWidget*
|
||||
set_version(GtkWidget *window)
|
||||
window_set_version(GtkWidget *window)
|
||||
{
|
||||
gchar buf[SMALL];
|
||||
|
||||
|
@ -52,3 +61,29 @@ set_version(GtkWidget *window)
|
|||
return window;
|
||||
}
|
||||
|
||||
/** Create and show a window. Which one depends on the argument.
|
||||
@param window_type An integer telling us which window to
|
||||
create.
|
||||
@return The pointer to the new window.
|
||||
@see #Windows */
|
||||
GtkWidget*
|
||||
window_create(gint window_type)
|
||||
{
|
||||
GtkWidget *window = NULL;
|
||||
|
||||
switch(window_type)
|
||||
{
|
||||
default:
|
||||
window = create_main_window();
|
||||
window_set_version(window);
|
||||
break;
|
||||
case WINDOW_STARTUP:
|
||||
window = create_window_startup();
|
||||
window_set_version(window);
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_widget_show(window);
|
||||
|
||||
return window;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,14 @@
|
|||
#define WINDOW_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "misc_interface.h"
|
||||
#include "file.h"
|
||||
#include "support.h"
|
||||
#include "window.h"
|
||||
|
||||
void
|
||||
window_show_startup(void);
|
||||
|
||||
GtkWidget*
|
||||
set_version(GtkWidget *window);
|
||||
window_set_version(GtkWidget *window);
|
||||
|
||||
GtkWidget*
|
||||
window_create(gint window_type);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
#include "file.h"
|
||||
#include "free.h"
|
||||
#include "league.h"
|
||||
#include "misc.h"
|
||||
#include "variables.h"
|
||||
#include "xml_cup.h"
|
||||
#include "xml_country.h"
|
||||
#include "xml_league.h"
|
||||
|
||||
/**
|
||||
* The tags used in the XML files defining countries.
|
||||
|
@ -6,7 +13,7 @@
|
|||
#define TAG_COUNTRY "country"
|
||||
#define TAG_NAME "name"
|
||||
#define TAG_SYMBOL "symbol"
|
||||
#define TAG_ID "id"
|
||||
#define TAG_SID "sid"
|
||||
#define TAG_LEAGUES "leagues"
|
||||
#define TAG_LEAGUE "league"
|
||||
#define TAG_CUPS "cups"
|
||||
|
@ -20,7 +27,7 @@ enum XmlCountryStates
|
|||
STATE_COUNTRY = 0,
|
||||
STATE_NAME,
|
||||
STATE_SYMBOL,
|
||||
STATE_ID,
|
||||
STATE_SID,
|
||||
STATE_LEAGUES,
|
||||
STATE_LEAGUE,
|
||||
STATE_CUPS,
|
||||
|
@ -51,8 +58,8 @@ xml_country_read_start_element (GMarkupParseContext *context,
|
|||
state = STATE_NAME;
|
||||
else if(strcmp(element_name, TAG_SYMBOL) == 0)
|
||||
state = STATE_SYMBOL;
|
||||
else if(strcmp(element_name, TAG_ID) == 0)
|
||||
state = STATE_ID;
|
||||
else if(strcmp(element_name, TAG_SID) == 0)
|
||||
state = STATE_SID;
|
||||
else if(strcmp(element_name, TAG_LEAGUES) == 0)
|
||||
{
|
||||
state = STATE_LEAGUES;
|
||||
|
@ -64,8 +71,8 @@ xml_country_read_start_element (GMarkupParseContext *context,
|
|||
else if(strcmp(element_name, TAG_CUPS) == 0)
|
||||
{
|
||||
state = STATE_CUPS;
|
||||
/* if(cups == NULL) */
|
||||
/* cups = g_array_new(FALSE, FALSE, sizeof(Cup)); */
|
||||
if(cps == NULL)
|
||||
cps = g_array_new(FALSE, FALSE, sizeof(Cup));
|
||||
}
|
||||
else if(strcmp(element_name, TAG_CUP) == 0)
|
||||
state = STATE_CUP;
|
||||
|
@ -88,7 +95,7 @@ xml_country_read_end_element (GMarkupParseContext *context,
|
|||
{
|
||||
if(strcmp(element_name, TAG_NAME) == 0 ||
|
||||
strcmp(element_name, TAG_SYMBOL) == 0 ||
|
||||
strcmp(element_name, TAG_ID) == 0 ||
|
||||
strcmp(element_name, TAG_SID) == 0 ||
|
||||
strcmp(element_name, TAG_LEAGUES) == 0 ||
|
||||
strcmp(element_name, TAG_CUPS) == 0)
|
||||
state = STATE_COUNTRY;
|
||||
|
@ -124,12 +131,12 @@ xml_country_read_text (GMarkupParseContext *context,
|
|||
country.name = g_string_new(buf);
|
||||
else if(state == STATE_SYMBOL)
|
||||
country.symbol = g_string_new(buf);
|
||||
else if(state == STATE_ID)
|
||||
country.id = g_string_new(buf);
|
||||
else if(state == STATE_SID)
|
||||
country.sid = g_string_new(buf);
|
||||
else if(state == STATE_LEAGUE)
|
||||
xml_league_read(buf);
|
||||
xml_league_read(buf, ligs);
|
||||
else if(state == STATE_CUP)
|
||||
xml_cup_read(buf);
|
||||
xml_cup_read(buf, cps);
|
||||
}
|
||||
|
||||
|
||||
|
@ -144,7 +151,7 @@ xml_country_read_text (GMarkupParseContext *context,
|
|||
void
|
||||
xml_country_read(const gchar *country_name)
|
||||
{
|
||||
gchar *file_name = find_support_file(country_name);
|
||||
gchar *file_name = file_find_support_file(country_name);
|
||||
GMarkupParser parser = {xml_country_read_start_element,
|
||||
xml_country_read_end_element,
|
||||
xml_country_read_text, NULL, NULL};
|
||||
|
@ -160,7 +167,7 @@ xml_country_read(const gchar *country_name)
|
|||
if(file_name == NULL)
|
||||
{
|
||||
sprintf(buf, "country_%s.xml", country_name);
|
||||
file_name = find_support_file(buf);
|
||||
file_name = file_find_support_file(buf);
|
||||
}
|
||||
|
||||
if(!g_file_get_contents(file_name, &file_contents, &length, &error))
|
||||
|
|
|
@ -2,13 +2,6 @@
|
|||
#define XML_COUNTRY_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "free.h"
|
||||
#include "gui.h"
|
||||
#include "league.h"
|
||||
#include "misc.h"
|
||||
#include "variables.h"
|
||||
#include "xml_cup.h"
|
||||
#include "xml_league.h"
|
||||
|
||||
GPtrArray*
|
||||
xml_country_get_team_names(const gchar *country_name);
|
||||
|
|
263
src/xml_cup.c
263
src/xml_cup.c
|
@ -1,3 +1,7 @@
|
|||
#include "cup.h"
|
||||
#include "file.h"
|
||||
#include "misc.h"
|
||||
#include "variables.h"
|
||||
#include "xml_cup.h"
|
||||
|
||||
|
||||
|
@ -8,23 +12,24 @@
|
|||
#define TAG_NAME "name"
|
||||
#define TAG_SHORT_NAME "short_name"
|
||||
#define TAG_SYMBOL "symbol"
|
||||
#define TAG_ID "id"
|
||||
#define TAG_SID "sid"
|
||||
#define TAG_TYPE "type"
|
||||
#define TAG_LAST_WEEK "last_week"
|
||||
#define TAG_WEEK_GAP "week_gap"
|
||||
#define TAG_YELLOW_RED "yellow_red"
|
||||
#define TAG_SKILL_DIFF "skill_diff"
|
||||
#define TAG_AVERAGE_STADIUM_CAPACITY "average_stadium_capacity"
|
||||
#define TAG_CUP_ROUNDS "cup_rounds"
|
||||
#define TAG_CUP_ROUND "cup_round"
|
||||
#define TAG_CUP_ROUND_HOME_AWAY "home_away"
|
||||
#define TAG_CUP_ROUND_REPLAY "replay"
|
||||
#define TAG_CUP_ROUND_NEUTRAL "neutral"
|
||||
#define TAG_CUP_ROUND_ROUND_ROBIN "round_robin"
|
||||
#define TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS "number_of_groups"
|
||||
#define TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE "number_of_advance"
|
||||
#define TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE "number_of_best_advance"
|
||||
#define TAG_CHOOSE_TEAMS "choose_teams"
|
||||
#define TAG_CHOOSE_TEAM "choose_team"
|
||||
#define TAG_CHOOSE_TEAM_ID "choose_team_id"
|
||||
#define TAG_CHOOSE_TEAM_SID "choose_team_sid"
|
||||
#define TAG_CHOOSE_TEAM_NUMBER_OF_TEAMS "number_of_teams"
|
||||
#define TAG_CHOOSE_TEAM_START_IDX "start_idx"
|
||||
#define TAG_CHOOSE_TEAM_END_IDX "end_idx"
|
||||
|
@ -37,13 +42,52 @@
|
|||
enum XmlCupStates
|
||||
{
|
||||
STATE_CUP = 0,
|
||||
STATE_NAME,
|
||||
STATE_SHORT_NAME,
|
||||
STATE_SYMBOL,
|
||||
STATE_SID,
|
||||
STATE_TYPE,
|
||||
STATE_LAST_WEEK,
|
||||
STATE_WEEK_GAP,
|
||||
STATE_YELLOW_RED,
|
||||
STATE_SKILL_DIFF,
|
||||
STATE_AVERAGE_STADIUM_CAPACITY,
|
||||
STATE_CUP_ROUNDS,
|
||||
STATE_CUP_ROUND,
|
||||
STATE_CUP_ROUND_HOME_AWAY,
|
||||
STATE_CUP_ROUND_REPLAY,
|
||||
STATE_CUP_ROUND_NEUTRAL,
|
||||
STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS,
|
||||
STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE,
|
||||
STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE,
|
||||
STATE_CHOOSE_TEAMS,
|
||||
STATE_CHOOSE_TEAM,
|
||||
STATE_CHOOSE_TEAM_SID,
|
||||
STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS,
|
||||
STATE_CHOOSE_TEAM_START_IDX,
|
||||
STATE_CHOOSE_TEAM_END_IDX,
|
||||
STATE_CHOOSE_TEAM_RANDOMLY,
|
||||
STATE_CHOOSE_TEAM_USER,
|
||||
STATE_END
|
||||
};
|
||||
|
||||
/**
|
||||
* Possible values for 'type'.
|
||||
*/
|
||||
#define TYPE_NATIONAL "national"
|
||||
#define TYPE_INTERNATIONAL "international"
|
||||
#define TYPE_SUPERCUP "supercup"
|
||||
|
||||
/**
|
||||
* The state variable used in the XML parsing functions.
|
||||
*/
|
||||
gint state;
|
||||
/** This tells us whether we are in a normal choose_team or
|
||||
in the choose_team for the user's league. */
|
||||
gboolean in_choose_team_user;
|
||||
|
||||
/** The variable we will fill and append to an array. */
|
||||
Cup new_cup;
|
||||
|
||||
/**
|
||||
* The function called by the parser when an opening tag is read.
|
||||
|
@ -53,13 +97,86 @@ gint state;
|
|||
*/
|
||||
void
|
||||
xml_cup_read_start_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
CupRound cp_round_new;
|
||||
CupChooseTeam cp_choose_team_new;
|
||||
|
||||
if(strcmp(element_name, TAG_CUP) == 0)
|
||||
{
|
||||
new_cup = cup_new();
|
||||
state = STATE_CUP;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_NAME) == 0)
|
||||
state = STATE_NAME;
|
||||
else if(strcmp(element_name, TAG_SHORT_NAME) == 0)
|
||||
state = STATE_SHORT_NAME;
|
||||
else if(strcmp(element_name, TAG_SYMBOL) == 0)
|
||||
state = STATE_SYMBOL;
|
||||
else if(strcmp(element_name, TAG_SID) == 0)
|
||||
state = STATE_SID;
|
||||
else if(strcmp(element_name, TAG_TYPE) == 0)
|
||||
state = STATE_TYPE;
|
||||
else if(strcmp(element_name, TAG_LAST_WEEK) == 0)
|
||||
state = STATE_LAST_WEEK;
|
||||
else if(strcmp(element_name, TAG_WEEK_GAP) == 0)
|
||||
state = STATE_WEEK_GAP;
|
||||
else if(strcmp(element_name, TAG_YELLOW_RED) == 0)
|
||||
state = STATE_YELLOW_RED;
|
||||
else if(strcmp(element_name, TAG_SKILL_DIFF) == 0)
|
||||
state = STATE_SKILL_DIFF;
|
||||
else if(strcmp(element_name, TAG_AVERAGE_STADIUM_CAPACITY) == 0)
|
||||
state = STATE_AVERAGE_STADIUM_CAPACITY;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUNDS) == 0)
|
||||
state = STATE_CUP_ROUNDS;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND) == 0)
|
||||
{
|
||||
cp_round_new = cup_round_new();
|
||||
g_array_append_val(new_cup.rounds, cp_round_new);
|
||||
state = STATE_CUP_ROUND;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND_HOME_AWAY) == 0)
|
||||
state = STATE_CUP_ROUND_HOME_AWAY;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND_REPLAY) == 0)
|
||||
state = STATE_CUP_ROUND_REPLAY;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND_NEUTRAL) == 0)
|
||||
state = STATE_CUP_ROUND_NEUTRAL;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS) == 0)
|
||||
state = STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE) == 0)
|
||||
state = STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) == 0)
|
||||
state = STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAMS) == 0)
|
||||
state = STATE_CHOOSE_TEAMS;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0)
|
||||
{
|
||||
cp_choose_team_new = cup_choose_team_new();
|
||||
g_array_append_val(new_cup.choose_teams, cp_choose_team_new);
|
||||
state = STATE_CHOOSE_TEAM;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_SID) == 0)
|
||||
state = STATE_CHOOSE_TEAM_SID;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_NUMBER_OF_TEAMS) == 0)
|
||||
state = STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_START_IDX) == 0)
|
||||
state = STATE_CHOOSE_TEAM_START_IDX;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_END_IDX) == 0)
|
||||
state = STATE_CHOOSE_TEAM_END_IDX;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_RANDOMLY) == 0)
|
||||
state = STATE_CHOOSE_TEAM_RANDOMLY;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_USER) == 0)
|
||||
{
|
||||
state = STATE_CHOOSE_TEAM_USER;
|
||||
in_choose_team_user = TRUE;
|
||||
}
|
||||
else
|
||||
g_warning("xml_cup_read_start_element: unknown tag: %s; I'm in state %d\n",
|
||||
element_name, state);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,11 +186,53 @@ xml_cup_read_start_element (GMarkupParseContext *context,
|
|||
*/
|
||||
void
|
||||
xml_cup_read_end_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
|
||||
if(strcmp(element_name, TAG_NAME) == 0 ||
|
||||
strcmp(element_name, TAG_SHORT_NAME) == 0 ||
|
||||
strcmp(element_name, TAG_SYMBOL) == 0 ||
|
||||
strcmp(element_name, TAG_SID) == 0 ||
|
||||
strcmp(element_name, TAG_TYPE) == 0 ||
|
||||
strcmp(element_name, TAG_LAST_WEEK) == 0 ||
|
||||
strcmp(element_name, TAG_WEEK_GAP) == 0 ||
|
||||
strcmp(element_name, TAG_YELLOW_RED) == 0 ||
|
||||
strcmp(element_name, TAG_SKILL_DIFF) == 0 ||
|
||||
strcmp(element_name, TAG_AVERAGE_STADIUM_CAPACITY) == 0 ||
|
||||
strcmp(element_name, TAG_CUP_ROUNDS) == 0 ||
|
||||
strcmp(element_name, TAG_CHOOSE_TEAMS) == 0)
|
||||
state = STATE_CUP;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND) == 0)
|
||||
state = STATE_CUP_ROUNDS;
|
||||
else if(strcmp(element_name, TAG_CUP_ROUND_HOME_AWAY) == 0 ||
|
||||
strcmp(element_name, TAG_CUP_ROUND_REPLAY) == 0 ||
|
||||
strcmp(element_name, TAG_CUP_ROUND_NEUTRAL) == 0 ||
|
||||
strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS) == 0 ||
|
||||
strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE) == 0 ||
|
||||
strcmp(element_name, TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE) == 0)
|
||||
state = STATE_CUP_ROUND;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM) == 0)
|
||||
state = STATE_CHOOSE_TEAMS;
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_USER) == 0 )
|
||||
{
|
||||
state = STATE_CHOOSE_TEAMS;
|
||||
in_choose_team_user = FALSE;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_CHOOSE_TEAM_SID) == 0 ||
|
||||
strcmp(element_name, TAG_CHOOSE_TEAM_NUMBER_OF_TEAMS) == 0 ||
|
||||
strcmp(element_name, TAG_CHOOSE_TEAM_START_IDX) == 0 ||
|
||||
strcmp(element_name, TAG_CHOOSE_TEAM_END_IDX) == 0 ||
|
||||
strcmp(element_name, TAG_CHOOSE_TEAM_RANDOMLY) == 0)
|
||||
{
|
||||
if(in_choose_team_user)
|
||||
state = STATE_CHOOSE_TEAM_USER;
|
||||
else
|
||||
state = STATE_CHOOSE_TEAM;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_CUP) != 0)
|
||||
g_warning("xml_cup_end_start_element: unknown tag: %s; I'm in state %d\n",
|
||||
element_name, state);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,26 +243,85 @@ xml_cup_read_end_element (GMarkupParseContext *context,
|
|||
*/
|
||||
void
|
||||
xml_cup_read_text (GMarkupParseContext *context,
|
||||
const gchar *text,
|
||||
gsize text_len,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
const gchar *text,
|
||||
gsize text_len,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
CupChooseTeam *choose_team = (in_choose_team_user) ?
|
||||
&new_cup.choose_team_user :
|
||||
&g_array_index(new_cup.choose_teams, CupChooseTeam, new_cup.choose_teams->len - 1);
|
||||
gchar buf[text_len + 1];
|
||||
gint value;
|
||||
|
||||
strncpy(buf, text, text_len);
|
||||
buf[text_len] = '\0';
|
||||
|
||||
value = (gint)g_ascii_strtod(buf, NULL);
|
||||
|
||||
if(state == STATE_NAME)
|
||||
g_string_printf(new_cup.name, "%s", buf);
|
||||
else if(state == STATE_SHORT_NAME)
|
||||
g_string_printf(new_cup.short_name, "%s", buf);
|
||||
else if(state == STATE_SYMBOL)
|
||||
g_string_printf(new_cup.symbol, "%s", buf);
|
||||
else if(state == STATE_SID)
|
||||
g_string_printf(new_cup.sid, "%s", buf);
|
||||
else if(state == STATE_TYPE)
|
||||
{
|
||||
if(strcmp(buf, TYPE_NATIONAL) == 0)
|
||||
new_cup.type = CUP_TYPE_NATIONAL;
|
||||
else if(strcmp(buf, TYPE_INTERNATIONAL) == 0)
|
||||
new_cup.type = CUP_TYPE_INTERNATIONAL;
|
||||
else
|
||||
new_cup.type = CUP_TYPE_SUPERCUP;
|
||||
}
|
||||
else if(state == STATE_LAST_WEEK)
|
||||
new_cup.last_week = value;
|
||||
else if(state == STATE_WEEK_GAP)
|
||||
new_cup.week_gap = value;
|
||||
else if(state == STATE_YELLOW_RED)
|
||||
new_cup.yellow_red = value;
|
||||
else if(state == STATE_SKILL_DIFF)
|
||||
new_cup.skill_diff = value;
|
||||
else if(state == STATE_AVERAGE_STADIUM_CAPACITY)
|
||||
new_cup.average_capacity = value;
|
||||
else if(state == STATE_CUP_ROUND_HOME_AWAY)
|
||||
g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1).home_away = value;
|
||||
else if(state == STATE_CUP_ROUND_REPLAY)
|
||||
g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1).replay = value;
|
||||
else if(state == STATE_CUP_ROUND_NEUTRAL)
|
||||
g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1).neutral = value;
|
||||
else if(state == STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_GROUPS)
|
||||
g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1).round_robin_number_of_groups = value;
|
||||
else if(state == STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_ADVANCE)
|
||||
g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1).round_robin_number_of_advance = value;
|
||||
else if(state == STATE_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE)
|
||||
g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1).round_robin_number_of_best_advance = value;
|
||||
else if(state == STATE_CHOOSE_TEAM_SID)
|
||||
g_string_printf(choose_team->sid, "%s", buf);
|
||||
else if(state == STATE_CHOOSE_TEAM_NUMBER_OF_TEAMS)
|
||||
choose_team->number_of_teams = value;
|
||||
else if(state == STATE_CHOOSE_TEAM_START_IDX)
|
||||
choose_team->start_idx = value;
|
||||
else if(state == STATE_CHOOSE_TEAM_END_IDX)
|
||||
choose_team->end_idx = value;
|
||||
else if(state == STATE_CHOOSE_TEAM_RANDOMLY)
|
||||
choose_team->randomly = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function reading an XML file specifying a country.
|
||||
* The variable country::cup gets freed and overwritten afterwards.
|
||||
* Function reading an XML file specifying a cup.
|
||||
* @param cup_name name of the xml file (e.g. 'cup_england_fa.xml')
|
||||
* to be read. Full path is not necessary, if the file is located in
|
||||
* one of the suppport directories; neither are the prefix 'cup_'
|
||||
* or the suffix '.xml'.
|
||||
* @param cups The array we append the new cup to.
|
||||
*/
|
||||
void
|
||||
xml_cup_read(const gchar *cup_name)
|
||||
xml_cup_read(const gchar *cup_name, GArray *cups)
|
||||
{
|
||||
gchar *file_name = find_support_file(cup_name);
|
||||
gchar *file_name = file_find_support_file(cup_name);
|
||||
GMarkupParser parser = {xml_cup_read_start_element,
|
||||
xml_cup_read_end_element,
|
||||
xml_cup_read_text, NULL, NULL};
|
||||
|
@ -119,7 +337,7 @@ xml_cup_read(const gchar *cup_name)
|
|||
if(file_name == NULL)
|
||||
{
|
||||
sprintf(buf, "cup_%s.xml", cup_name);
|
||||
file_name = find_support_file(buf);
|
||||
file_name = file_find_support_file(buf);
|
||||
}
|
||||
|
||||
if(!g_file_get_contents(file_name, &file_contents, &length, &error))
|
||||
|
@ -130,6 +348,7 @@ xml_cup_read(const gchar *cup_name)
|
|||
}
|
||||
|
||||
state = STATE_CUP;
|
||||
in_choose_team_user = FALSE;
|
||||
strcpy(buf, file_name);
|
||||
g_free(file_name);
|
||||
|
||||
|
@ -138,6 +357,8 @@ xml_cup_read(const gchar *cup_name)
|
|||
g_markup_parse_context_end_parse(context, NULL);
|
||||
g_markup_parse_context_free(context);
|
||||
g_free(file_contents);
|
||||
|
||||
g_array_append_val(cups, new_cup);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
#define XML_CUP_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "misc.h"
|
||||
#include "gui.h"
|
||||
#include "variables.h"
|
||||
|
||||
void
|
||||
xml_cup_read_text (GMarkupParseContext *context,
|
||||
|
@ -29,6 +26,6 @@ xml_cup_read_end_element (GMarkupParseContext *context,
|
|||
|
||||
|
||||
void
|
||||
xml_cup_read(const gchar *file);
|
||||
xml_cup_read(const gchar *file, GArray *cups);
|
||||
|
||||
#endif
|
||||
|
|
120
src/xml_league.c
120
src/xml_league.c
|
@ -1,3 +1,8 @@
|
|||
#include "file.h"
|
||||
#include "league.h"
|
||||
#include "misc.h"
|
||||
#include "team.h"
|
||||
#include "variables.h"
|
||||
#include "xml_league.h"
|
||||
|
||||
/**
|
||||
|
@ -6,19 +11,21 @@
|
|||
#define TAG_LEAGUE "league"
|
||||
#define TAG_NAME "name"
|
||||
#define TAG_SHORT_NAME "short_name"
|
||||
#define TAG_ID "id"
|
||||
#define TAG_SID "sid"
|
||||
#define TAG_SYMBOL "symbol"
|
||||
#define TAG_FIRST_WEEK "first_week"
|
||||
#define TAG_WEEK_GAP "week_gap"
|
||||
#define TAG_YELLOW_RED "yellow_red"
|
||||
#define TAG_AVERAGE_SKILL "average_skill"
|
||||
#define TAG_AVERAGE_STADIUM_CAPACITY "average_stadium_capacity"
|
||||
#define TAG_PROM_REL "prom_rel"
|
||||
#define TAG_PROM_GAMES "prom_games"
|
||||
#define TAG_PROM_GAMES_DEST_ID "prom_games_dest_id"
|
||||
#define TAG_PROM_GAMES_DEST_SID "prom_games_dest_sid"
|
||||
#define TAG_PROM_GAMES_CUP "cup"
|
||||
#define TAG_PROM_REL_ELEMENT "prom_rel_element"
|
||||
#define TAG_PROM_REL_ELEMENT_RANK_START "rank_start"
|
||||
#define TAG_PROM_REL_ELEMENT_RANK_END "rank_end"
|
||||
#define TAG_PROM_REL_ELEMENT_DEST_ID "dest_id"
|
||||
#define TAG_PROM_REL_ELEMENT_DEST_SID "dest_sid"
|
||||
#define TAG_TEAMS "teams"
|
||||
#define TAG_TEAM "team"
|
||||
#define TAG_TEAM_NAME "team_name"
|
||||
|
@ -29,21 +36,23 @@
|
|||
enum XmlLeagueStates
|
||||
{
|
||||
STATE_LEAGUE = 0,
|
||||
STATE_ID,
|
||||
STATE_SID,
|
||||
STATE_NAME,
|
||||
STATE_SHORT_NAME,
|
||||
STATE_SYMBOL,
|
||||
STATE_FIRST_WEEK,
|
||||
STATE_WEEK_GAP,
|
||||
STATE_YELLOW_RED,
|
||||
STATE_AVERAGE_SKILL,
|
||||
STATE_AVERAGE_STADIUM_CAPACITY,
|
||||
STATE_PROM_REL,
|
||||
STATE_PROM_GAMES,
|
||||
STATE_PROM_GAMES_DEST_ID,
|
||||
STATE_PROM_GAMES_DEST_SID,
|
||||
STATE_PROM_GAMES_CUP,
|
||||
STATE_PROM_REL_ELEMENT,
|
||||
STATE_PROM_REL_ELEMENT_RANK_START,
|
||||
STATE_PROM_REL_ELEMENT_RANK_END,
|
||||
STATE_PROM_REL_ELEMENT_DEST_ID,
|
||||
STATE_PROM_REL_ELEMENT_DEST_SID,
|
||||
STATE_TEAMS,
|
||||
STATE_TEAM,
|
||||
STATE_TEAM_NAME,
|
||||
|
@ -54,6 +63,11 @@ enum XmlLeagueStates
|
|||
* The state variable used in the XML parsing functions.
|
||||
*/
|
||||
gint state;
|
||||
/** The counter counting the teams. */
|
||||
gint team_cnt;
|
||||
|
||||
/** The new league we create and append to an array. */
|
||||
League new_league;
|
||||
|
||||
/**
|
||||
* The function called by the parser when an opening tag is read.
|
||||
|
@ -69,22 +83,20 @@ xml_league_read_start_element (GMarkupParseContext *context,
|
|||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
League new;
|
||||
PromRelElement new_element;
|
||||
Team new_team;
|
||||
|
||||
if(strcmp(element_name, TAG_LEAGUE) == 0)
|
||||
{
|
||||
new = league_new();
|
||||
g_array_append_val(ligs, new);
|
||||
new_league = league_new();
|
||||
state = STATE_LEAGUE;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_NAME) == 0)
|
||||
state = STATE_NAME;
|
||||
else if(strcmp(element_name, TAG_SHORT_NAME) == 0)
|
||||
state = STATE_SHORT_NAME;
|
||||
else if(strcmp(element_name, TAG_ID) == 0)
|
||||
state = STATE_ID;
|
||||
else if(strcmp(element_name, TAG_SID) == 0)
|
||||
state = STATE_SID;
|
||||
else if(strcmp(element_name, TAG_SYMBOL) == 0)
|
||||
state = STATE_SYMBOL;
|
||||
else if(strcmp(element_name, TAG_FIRST_WEEK) == 0)
|
||||
|
@ -93,37 +105,42 @@ xml_league_read_start_element (GMarkupParseContext *context,
|
|||
state = STATE_WEEK_GAP;
|
||||
else if(strcmp(element_name, TAG_YELLOW_RED) == 0)
|
||||
state = STATE_YELLOW_RED;
|
||||
else if(strcmp(element_name, TAG_AVERAGE_SKILL) == 0)
|
||||
state = STATE_AVERAGE_SKILL;
|
||||
else if(strcmp(element_name, TAG_AVERAGE_STADIUM_CAPACITY) == 0)
|
||||
state = STATE_AVERAGE_STADIUM_CAPACITY;
|
||||
else if(strcmp(element_name, TAG_PROM_REL) == 0)
|
||||
state = STATE_PROM_REL;
|
||||
else if(strcmp(element_name, TAG_PROM_GAMES) == 0)
|
||||
state = STATE_PROM_GAMES;
|
||||
else if(strcmp(element_name, TAG_PROM_GAMES_DEST_ID) == 0)
|
||||
state = STATE_PROM_GAMES_DEST_ID;
|
||||
else if(strcmp(element_name, TAG_PROM_GAMES_DEST_SID) == 0)
|
||||
state = STATE_PROM_GAMES_DEST_SID;
|
||||
else if(strcmp(element_name, TAG_PROM_GAMES_CUP) == 0)
|
||||
state = STATE_PROM_GAMES_CUP;
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT) == 0)
|
||||
{
|
||||
new_element = prom_rel_element_new();
|
||||
g_array_append_val(lig(ligs->len - 1).prom_rel.elements, new_element);
|
||||
g_array_append_val(new_league.prom_rel.elements, new_element);
|
||||
state = STATE_PROM_REL_ELEMENT;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_RANK_START) == 0)
|
||||
state = STATE_PROM_REL_ELEMENT_RANK_START;
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_RANK_END) == 0)
|
||||
state = STATE_PROM_REL_ELEMENT_RANK_END;
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_DEST_ID) == 0)
|
||||
state = STATE_PROM_REL_ELEMENT_DEST_ID;
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_DEST_SID) == 0)
|
||||
state = STATE_PROM_REL_ELEMENT_DEST_SID;
|
||||
else if(strcmp(element_name, TAG_TEAMS) == 0)
|
||||
state = STATE_TEAMS;
|
||||
else if(strcmp(element_name, TAG_TEAM) == 0)
|
||||
{
|
||||
new_team = team_new();
|
||||
g_array_append_val(lig(ligs->len - 1).teams, new_team);
|
||||
new_team.clid = new_league.id;
|
||||
new_team.id = team_cnt++;
|
||||
g_array_append_val(new_league.teams, new_team);
|
||||
state = STATE_TEAM;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_TEAM_NAME) == 0)
|
||||
state = STATE_TEAM_NAME;
|
||||
|
||||
else
|
||||
g_warning("xml_league_read_start_element: unknown tag: %s; I'm in state %d\n",
|
||||
element_name, state);
|
||||
|
@ -143,29 +160,30 @@ xml_league_read_end_element (GMarkupParseContext *context,
|
|||
{
|
||||
if(strcmp(element_name, TAG_NAME) == 0 ||
|
||||
strcmp(element_name, TAG_SHORT_NAME) == 0 ||
|
||||
strcmp(element_name, TAG_ID) == 0 ||
|
||||
strcmp(element_name, TAG_SID) == 0 ||
|
||||
strcmp(element_name, TAG_SYMBOL) == 0 ||
|
||||
strcmp(element_name, TAG_FIRST_WEEK) == 0 ||
|
||||
strcmp(element_name, TAG_WEEK_GAP) == 0 ||
|
||||
strcmp(element_name, TAG_YELLOW_RED) == 0 ||
|
||||
strcmp(element_name, TAG_AVERAGE_SKILL) == 0 ||
|
||||
strcmp(element_name, TAG_AVERAGE_STADIUM_CAPACITY) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL) == 0 ||
|
||||
strcmp(element_name, TAG_TEAMS) == 0)
|
||||
state = STATE_LEAGUE;
|
||||
else if(strcmp(element_name, TAG_PROM_GAMES) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT) == 0)
|
||||
state = STATE_PROM_REL;
|
||||
else if(strcmp(element_name, TAG_PROM_GAMES_DEST_ID) == 0 ||
|
||||
else if(strcmp(element_name, TAG_PROM_GAMES_DEST_SID) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_GAMES_CUP) == 0)
|
||||
state = STATE_PROM_GAMES;
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_RANK_START) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT_RANK_END) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT_DEST_ID) == 0)
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT_DEST_SID) == 0)
|
||||
state = STATE_PROM_REL_ELEMENT;
|
||||
else if(strcmp(element_name, TAG_TEAM) == 0)
|
||||
state = STATE_TEAMS;
|
||||
else if(strcmp(element_name, TAG_TEAM_NAME) == 0)
|
||||
state = STATE_TEAM;
|
||||
|
||||
else if(strcmp(element_name, TAG_LEAGUE) != 0)
|
||||
g_warning("xml_league_end_start_element: unknown tag: %s; I'm in state %d\n",
|
||||
element_name, state);
|
||||
|
@ -193,38 +211,44 @@ xml_league_read_text (GMarkupParseContext *context,
|
|||
value = (gint)g_ascii_strtod(buf, NULL);
|
||||
|
||||
if(state == STATE_NAME)
|
||||
g_string_printf(lig(ligs->len - 1).name, "%s", buf);
|
||||
g_string_printf(new_league.name, "%s", buf);
|
||||
else if(state == STATE_SHORT_NAME)
|
||||
g_string_printf(lig(ligs->len - 1).short_name, "%s", buf);
|
||||
else if(state == STATE_ID)
|
||||
g_string_printf(lig(ligs->len - 1).id, "%s", buf);
|
||||
g_string_printf(new_league.short_name, "%s", buf);
|
||||
else if(state == STATE_SID)
|
||||
g_string_printf(new_league.sid, "%s", buf);
|
||||
else if(state == STATE_SYMBOL)
|
||||
g_string_printf(lig(ligs->len - 1).symbol, "%s", buf);
|
||||
g_string_printf(new_league.symbol, "%s", buf);
|
||||
else if(state == STATE_FIRST_WEEK)
|
||||
lig(ligs->len - 1).first_week = value;
|
||||
new_league.first_week = value;
|
||||
else if(state == STATE_WEEK_GAP)
|
||||
lig(ligs->len - 1).week_gap = value;
|
||||
new_league.week_gap = value;
|
||||
else if(state == STATE_YELLOW_RED)
|
||||
lig(ligs->len - 1).yellow_red = value;
|
||||
else if(state == STATE_PROM_GAMES_DEST_ID)
|
||||
lig(ligs->len - 1).prom_rel.prom_games_dest_id =
|
||||
g_string_assign(lig(ligs->len - 1).prom_rel.prom_games_dest_id, buf);
|
||||
new_league.yellow_red = value;
|
||||
else if(state == STATE_AVERAGE_SKILL)
|
||||
new_league.average_skill = value;
|
||||
else if(state == STATE_AVERAGE_STADIUM_CAPACITY)
|
||||
new_league.average_capacity = value;
|
||||
else if(state == STATE_PROM_GAMES_DEST_SID)
|
||||
new_league.prom_rel.prom_games_dest_sid =
|
||||
g_string_assign(new_league.prom_rel.prom_games_dest_sid, buf);
|
||||
else if(state == STATE_PROM_GAMES_CUP)
|
||||
lig(ligs->len - 1).prom_rel.prom_games_cup_id =
|
||||
g_string_assign(lig(ligs->len - 1).prom_rel.prom_games_cup_id, buf);
|
||||
new_league.prom_rel.prom_games_cup_sid =
|
||||
g_string_assign(new_league.prom_rel.prom_games_cup_sid, buf);
|
||||
else if(state == STATE_PROM_REL_ELEMENT_RANK_START)
|
||||
g_array_index(lig(ligs->len - 1).prom_rel.elements,
|
||||
g_array_index(new_league.prom_rel.elements,
|
||||
PromRelElement,
|
||||
lig(ligs->len - 1).prom_rel.elements->len - 1).ranks[0] = value;
|
||||
new_league.prom_rel.elements->len - 1).ranks[0] = value;
|
||||
else if(state == STATE_PROM_REL_ELEMENT_RANK_END)
|
||||
g_array_index(lig(ligs->len - 1).prom_rel.elements,
|
||||
g_array_index(new_league.prom_rel.elements,
|
||||
PromRelElement,
|
||||
lig(ligs->len - 1).prom_rel.elements->len - 1).ranks[1] = value;
|
||||
new_league.prom_rel.elements->len - 1).ranks[1] = value;
|
||||
else if(state == STATE_TEAM_NAME)
|
||||
g_array_index(lig(ligs->len - 1).teams, Team,
|
||||
lig(ligs->len - 1).teams->len - 1).name =
|
||||
g_string_assign(g_array_index(lig(ligs->len - 1).teams, Team,
|
||||
lig(ligs->len - 1).teams->len - 1).name, buf);
|
||||
{
|
||||
g_array_index(new_league.teams, Team,
|
||||
new_league.teams->len - 1).name =
|
||||
g_string_assign(g_array_index(new_league.teams, Team,
|
||||
new_league.teams->len - 1).name, buf);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,11 +259,12 @@ xml_league_read_text (GMarkupParseContext *context,
|
|||
* to be read. Full path is not necessary, if the file is located in
|
||||
* one of the suppport directories; neither are the prefix 'league_'
|
||||
* or the suffix '.xml'.
|
||||
* @param leagues The array we write the league into.
|
||||
*/
|
||||
void
|
||||
xml_league_read(const gchar *league_name)
|
||||
xml_league_read(const gchar *league_name, GArray *leagues)
|
||||
{
|
||||
gchar *file_name = find_support_file(league_name);
|
||||
gchar *file_name = file_find_support_file(league_name);
|
||||
GMarkupParser parser = {xml_league_read_start_element,
|
||||
xml_league_read_end_element,
|
||||
xml_league_read_text, NULL, NULL};
|
||||
|
@ -255,7 +280,7 @@ xml_league_read(const gchar *league_name)
|
|||
if(file_name == NULL)
|
||||
{
|
||||
sprintf(buf, "league_%s.xml", league_name);
|
||||
file_name = find_support_file(buf);
|
||||
file_name = file_find_support_file(buf);
|
||||
}
|
||||
|
||||
if(!g_file_get_contents(file_name, &file_contents, &length, &error))
|
||||
|
@ -266,6 +291,7 @@ xml_league_read(const gchar *league_name)
|
|||
}
|
||||
|
||||
state = STATE_LEAGUE;
|
||||
team_cnt = 0;
|
||||
strcpy(buf, file_name);
|
||||
g_free(file_name);
|
||||
|
||||
|
@ -274,6 +300,8 @@ xml_league_read(const gchar *league_name)
|
|||
g_markup_parse_context_end_parse(context, NULL);
|
||||
g_markup_parse_context_free(context);
|
||||
g_free(file_contents);
|
||||
|
||||
g_array_append_val(leagues, new_league);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
#define XML_LEAGUE_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
#include "league.h"
|
||||
#include "gui.h"
|
||||
#include "misc.h"
|
||||
#include "variables.h"
|
||||
#include "team_struct.h"
|
||||
|
||||
void
|
||||
xml_league_read_start_element (GMarkupParseContext *context,
|
||||
|
@ -29,6 +26,6 @@ xml_league_read_text (GMarkupParseContext *context,
|
|||
GError **error);
|
||||
|
||||
void
|
||||
xml_league_read(const gchar *league_name);
|
||||
xml_league_read(const gchar *league_name, GArray *leagues);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
#include "file.h"
|
||||
#include "free.h"
|
||||
#include "maths.h"
|
||||
#include "misc.h"
|
||||
#include "variables.h"
|
||||
#include "xml_name.h"
|
||||
|
||||
#define TAG_NAMES "player_names"
|
||||
#define TAG_PLAYER_NAME "player_name"
|
||||
#define TAG_PLAYER_NAME_NAME "name"
|
||||
|
||||
enum XmlNameStates
|
||||
{
|
||||
STATE_NAMES = 0,
|
||||
STATE_PLAYER_NAME,
|
||||
STATE_PLAYER_NAME_NAME,
|
||||
STATE_END
|
||||
};
|
||||
|
||||
/** Keep track of the state. */
|
||||
gint state;
|
||||
GPtrArray *temp_array;
|
||||
GString *new_name;
|
||||
|
||||
/** @see xml_league_read_start_element */
|
||||
void
|
||||
xml_name_read_start_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
if(strcmp(element_name, TAG_NAMES) == 0)
|
||||
state = STATE_NAMES;
|
||||
else if(strcmp(element_name, TAG_PLAYER_NAME) == 0)
|
||||
{
|
||||
new_name = g_string_new("");
|
||||
state = STATE_PLAYER_NAME;
|
||||
}
|
||||
else if(strcmp(element_name, TAG_PLAYER_NAME_NAME) == 0)
|
||||
state = STATE_PLAYER_NAME_NAME;
|
||||
else
|
||||
g_warning("xml_name_read_start_element: unknown tag: %s; I'm in state %d\n",
|
||||
element_name, state);
|
||||
}
|
||||
|
||||
/** @see xml_league_read_end_element */
|
||||
void
|
||||
xml_name_read_end_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
if(strcmp(element_name, TAG_PLAYER_NAME) == 0)
|
||||
state = STATE_NAMES;
|
||||
else if(strcmp(element_name, TAG_PLAYER_NAME_NAME) == 0)
|
||||
state = STATE_PLAYER_NAME;
|
||||
else if(strcmp(element_name, TAG_NAMES) != 0)
|
||||
g_warning("xml_name_end_start_element: unknown tag: %s; I'm in state %d\n",
|
||||
element_name, state);
|
||||
}
|
||||
|
||||
/** @see xml_league_read_text */
|
||||
void
|
||||
xml_name_read_text (GMarkupParseContext *context,
|
||||
const gchar *text,
|
||||
gsize text_len,
|
||||
gpointer user_data,
|
||||
GError **error)
|
||||
{
|
||||
gchar buf[text_len + 1];
|
||||
|
||||
strncpy(buf, text, text_len);
|
||||
buf[text_len] = '\0';
|
||||
|
||||
if(state == STATE_PLAYER_NAME_NAME)
|
||||
{
|
||||
g_string_printf(new_name, "%s", buf);
|
||||
g_ptr_array_add(temp_array, (gpointer)new_name);
|
||||
}
|
||||
}
|
||||
|
||||
/** Fill the player names array with names from the
|
||||
player names file. Randomize the order and keep only
|
||||
'number_of_names' of them.
|
||||
@param names_file The file the names are read from.
|
||||
@param number_of_names Number of player names we keep in memory.
|
||||
If this is -1, we keep all of them. */
|
||||
void
|
||||
xml_name_read(const gchar *names_file, gint number_of_names)
|
||||
{
|
||||
gint i;
|
||||
gchar *file_name = file_find_support_file(names_file);
|
||||
GMarkupParser parser = {xml_name_read_start_element,
|
||||
xml_name_read_end_element,
|
||||
xml_name_read_text, NULL, NULL};
|
||||
GMarkupParseContext *context;
|
||||
gchar *file_contents;
|
||||
gint length;
|
||||
GError *error = NULL;
|
||||
gchar buf[SMALL];
|
||||
|
||||
context =
|
||||
g_markup_parse_context_new(&parser, 0, NULL, NULL);
|
||||
|
||||
if(!g_file_get_contents(file_name, &file_contents, &length, &error))
|
||||
{
|
||||
g_warning("xml_name_read: error reading file %s\n", file_name);
|
||||
misc_print_error(error, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
state = STATE_NAMES;
|
||||
strcpy(buf, file_name);
|
||||
g_free(file_name);
|
||||
free_g_string_array(&player_names);
|
||||
temp_array = g_ptr_array_new();
|
||||
|
||||
if(g_markup_parse_context_parse(context, file_contents, length, &error))
|
||||
{
|
||||
g_markup_parse_context_end_parse(context, NULL);
|
||||
g_markup_parse_context_free(context);
|
||||
g_free(file_contents);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_critical("xml_name_read: error parsing file %s\n", buf);
|
||||
misc_print_error(error, TRUE);
|
||||
}
|
||||
|
||||
if(number_of_names == -1)
|
||||
{
|
||||
player_names = temp_array;
|
||||
return;
|
||||
}
|
||||
|
||||
gint int_array[temp_array->len];
|
||||
math_generate_permutation(int_array, 0, temp_array->len - 1);
|
||||
player_names = g_ptr_array_new();
|
||||
|
||||
for(i=0;i<number_of_names;i++)
|
||||
{
|
||||
new_name = g_string_new(((GString*)g_ptr_array_index(temp_array, int_array[i]))->str);
|
||||
g_ptr_array_add(player_names, (gpointer)new_name);
|
||||
}
|
||||
|
||||
free_g_string_array(&temp_array);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef XML_NAME_H
|
||||
#define XML_NAME_H
|
||||
|
||||
#include "bygfoot.h"
|
||||
|
||||
void
|
||||
xml_name_read_start_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
const gchar **attribute_names,
|
||||
const gchar **attribute_values,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
xml_name_read_end_element (GMarkupParseContext *context,
|
||||
const gchar *element_name,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
xml_name_read_text (GMarkupParseContext *context,
|
||||
const gchar *text,
|
||||
gsize text_len,
|
||||
gpointer user_data,
|
||||
GError **error);
|
||||
|
||||
void
|
||||
xml_name_read(const gchar *names_file, gint number_of_names);
|
||||
|
||||
#endif
|
|
@ -2,7 +2,7 @@
|
|||
<country>
|
||||
<name>England</name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<id>england</id>
|
||||
<sid>england</sid>
|
||||
<leagues>
|
||||
<league>england1</league>
|
||||
<league>england2</league>
|
||||
|
@ -14,5 +14,8 @@
|
|||
<cups>
|
||||
<cup>england_fa</cup>
|
||||
<cup>england_league</cup>
|
||||
<cup>champ_league</cup>
|
||||
<cup>cwc</cup>
|
||||
<cup>uefa</cup>
|
||||
</cups>
|
||||
</country>
|
||||
|
|
|
@ -3,11 +3,9 @@
|
|||
<name>FA Cup</name>
|
||||
<short_name>FA Cup</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<id>england_fa</id>
|
||||
<type>national</type>
|
||||
<sid>england_fa</sid>
|
||||
<last_week>47</last_week>
|
||||
<week_gap>4</week_gap>
|
||||
<yellow_red>3</yellow_red>
|
||||
<week_gap>4</week_gap>
|
||||
|
||||
<cup_rounds>
|
||||
<cup_round>
|
||||
|
@ -44,24 +42,19 @@
|
|||
|
||||
<choose_teams>
|
||||
<choose_team>
|
||||
<choose_team_id>england1</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england1</choose_team_sid>
|
||||
</choose_team>
|
||||
<choose_team>
|
||||
<choose_team_id>england2</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england2</choose_team_sid>
|
||||
</choose_team>
|
||||
<choose_team>
|
||||
<choose_team_id>england3</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england3</choose_team_sid>
|
||||
</choose_team>
|
||||
<choose_team>
|
||||
<choose_team_id>england4</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england4</choose_team_sid>
|
||||
</choose_team>
|
||||
<choose_team>
|
||||
<choose_team_id>england5</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england5</choose_team_sid>
|
||||
</choose_team>
|
||||
</choose_teams>
|
||||
</cup>
|
||||
|
|
|
@ -3,11 +3,9 @@
|
|||
<name>League Cup</name>
|
||||
<short_name>League Cup</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<id>england_league</id>
|
||||
<type>national</type>
|
||||
<sid>england_league</sid>
|
||||
<last_week>48</last_week>
|
||||
<week_gap>4</week_gap>
|
||||
<yellow_red>3</yellow_red>
|
||||
|
||||
<cup_rounds>
|
||||
<cup_round>
|
||||
|
@ -26,6 +24,7 @@
|
|||
<home_away>0</home_away>
|
||||
</cup_round>
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
</cup_round>
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
|
@ -35,20 +34,16 @@
|
|||
|
||||
<choose_teams>
|
||||
<choose_team>
|
||||
<choose_team_id>england1</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england1</choose_team_sid>
|
||||
</choose_team>
|
||||
<choose_team>
|
||||
<choose_team_id>england2</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england2</choose_team_sid>
|
||||
</choose_team>
|
||||
<choose_team>
|
||||
<choose_team_id>england3</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england3</choose_team_sid>
|
||||
</choose_team>
|
||||
<choose_team>
|
||||
<choose_team_id>england4</choose_team_id>
|
||||
<number_of_teams>-1</number_of_teams>
|
||||
<choose_team_sid>england4</choose_team_sid>
|
||||
</choose_team>
|
||||
</choose_teams>
|
||||
</cup>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<name>Promotion Games</name>
|
||||
<short_name>Prom. Gam.</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<id>england_prom_games</id>
|
||||
<sid>england_prom_games</sid>
|
||||
<type>national</type>
|
||||
<home_away>1</home_away>
|
||||
</cup>
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>belgium1_short</sid>
|
||||
<symbol>flag_bl.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Anderlecht</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Brugge</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Westerlo</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Liege</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Genk</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>czech1_short</sid>
|
||||
<symbol>flag_cz.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Sp. Praha</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Sl. Praha</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Bratislava</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>denmark1_short</sid>
|
||||
<symbol>flag_dk.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Brondby</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Halmstad</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Kobenhavn</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Odense</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Aarhus</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Aalborg</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -1,21 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<id>england1</id>
|
||||
<sid>england1</sid>
|
||||
<name>Premiership</name>
|
||||
<short_name>Prem.</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<first_week>1</first_week>
|
||||
<week_gap>1</week_gap>
|
||||
<average_skill>80</average_skill>
|
||||
<average_stadium_capacity>40000</average_stadium_capacity>
|
||||
|
||||
<prom_rel>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>18</rank_start>
|
||||
<rank_end>20</rank_end>
|
||||
<dest_id>england2</dest_id>
|
||||
<dest_sid>england2</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
</prom_rel>
|
||||
|
||||
<teams>
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<id>england2</id>
|
||||
<sid>england2</sid>
|
||||
<name>Football League Championship</name>
|
||||
<short_name>F. L. Champ.</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<first_week>1</first_week>
|
||||
<week_gap>1</week_gap>
|
||||
<average_skill>70</average_skill>
|
||||
<average_stadium_capacity>30000</average_stadium_capacity>
|
||||
|
||||
<prom_rel>
|
||||
|
||||
<prom_games>
|
||||
<prom_games_dest_id>england1</prom_games_dest_id>
|
||||
<prom_games_dest_sid>england1</prom_games_dest_sid>
|
||||
<cup>cup_england_prom_games</cup>
|
||||
</prom_games>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>1</rank_start>
|
||||
<rank_end>2</rank_end>
|
||||
<dest_id>england1</dest_id>
|
||||
<dest_sid>england1</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>22</rank_start>
|
||||
<rank_end>24</rank_end>
|
||||
<dest_id>england3</dest_id>
|
||||
<dest_sid>england3</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
</prom_rel>
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<id>england3</id>
|
||||
<sid>england3</sid>
|
||||
<name>Football League One</name>
|
||||
<short_name>F. L. One</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<first_week>1</first_week>
|
||||
<week_gap>1</week_gap>
|
||||
<average_skill>60</average_skill>
|
||||
<average_stadium_capacity>20000</average_stadium_capacity>
|
||||
|
||||
<prom_rel>
|
||||
|
||||
<prom_games>
|
||||
<prom_games_dest_id>england2</prom_games_dest_id>
|
||||
<prom_games_dest_sid>england2</prom_games_dest_sid>
|
||||
<cup>cup_england_prom_games</cup>
|
||||
</prom_games>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>1</rank_start>
|
||||
<rank_end>2</rank_end>
|
||||
<dest_id>england2</dest_id>
|
||||
<dest_sid>england2</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>21</rank_start>
|
||||
<rank_end>24</rank_end>
|
||||
<dest_id>england4</dest_id>
|
||||
<dest_sid>england4</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
</prom_rel>
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<id>england3</id>
|
||||
<sid>england3</sid>
|
||||
<name>Football League Two</name>
|
||||
<short_name>F. L. Two</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<first_week>1</first_week>
|
||||
<week_gap>1</week_gap>
|
||||
<average_skill>50</average_skill>
|
||||
<average_stadium_capacity>10000</average_stadium_capacity>
|
||||
|
||||
<prom_rel>
|
||||
|
||||
<prom_games>
|
||||
<prom_games_dest_id>england2</prom_games_dest_id>
|
||||
<prom_games_dest_sid>england2</prom_games_dest_sid>
|
||||
<cup>cup_england_prom_games</cup>
|
||||
</prom_games>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>1</rank_start>
|
||||
<rank_end>2</rank_end>
|
||||
<dest_id>england2</dest_id>
|
||||
<dest_sid>england2</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>21</rank_start>
|
||||
<rank_end>24</rank_end>
|
||||
<dest_id>england4</dest_id>
|
||||
<dest_sid>england4</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
</prom_rel>
|
||||
|
|
|
@ -1,24 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<id>england4</id>
|
||||
<sid>england4</sid>
|
||||
<name>Nationwide Conference</name>
|
||||
<short_name>Nat. Conf.</short_name>
|
||||
<symbol>flag_en.png</symbol>
|
||||
<first_week>1</first_week>
|
||||
<week_gap>1</week_gap>
|
||||
<average_skill>40</average_skill>
|
||||
<average_stadium_capacity>7500</average_stadium_capacity>
|
||||
|
||||
<prom_rel>
|
||||
|
||||
<prom_games>
|
||||
<prom_games_dest_id>england4</prom_games_dest_id>
|
||||
<prom_games_dest_sid>england4</prom_games_dest_sid>
|
||||
<cup>cup_england_prom_games</cup>
|
||||
</prom_games>
|
||||
|
||||
<prom_rel_element>
|
||||
<rank_start>1</rank_start>
|
||||
<rank_end>1</rank_end>
|
||||
<dest_id>england4</dest_id>
|
||||
<dest_sid>england4</dest_sid>
|
||||
</prom_rel_element>
|
||||
|
||||
</prom_rel>
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>france1_short</sid>
|
||||
<symbol>flag_fr.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Nantes</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Lille</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Lyon</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Bordeaux</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Paris</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Monaco</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Marseille</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Auxerre</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Strasbourg</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>germany1_short</sid>
|
||||
<symbol>flag_de.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Bremen</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>München</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Stuttgart</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Leverkusen</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Schalke</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Dortmund</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>greece1_short</sid>
|
||||
<symbol>flag_gr.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>P. Athens</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Piraeus</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>A. Athens</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Tsaloniki</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Nicosia</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>italy1_short</sid>
|
||||
<symbol>flag_it.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Roma</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Torino</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>L. Roma</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Firenze</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Milano</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Parma</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Internazional</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Genova</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>netherlands1_short</sid>
|
||||
<symbol>flag_nl.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>F. Rotterdam</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Eindhoven</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Kerkrade</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Amsterdam</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Enschede</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Utrecht</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
<sid>portugal1</sid>
|
||||
<symbol>flag_pt.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>B. Porto</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Porto</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>S. Lisboa</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>B. Lisboa</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>russia1_short</sid>
|
||||
<symbol>flag_ru.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>L. Moscow</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>S. Moscow</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>D. Moscow</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>T. Moscow</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>scotland1_short</sid>
|
||||
<symbol>flag_sco.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Midlothian</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Glasgow</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>C. Glasgow</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Hibernian</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Kilmarnock</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>spain1_short</sid>
|
||||
<symbol>flag_es.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Barcelona</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>R. Madrid</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>A. Madrid</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>La Coruna</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Mallorca</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Valencia</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Zaragoza</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Sociedad</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>switzerland1_short</sid>
|
||||
<symbol>flag_ch.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>Neuchatel</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Aarau</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Bern</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>G. Zürich</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Servette</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>St. Gallen</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Basel</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>turkey1_short</sid>
|
||||
<symbol>flag_tr.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>G. Istanbul</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>F. Istanbul</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>B. Istanbul</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Trabzon</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<league>
|
||||
|
||||
<sid>ukraine1_short</sid>
|
||||
<symbol>flag_uk.png</symbol>
|
||||
|
||||
<teams>
|
||||
<team>
|
||||
<team_name>D. Kyiv</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>C. Kyiv</team_name>
|
||||
</team>
|
||||
<team>
|
||||
<team_name>Donetsk</team_name>
|
||||
</team>
|
||||
</teams>
|
||||
</league>
|
Loading…
Reference in New Issue