mirror of
https://github.com/tstellar/bygfoot.git
synced 2025-01-28 14:39:22 +01:00
Tables attached to cup rounds (not the cups themselves). Cups with round robin as last round allowed.
This commit is contained in:
parent
24b5d8edcc
commit
37f9b5ebdd
@ -48,7 +48,7 @@ bygfoot_SOURCES = \
|
||||
window.c file.h finance.h free.h game_gui.h gui.h interface.h main.h misc_interface.h misc2_interface.h option.h support.h user.h window.h \
|
||||
xml.c cup.h file.h free.h gui.h league.h misc.h support.h table.h transfer_struct.h user.h variables.h xml.h xml_loadsave_cup.h xml_loadsave_league.h xml_loadsave_teams.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_transfers.h xml_loadsave_users.h \
|
||||
xml_loadsave_misc.c cup.h file.h misc.h variables.h xml.h xml_loadsave_misc.h xml_loadsave_cup.h xml_loadsave_league.h \
|
||||
xml_loadsave_cup.c cup.h file.h misc.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \
|
||||
xml_loadsave_cup.c cup.h file.h misc.h table.h team.h xml.h xml_loadsave_cup.h xml_loadsave_fixtures.h xml_loadsave_table.h xml_loadsave_teams.h \
|
||||
xml_loadsave_fixtures.c file.h fixture.h misc.h team.h xml.h xml_loadsave_fixtures.h \
|
||||
xml_loadsave_league.c file.h league.h misc.h xml.h xml_loadsave_fixtures.h xml_loadsave_league.h xml_loadsave_table.h xml_loadsave_teams.h \
|
||||
xml_loadsave_live_game.c cup.h file.h fixture.h league.h live_game.h misc.h variables.h xml.h xml_loadsave_live_game.h \
|
||||
|
@ -196,13 +196,13 @@ callback_show_tables(gint type)
|
||||
else if(type == SHOW_NEXT_LEAGUE)
|
||||
{
|
||||
clid = league_cup_get_next_clid(stat1);
|
||||
while(clid >= ID_CUP_START && cup_from_clid(clid)->tables->len == 0)
|
||||
while(clid >= ID_CUP_START && cup_has_tables(clid) == -1)
|
||||
clid = league_cup_get_next_clid(clid);
|
||||
}
|
||||
else if(type == SHOW_PREVIOUS_LEAGUE)
|
||||
{
|
||||
clid = league_cup_get_previous_clid(stat1);
|
||||
while(clid >= ID_CUP_START && cup_from_clid(clid)->tables->len == 0)
|
||||
while(clid >= ID_CUP_START && cup_has_tables(clid) == -1)
|
||||
clid = league_cup_get_previous_clid(clid);
|
||||
}
|
||||
|
||||
|
66
src/cup.c
66
src/cup.c
@ -37,7 +37,6 @@ cup_new(gboolean new_id)
|
||||
new.rounds = g_array_new(FALSE, FALSE, sizeof(CupRound));
|
||||
new.teams = g_array_new(FALSE, FALSE, sizeof(Team));
|
||||
new.user_teams = g_ptr_array_new();
|
||||
new.tables = g_array_new(FALSE, FALSE, sizeof(Table));
|
||||
new.fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture));
|
||||
new.bye = NULL;
|
||||
|
||||
@ -73,6 +72,7 @@ cup_round_new(void)
|
||||
new.round_robin_number_of_groups = 0;
|
||||
new.round_robin_number_of_advance = -1;
|
||||
new.round_robin_number_of_best_advance = 0;
|
||||
new.tables = g_array_new(FALSE, FALSE, sizeof(Table));
|
||||
|
||||
return new;
|
||||
}
|
||||
@ -458,7 +458,7 @@ cup_get_teams_sorted(const Cup *cup)
|
||||
g_ptr_array_add(teams, team_of_id(g_array_index(cup->fixtures, Fixture, i).team_ids[j]));
|
||||
}
|
||||
|
||||
g_ptr_array_sort_with_data(teams, cup_compare_success, (gpointer)cup->fixtures);
|
||||
g_ptr_array_sort_with_data(teams, cup_compare_success, (gpointer)cup);
|
||||
|
||||
g_array_free(team_ids, TRUE);
|
||||
|
||||
@ -470,7 +470,9 @@ cup_get_teams_sorted(const Cup *cup)
|
||||
gint
|
||||
cup_compare_success(gconstpointer a, gconstpointer b, gpointer data)
|
||||
{
|
||||
const GArray *fixtures = (GArray*)data;
|
||||
const Cup *cup = (const Cup*)data;
|
||||
const CupRound *cupround = NULL;
|
||||
const GArray *fixtures = cup->fixtures;
|
||||
const Team *team1 = *(const Team**)a;
|
||||
const Team *team2 = *(const Team**)b;
|
||||
const Fixture *last_fix = &g_array_index(fixtures, Fixture, fixtures->len - 1);
|
||||
@ -478,13 +480,20 @@ cup_compare_success(gconstpointer a, gconstpointer b, gpointer data)
|
||||
round_reached2 = cup_get_round_reached(team2, fixtures);
|
||||
gint return_value = 0;
|
||||
|
||||
if(round_reached1 < round_reached2)
|
||||
if(team1 == team2)
|
||||
return_value = 0;
|
||||
else if(round_reached1 < round_reached2)
|
||||
return_value = 1;
|
||||
else if(round_reached1 > round_reached2)
|
||||
return_value = -1;
|
||||
else
|
||||
{
|
||||
if(round_reached1 != last_fix->round)
|
||||
cupround = &g_array_index(cup->rounds, CupRound, round_reached1);
|
||||
|
||||
if(cupround->tables->len > 0)
|
||||
return_value =
|
||||
cup_compare_success_tables(team1, team2, cup, round_reached1);
|
||||
else if(round_reached1 != last_fix->round)
|
||||
return_value = 0;
|
||||
else
|
||||
{
|
||||
@ -498,6 +507,34 @@ cup_compare_success(gconstpointer a, gconstpointer b, gpointer data)
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/** Compare two teams in cup tables. */
|
||||
gint
|
||||
cup_compare_success_tables(const Team *tm1, const Team *tm2, const Cup *cup, gint round)
|
||||
{
|
||||
gint i, j;
|
||||
gint return_value = 0;
|
||||
const CupRound *cupround = &g_array_index(cup->rounds, CupRound, round);
|
||||
const TableElement *elem1 = NULL, *elem2 = NULL;
|
||||
|
||||
if(team_get_cup_rank(tm1, cupround) > team_get_cup_rank(tm2, cupround))
|
||||
return_value = 1;
|
||||
else if(team_get_cup_rank(tm1, cupround) < team_get_cup_rank(tm2, cupround))
|
||||
return_value = -1;
|
||||
else
|
||||
{
|
||||
for(i=0;i<cupround->tables->len;i++)
|
||||
for(j=0;j<g_array_index(cupround->tables, Table, i).elements->len;j++)
|
||||
if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm1)
|
||||
elem1 = &g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j);
|
||||
else if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm2)
|
||||
elem2 = &g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j);
|
||||
|
||||
return_value = table_element_compare_func(elem1, elem2, GINT_TO_POINTER(cup->id));
|
||||
}
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/** Return the cup round that the team reached in the cup.
|
||||
@param fixtures The fixtures array of the cup. */
|
||||
gint
|
||||
@ -674,7 +711,7 @@ cup_round_name(const Fixture *fix, gchar *buf)
|
||||
|
||||
cup_get_round_name(cup, fix->round, buf);
|
||||
|
||||
if(cup_round->home_away)
|
||||
if(cup_round->home_away && cup_round->round_robin_number_of_groups == 0)
|
||||
{
|
||||
if(fix->second_leg)
|
||||
strcat(buf, " -- Second leg");
|
||||
@ -764,3 +801,20 @@ query_cup_supercup_begins(const Cup *supercup)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/** Find out whether the cup contains tables
|
||||
that can be displayed. Returns -1 if false
|
||||
and the number of the cup round with tables
|
||||
otherwise. */
|
||||
gint
|
||||
cup_has_tables(gint clid)
|
||||
{
|
||||
const Cup *cup = cup_from_clid(clid);
|
||||
gint i;
|
||||
|
||||
for(i=cup->rounds->len - 1; i>=0; i--)
|
||||
if(g_array_index(cup->rounds, CupRound, i).tables->len > 0)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "league_struct.h"
|
||||
|
||||
#define query_cup_is_prom(clid) (clid >= ID_PROM_CUP_START && clid < ID_SUPERCUP_START)
|
||||
#define cup_get_last_tables_round(clid) &g_array_index(cup_from_clid(clid)->rounds, CupRound, cup_has_tables(clid))
|
||||
#define cup_get_last_tables(clid) g_array_index(cup_from_clid(clid)->rounds, CupRound, cup_has_tables(clid)).tables
|
||||
|
||||
Cup
|
||||
cup_new(gboolean new_id);
|
||||
@ -47,6 +49,9 @@ cup_round_name(const Fixture *fix, gchar *buf);
|
||||
GPtrArray*
|
||||
cup_get_teams_sorted(const Cup *cup);
|
||||
|
||||
gint
|
||||
cup_compare_success_tables(const Team *tm1, const Team *tm2, const Cup *cup, gint round);
|
||||
|
||||
GPtrArray*
|
||||
cup_get_teams_from_names(GPtrArray *team_names);
|
||||
|
||||
@ -72,4 +77,7 @@ cup_get_last_week_from_first(const Cup *cup, gint first_week);
|
||||
void
|
||||
cup_get_round_name(const Cup *cup, gint round, gchar *buf);
|
||||
|
||||
gint
|
||||
cup_has_tables(gint clid);
|
||||
|
||||
#endif
|
||||
|
@ -38,6 +38,8 @@ typedef struct
|
||||
and additionally the best 3 from all the groups.
|
||||
Default: 0. */
|
||||
gint round_robin_number_of_best_advance;
|
||||
/** The round robin tables (in case there is a round robin). */
|
||||
GArray *tables;
|
||||
|
||||
} CupRound;
|
||||
|
||||
@ -112,8 +114,6 @@ typedef struct
|
||||
GArray *teams;
|
||||
/** Pointers to the teams from the leagues that participate. */
|
||||
GPtrArray *user_teams;
|
||||
/** An array of tables for round robin groups. */
|
||||
GArray *tables;
|
||||
/** The fixtures of a season for the cup. */
|
||||
GArray *fixtures;
|
||||
} Cup;
|
||||
|
@ -62,18 +62,15 @@ fixture_write_cup_fixtures(Cup *cup)
|
||||
g_array_free(cup->fixtures, TRUE);
|
||||
cup->fixtures = g_array_new(FALSE, FALSE, sizeof(Fixture));
|
||||
|
||||
if(g_array_index(cup->rounds, CupRound, 0).
|
||||
round_robin_number_of_groups > 0)
|
||||
fixture_write_cup_round_robin(cup, 0, NULL);
|
||||
if(cup->type == CUP_TYPE_INTERNATIONAL)
|
||||
teams = cup_get_team_pointers(cup);
|
||||
else
|
||||
{
|
||||
if(cup->type == CUP_TYPE_INTERNATIONAL)
|
||||
teams = cup_get_team_pointers(cup);
|
||||
else
|
||||
teams = cup_get_choose_teams_pointers(cup);
|
||||
teams = cup_get_choose_teams_pointers(cup);
|
||||
|
||||
if(g_array_index(cup->rounds, CupRound, 0).round_robin_number_of_groups > 0)
|
||||
fixture_write_cup_round_robin(cup, 0, teams);
|
||||
else
|
||||
fixture_write_knockout_round(cup, 0, teams);
|
||||
}
|
||||
}
|
||||
|
||||
/** Update the fixtures for the given cup.
|
||||
@ -185,16 +182,18 @@ fixture_get_round_robin_advance(const Cup *cup, gint round)
|
||||
const CupRound *cupround = &g_array_index(cup->rounds, CupRound, round);
|
||||
GArray *best_advance = g_array_new(FALSE, FALSE, sizeof(TableElement));
|
||||
|
||||
for(i=0;i<cup->tables->len;i++)
|
||||
for(j=0;j<g_array_index(cup->tables, Table, i).elements->len;j++)
|
||||
for(i=0;i<cupround->tables->len;i++)
|
||||
for(j=0;j<g_array_index(cupround->tables, Table, i).elements->len;j++)
|
||||
{
|
||||
if(j < cupround->round_robin_number_of_advance)
|
||||
g_ptr_array_add(array, g_array_index(
|
||||
g_array_index(cup->tables, Table, i).elements,
|
||||
g_array_index(cupround->tables, Table, i).elements,
|
||||
TableElement, j).team);
|
||||
else
|
||||
g_array_append_val(best_advance,
|
||||
g_array_index(g_array_index(cup->tables, Table, i).elements,
|
||||
g_array_index(g_array_index(cupround->tables, Table, i).elements,
|
||||
TableElement, j));
|
||||
}
|
||||
|
||||
g_array_sort_with_data(best_advance,
|
||||
(GCompareDataFunc)table_element_compare_func,
|
||||
@ -203,6 +202,8 @@ fixture_get_round_robin_advance(const Cup *cup, gint round)
|
||||
for(i=0;i<cupround->round_robin_number_of_best_advance;i++)
|
||||
g_ptr_array_add(array, g_array_index(best_advance, TableElement, i).team);
|
||||
|
||||
g_array_free(best_advance, TRUE);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
@ -280,14 +281,13 @@ void
|
||||
fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
|
||||
{
|
||||
gint i, j;
|
||||
gint number_of_groups =
|
||||
g_array_index(cup->rounds, CupRound, cup_round).round_robin_number_of_groups;
|
||||
GPtrArray *teams_group[number_of_groups];
|
||||
CupRound *cupround = &g_array_index(cup->rounds, CupRound, cup_round);
|
||||
gint number_of_groups = cupround->round_robin_number_of_groups;
|
||||
GPtrArray *teams_group = NULL;
|
||||
Table new_table;
|
||||
TableElement new_table_element;
|
||||
|
||||
if(teams == NULL)
|
||||
teams = misc_randomise_g_pointer_array(cup_get_team_pointers(cup));
|
||||
teams = misc_randomise_g_pointer_array(teams);
|
||||
|
||||
if(teams->len % number_of_groups != 0)
|
||||
{
|
||||
@ -298,7 +298,11 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
|
||||
main_exit_program(EXIT_FIXTURE_WRITE_ERROR, NULL);
|
||||
}
|
||||
|
||||
free_cup_tables(cup->tables, TRUE);
|
||||
for(i=0;i<cupround->tables->len;i++)
|
||||
free_table(&g_array_index(cupround->tables, Table, i));
|
||||
|
||||
g_array_free(cupround->tables, TRUE);
|
||||
cupround->tables = g_array_new(FALSE, FALSE, sizeof(Table));
|
||||
|
||||
for(i=0;i<number_of_groups;i++)
|
||||
{
|
||||
@ -307,25 +311,29 @@ fixture_write_cup_round_robin(Cup *cup, gint cup_round, GPtrArray *teams)
|
||||
new_table.round = cup_round;
|
||||
new_table.elements = g_array_new(FALSE, FALSE, sizeof(TableElement));
|
||||
|
||||
teams_group[i] = g_ptr_array_new();
|
||||
teams_group = g_ptr_array_new();
|
||||
|
||||
for(j=0;j<teams->len / number_of_groups;j++)
|
||||
{
|
||||
g_ptr_array_add(teams_group[i], g_ptr_array_index(teams, j + i * number_of_groups));
|
||||
g_ptr_array_add(teams_group, g_ptr_array_index(teams, j + i * number_of_groups));
|
||||
new_table_element =
|
||||
table_element_new((Team*)g_ptr_array_index(teams, j + i * number_of_groups));
|
||||
g_array_append_val(new_table.elements, new_table_element);
|
||||
}
|
||||
|
||||
g_array_append_val(cup->tables, new_table);
|
||||
g_array_append_val(cupround->tables, new_table);
|
||||
|
||||
fixture_write_round_robin((gpointer)cup, cup_round, teams_group);
|
||||
|
||||
fixture_write_round_robin((gpointer)cup, cup_round, teams_group[i]);
|
||||
}
|
||||
|
||||
g_ptr_array_free(teams, TRUE);
|
||||
|
||||
cup->next_fixture_update_week = (cup_round < cup->rounds->len - 1) ?
|
||||
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : -1;
|
||||
cup->next_fixture_update_week_round = (cup_round < cup->rounds->len - 1) ?
|
||||
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : -1;
|
||||
|
||||
}
|
||||
|
||||
/** Write round robin fixtures for the teams in the array.
|
||||
@ -396,6 +404,8 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round, GPtrArray *teams)
|
||||
first_week + (len - 1 + i) * week_gap,
|
||||
fixture_get_free_round(first_week + (len - 1 + i) * week_gap, clid),
|
||||
clid, cup_round, 0, home_advantage, FALSE, FALSE);
|
||||
|
||||
g_ptr_array_free(teams, TRUE);
|
||||
}
|
||||
|
||||
/** Write one matchday of round robin games.
|
||||
@ -488,6 +498,8 @@ fixture_write_knockout_round(Cup *cup, gint cup_round, GPtrArray *teams)
|
||||
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_number : -1;
|
||||
cup->next_fixture_update_week_round = (cup_round < cup->rounds->len - 1 || round->replay > 0) ?
|
||||
g_array_index(cup->fixtures, Fixture, cup->fixtures->len - 1).week_round_number : -1;
|
||||
|
||||
g_ptr_array_free(teams, TRUE);
|
||||
}
|
||||
|
||||
/** Write a fixture and append it to a fixture array.
|
||||
@ -632,8 +644,7 @@ gboolean
|
||||
query_fixture_has_tables(const Fixture *fix)
|
||||
{
|
||||
return (fix->clid < ID_CUP_START ||
|
||||
g_array_index(cup_from_clid(fix->clid)->rounds, CupRound, fix->round).
|
||||
round_robin_number_of_groups != 0);
|
||||
cup_has_tables(fix->clid) == fix->round);
|
||||
}
|
||||
|
||||
/** Find out whether there were games in the specified league
|
||||
|
33
src/free.c
33
src/free.c
@ -310,7 +310,7 @@ free_cups_array(GArray **cups, gboolean reset)
|
||||
void
|
||||
free_cup(Cup *cup)
|
||||
{
|
||||
gint i;
|
||||
gint i, j;
|
||||
GString **strings[4] =
|
||||
{&cup->name,
|
||||
&cup->short_name,
|
||||
@ -323,6 +323,11 @@ free_cup(Cup *cup)
|
||||
for(i=0;i<4;i++)
|
||||
free_g_string(strings[i]);
|
||||
|
||||
for(i=0;i<cup->rounds->len;i++)
|
||||
if(g_array_index(cup->rounds, CupRound, i).round_robin_number_of_groups > 0)
|
||||
for(j=0;j<g_array_index(cup->rounds, CupRound, i).tables->len;j++)
|
||||
free_table(&g_array_index(g_array_index(cup->rounds, CupRound, i).tables, Table, j));
|
||||
|
||||
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));
|
||||
@ -337,32 +342,6 @@ free_cup(Cup *cup)
|
||||
|
||||
free_g_ptr_array(&cup->bye);
|
||||
free_g_ptr_array(&cup->user_teams);
|
||||
|
||||
free_cup_tables(cup->tables, FALSE);
|
||||
}
|
||||
|
||||
/** Free the memory occupied by the cup tables.
|
||||
@param tables The array containing the tables. */
|
||||
void
|
||||
free_cup_tables(GArray *tables, gboolean reset)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if(tables == NULL)
|
||||
{
|
||||
if(reset)
|
||||
tables = g_array_new(FALSE, FALSE, sizeof(Table));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for(i=0;i<tables->len;i++)
|
||||
free_table(&g_array_index(tables, Table, i));
|
||||
|
||||
free_g_array(&tables);
|
||||
|
||||
if(reset)
|
||||
tables = g_array_new(FALSE, FALSE, sizeof(Table));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -320,7 +320,7 @@ game_assign_attendance(Fixture *fix)
|
||||
tm[0]->stadium.capacity);
|
||||
|
||||
if(fix->clid < ID_CUP_START &&
|
||||
team_rank(tm[1], fix->clid) <
|
||||
team_get_league_rank(tm[1]) <
|
||||
(gint)rint((gfloat)league_from_clid(fix->clid)->teams->len *
|
||||
const_float("float_game_stadium_attendance_rank_percentage")))
|
||||
factor *= const_float("float_game_stadium_attendance_rank_factor");
|
||||
|
@ -195,7 +195,7 @@ game_gui_set_main_window_header(void)
|
||||
gtk_label_set_text(label_money, buf);
|
||||
|
||||
gui_label_set_text_from_int(label_rank,
|
||||
team_rank(current_user.tm, current_user.tm->clid), FALSE);
|
||||
team_get_league_rank(current_user.tm), FALSE);
|
||||
|
||||
gtk_label_set_text(label_team, current_user.tm->name->str);
|
||||
gtk_label_set_text(label_league, league_from_clid(current_user.tm->clid)->name->str);
|
||||
@ -470,7 +470,7 @@ game_gui_show_job_offer(Team *team, gint type)
|
||||
gtk_label_set_text(label_text2, buf2);
|
||||
gtk_label_set_text(label_name, team->name->str);
|
||||
gtk_label_set_text(label_league, league_from_clid(team->clid)->name->str);
|
||||
gui_label_set_text_from_int(label_rank, team_rank(team, team->clid), FALSE);
|
||||
gui_label_set_text_from_int(label_rank, team_get_league_rank(team), FALSE);
|
||||
misc_print_grouped_int(math_round_integer(team->stadium.capacity *
|
||||
math_rndi(const_int("int_initial_money_lower"),
|
||||
const_int("int_initial_money_upper")), 2),
|
||||
|
@ -471,7 +471,7 @@ query_league_prom_games_begin(const League *league)
|
||||
gboolean proceed = FALSE;
|
||||
|
||||
for(i=0;i<league->prom_rel.prom_games_cup.choose_teams->len;i++)
|
||||
{
|
||||
{
|
||||
for(j=0;j<ligs->len;j++)
|
||||
if(strcmp(lig(j).sid->str,
|
||||
g_array_index(league->prom_rel.prom_games_cup.choose_teams,
|
||||
|
@ -66,6 +66,11 @@ start_new_season(void)
|
||||
/*todo: nullify, promotion/relegation*/
|
||||
if(season > 1)
|
||||
{
|
||||
for(i=0;i<users->len;i++)
|
||||
user_history_add(&usr(i), USER_HISTORY_END_SEASON,
|
||||
usr(i).team_id, usr(i).tm->clid,
|
||||
team_get_league_rank(usr(i).tm), "");
|
||||
|
||||
start_new_season_team_movements();
|
||||
|
||||
for(i=0;i<users->len;i++)
|
||||
@ -253,14 +258,14 @@ end_week_round_sort_tables(void)
|
||||
GINT_TO_POINTER(lig(i).id));
|
||||
|
||||
for(i=0;i<acps->len;i++)
|
||||
if(acp(i)->tables != NULL && acp(i)->tables->len != 0 &&
|
||||
query_fixture_in_week_round(acp(i)->id, week, week_round) &&
|
||||
if(query_fixture_in_week_round(acp(i)->id, week, week_round) &&
|
||||
g_array_index(acp(i)->fixtures, Fixture, acp(i)->fixtures->len - 1).round ==
|
||||
g_array_index(acp(i)->tables, Table, 0).round)
|
||||
for(j=0;j<acp(i)->tables->len;j++)
|
||||
g_array_sort_with_data(g_array_index(acp(i)->tables, Table, j).elements,
|
||||
(GCompareDataFunc)table_element_compare_func,
|
||||
GINT_TO_POINTER(acp(i)->id));
|
||||
cup_has_tables(acp(i)->id))
|
||||
for(j=0;j<cup_get_last_tables(acp(i)->id)->len;j++)
|
||||
g_array_sort_with_data(
|
||||
g_array_index(cup_get_last_tables(acp(i)->id), Table, j).elements,
|
||||
(GCompareDataFunc)table_element_compare_func,
|
||||
GINT_TO_POINTER(acp(i)->id));
|
||||
}
|
||||
|
||||
/** Update cup fixtures. */
|
||||
@ -285,7 +290,12 @@ end_week_round_update_fixtures(void)
|
||||
fixture_write_cup_fixtures(&lig(i).prom_rel.prom_games_cup);
|
||||
g_ptr_array_add(acps, &lig(i).prom_rel.prom_games_cup);
|
||||
}
|
||||
|
||||
else if(week == (lig(i).teams->len - 1) * 2 && week_round == 1 &&
|
||||
team_is_user(g_array_index(lig(i).table.elements, TableElement, 0).team) != -1)
|
||||
user_history_add(&usr(team_is_user(g_array_index(lig(i).table.elements, TableElement, 0).team)),
|
||||
USER_HISTORY_CHAMPION, g_array_index(lig(i).table.elements, TableElement, 0).team_id,
|
||||
lig(i).id, -1, "");
|
||||
|
||||
for(i=0;i<scps->len;i++)
|
||||
{
|
||||
if(query_cup_supercup_begins(&scp(i)))
|
||||
|
@ -94,9 +94,10 @@ table_update_get_elements(TableElement **elements, const Fixture *fix)
|
||||
}
|
||||
}
|
||||
else
|
||||
for(i=0;i<cup_from_clid(fix->clid)->tables->len;i++)
|
||||
for(i=0;i<cup_get_last_tables(fix->clid)->len;i++)
|
||||
{
|
||||
table = &g_array_index(cup_from_clid(fix->clid)->tables, Table, i);
|
||||
table = &g_array_index(cup_get_last_tables(fix->clid), Table, i);
|
||||
|
||||
if(elements[0] == NULL || elements[1] == NULL)
|
||||
for(j=0;j<table->elements->len;j++)
|
||||
{
|
||||
@ -134,7 +135,7 @@ table_element_compare_func(gconstpointer a,
|
||||
if(clid < ID_CUP_START)
|
||||
cup_round = -1;
|
||||
else
|
||||
cup_round = g_array_index(cup_from_clid(clid)->tables, Table, 0).round;
|
||||
cup_round = cup_has_tables(clid);
|
||||
|
||||
/*todo use misc_int_compare*/
|
||||
if(element1->values[TABLE_PTS] > element2->values[TABLE_PTS])
|
||||
@ -175,7 +176,7 @@ table_element_compare_func(gconstpointer a,
|
||||
}
|
||||
|
||||
if(fix[0] == NULL || fix[1] == NULL)
|
||||
value = -1;
|
||||
value = 0;
|
||||
else
|
||||
{
|
||||
if(fix[0]->result[0][0] + fix[1]->result[1][0] >
|
||||
|
45
src/team.c
45
src/team.c
@ -450,33 +450,36 @@ team_get_average_skill(const Team *tm, gboolean cskill)
|
||||
return (counter > 0) ? sum / (gfloat)counter : 0;
|
||||
}
|
||||
|
||||
/** Return the rank of the team.
|
||||
@param tm The team we examine.
|
||||
@param clid The league or cup we browse the table of. */
|
||||
/** Return the rank of the team in the league tables. */
|
||||
gint
|
||||
team_rank(const Team *tm, gint clid)
|
||||
team_get_league_rank(const Team *tm)
|
||||
{
|
||||
gint i;
|
||||
GArray *elements = league_from_clid(tm->clid)->table.elements;
|
||||
|
||||
for(i=0;i<elements->len;i++)
|
||||
if(g_array_index(elements, TableElement, i).team == tm)
|
||||
return i + 1;
|
||||
|
||||
g_warning("team_get_league_rank: no rank found for team %s in league %s. \n",
|
||||
tm->name->str, league_cup_get_name_string(tm->clid));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Return the rank of the team in the round robin stage. */
|
||||
gint
|
||||
team_get_cup_rank(const Team *tm, const CupRound *cupround)
|
||||
{
|
||||
gint i, j;
|
||||
GArray *elements = NULL;
|
||||
|
||||
if(clid < ID_CUP_START)
|
||||
for(i=0;i<cupround->tables->len;i++)
|
||||
{
|
||||
elements = league_from_clid(clid)->table.elements;
|
||||
for(i=0;i<elements->len;i++)
|
||||
if(g_array_index(elements, TableElement, i).team == tm)
|
||||
return i + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0;i<cup_from_clid(clid)->tables->len;i++)
|
||||
{
|
||||
elements = g_array_index(cup_from_clid(clid)->tables, Table, i).elements;
|
||||
for(j=0;j<elements->len;j++)
|
||||
if(g_array_index(elements, TableElement, j).team == tm)
|
||||
return j + 1;
|
||||
}
|
||||
for(j=0;j<g_array_index(cupround->tables, Table, i).elements->len;j++)
|
||||
if(g_array_index(g_array_index(cupround->tables, Table, i).elements, TableElement, j).team == tm)
|
||||
return j + 1;
|
||||
}
|
||||
|
||||
g_warning("team_get_cup_rank: no rank found for team %s. \n ", tm->name->str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -780,7 +783,7 @@ team_compare_func(gconstpointer a, gconstpointer b, gpointer data)
|
||||
if(type == TEAM_COMPARE_LEAGUE_RANK)
|
||||
{
|
||||
if(tm1->clid == tm2->clid)
|
||||
return_value = misc_int_compare(team_rank(tm2, tm2->clid), team_rank(tm1, tm1->clid));
|
||||
return_value = misc_int_compare(team_get_league_rank(tm2), team_get_league_rank(tm1));
|
||||
else
|
||||
return_value = misc_int_compare(
|
||||
league_cup_get_index_from_clid(tm2->clid),
|
||||
|
@ -73,7 +73,10 @@ gint
|
||||
team_is_user(const Team *tm);
|
||||
|
||||
gint
|
||||
team_rank(const Team *tm, gint clid);
|
||||
team_get_cup_rank(const Team *tm, const CupRound *cupround);
|
||||
|
||||
gint
|
||||
team_get_league_rank(const Team *tm);
|
||||
|
||||
void
|
||||
team_change_structure(Team *tm, gint new_structure);
|
||||
|
@ -863,7 +863,7 @@ treeview_create_fixtures_header(const Fixture *fix, GtkListStore *liststore, gbo
|
||||
void
|
||||
treeview_create_fixture(const Fixture *fix, GtkListStore *liststore)
|
||||
{
|
||||
gint i;
|
||||
gint i, rank;
|
||||
GtkTreeIter iter;
|
||||
GdkPixbuf *symbol[2] = {NULL, NULL};
|
||||
gchar buf_result[SMALL], buf[3][SMALL];
|
||||
@ -896,10 +896,16 @@ treeview_create_fixture(const Fixture *fix, GtkListStore *liststore)
|
||||
fixture_result_to_buf(fix, buf_result);
|
||||
|
||||
for(i=0;i<2;i++)
|
||||
if(team_rank(fix->teams[i], fix->clid) != -1)
|
||||
if(query_fixture_has_tables(fix))
|
||||
{
|
||||
if(fix->clid < ID_CUP_START)
|
||||
rank = team_get_league_rank(fix->teams[i]);
|
||||
else
|
||||
rank = team_get_cup_rank(fix->teams[i], cup_get_last_tables_round(fix->clid));
|
||||
|
||||
sprintf(buf[i], "<span background='%s' foreground='%s'>%s [%d]</span>",
|
||||
colour_bg, colour_fg, fix->teams[i]->name->str,
|
||||
team_rank(fix->teams[i], fix->clid));
|
||||
colour_bg, colour_fg, fix->teams[i]->name->str, rank);
|
||||
}
|
||||
else if(fix->clid >= ID_CUP_START &&
|
||||
cup_from_clid(fix->clid)->type == CUP_TYPE_NATIONAL)
|
||||
sprintf(buf[i], "<span background='%s' foreground='%s'>%s (%d)</span>",
|
||||
@ -1067,6 +1073,7 @@ treeview_create_single_table(GtkListStore *liststore, const Table *table, gint n
|
||||
gtk_list_store_append(liststore, &iter);
|
||||
|
||||
elem = &g_array_index(table->elements, TableElement, i);
|
||||
|
||||
if(table->clid >= ID_CUP_START)
|
||||
symbol = treeview_helper_pixbuf_from_filename(elem->team->symbol->str);
|
||||
|
||||
@ -1105,7 +1112,6 @@ GtkTreeModel*
|
||||
treeview_create_table(gint clid)
|
||||
{
|
||||
gint i;
|
||||
GArray *tables = NULL;
|
||||
GtkListStore *liststore =
|
||||
gtk_list_store_new(11,
|
||||
GDK_TYPE_PIXBUF,
|
||||
@ -1119,15 +1125,15 @@ treeview_create_table(gint clid)
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING,
|
||||
G_TYPE_STRING);
|
||||
|
||||
|
||||
if(clid < ID_CUP_START)
|
||||
treeview_create_single_table(liststore,
|
||||
&league_from_clid(clid)->table, -1);
|
||||
else
|
||||
{
|
||||
tables = cup_from_clid(clid)->tables;
|
||||
for(i=0;i<tables->len;i++)
|
||||
treeview_create_single_table(liststore, &g_array_index(tables, Table, i), i + 1);
|
||||
for(i=0;i<cup_get_last_tables(clid)->len;i++)
|
||||
treeview_create_single_table(liststore,
|
||||
&g_array_index(cup_get_last_tables(clid), Table, i), i + 1);
|
||||
}
|
||||
|
||||
return GTK_TREE_MODEL(liststore);
|
||||
@ -1543,7 +1549,7 @@ treeview_create_next_opponent(void)
|
||||
|
||||
if(opp->clid < ID_CUP_START)
|
||||
{
|
||||
sprintf(buf, "%d (%s)", team_rank(opp, opp->clid), league_from_clid(opp->clid)->name->str);
|
||||
sprintf(buf, "%d (%s)", team_get_league_rank(opp), league_cup_get_name_string(opp->clid));
|
||||
gtk_list_store_append(liststore, &iter);
|
||||
gtk_list_store_set(liststore, &iter, 0, _("Rank"), 1, buf, -1);
|
||||
}
|
||||
|
@ -255,6 +255,8 @@ treeview_helper_get_user_history_icon(gint history_type)
|
||||
return const_str("string_treeview_helper_user_history_symbol_relegated");
|
||||
case USER_HISTORY_REACH_CUP_ROUND:
|
||||
return const_str("string_treeview_helper_user_history_symbol_reach_cup_round");
|
||||
case USER_HISTORY_CHAMPION:
|
||||
return const_str("string_treeview_helper_user_history_symbol_champion");
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -427,6 +427,7 @@ void
|
||||
user_change_team(User *user, Team *tm)
|
||||
{
|
||||
gint i;
|
||||
|
||||
user->tm = tm;
|
||||
user->team_id = tm->id;
|
||||
|
||||
@ -528,7 +529,6 @@ user_history_add(User *user, gint type, gint team_id,
|
||||
his->season = season;
|
||||
his->week = week;
|
||||
|
||||
/*todo: check for old cup comp */
|
||||
his->type = type;
|
||||
his->team_id = team_id;
|
||||
his->value1 = value1;
|
||||
@ -552,7 +552,7 @@ void
|
||||
user_history_to_string(const UserHistory *history, gchar *buf)
|
||||
{
|
||||
gchar buf2[SMALL];
|
||||
|
||||
|
||||
switch(history->type)
|
||||
{
|
||||
default:
|
||||
@ -610,5 +610,9 @@ user_history_to_string(const UserHistory *history, gchar *buf)
|
||||
history->value2 + 1,
|
||||
league_cup_get_name_string(history->value1));
|
||||
break;
|
||||
case USER_HISTORY_CHAMPION:
|
||||
sprintf(buf, "You are champion of the %s!",
|
||||
league_cup_get_name_string(history->value1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +128,7 @@ enum UserHistoryType
|
||||
USER_HISTORY_WIN_FINAL,
|
||||
USER_HISTORY_LOSE_FINAL,
|
||||
USER_HISTORY_REACH_CUP_ROUND,
|
||||
USER_HISTORY_CHAMPION,
|
||||
USER_HISTORY_END
|
||||
};
|
||||
|
||||
|
27
src/xml.c
27
src/xml.c
@ -153,9 +153,9 @@ xml_load_cups(const gchar *dirname, const gchar *basename)
|
||||
void
|
||||
xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrArray *dir_contents)
|
||||
{
|
||||
gint i;
|
||||
gchar buf[SMALL];
|
||||
gint i, j;
|
||||
Table new_table;
|
||||
gchar buf[SMALL];
|
||||
gchar *prefix = g_strndup(basename, strlen(basename) - 4);
|
||||
Cup *local_cup = cup;
|
||||
|
||||
@ -188,20 +188,19 @@ xml_load_cup(Cup *cup, const gchar *dirname, const gchar *basename, const GPtrAr
|
||||
sprintf(buf, "%s/%s_fixtures.xml", dirname, prefix);
|
||||
xml_loadsave_fixtures_read(buf, local_cup->fixtures);
|
||||
|
||||
for(i=0;i<dir_contents->len;i++)
|
||||
{
|
||||
if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, i))->str,
|
||||
prefix) &&
|
||||
query_misc_string_contains(((GString*)g_ptr_array_index(dir_contents, i))->str,
|
||||
"_table"))
|
||||
for(i=0;i<local_cup->rounds->len;i++)
|
||||
for(j=0;j<dir_contents->len;j++)
|
||||
{
|
||||
new_table = table_new();
|
||||
sprintf(buf, "%s/%s", dirname,
|
||||
((GString*)g_ptr_array_index(dir_contents, i))->str);
|
||||
xml_loadsave_table_read(buf, &new_table);
|
||||
g_array_append_val(local_cup->tables, new_table);
|
||||
sprintf(buf, "%s_round_%02d_table", prefix, i);
|
||||
if(g_str_has_prefix(((GString*)g_ptr_array_index(dir_contents, j))->str,
|
||||
buf))
|
||||
{
|
||||
sprintf(buf, "%s/%s", dirname, ((GString*)g_ptr_array_index(dir_contents, j))->str);
|
||||
new_table = table_new();
|
||||
xml_loadsave_table_read(buf, &new_table);
|
||||
g_array_append_val(g_array_index(local_cup->rounds, CupRound, i).tables, new_table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_free(prefix);
|
||||
}
|
||||
|
@ -359,14 +359,6 @@ xml_cup_read(const gchar *cup_name, GArray *cups)
|
||||
misc_print_error(&error, TRUE);
|
||||
}
|
||||
|
||||
if(g_array_index(new_cup.rounds, CupRound, new_cup.rounds->len - 1).
|
||||
round_robin_number_of_groups != 0)
|
||||
{
|
||||
sprintf(buf, "xml_cup_read: last cup round of cup %s is round robin which is forbidden.\n",
|
||||
new_cup.name->str);
|
||||
main_exit_program(EXIT_CUP_LAST_ROUND, buf);
|
||||
}
|
||||
|
||||
if(cups == cps)
|
||||
new_cup.id = cup_id_new;
|
||||
else if(cups == scps)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "cup.h"
|
||||
#include "file.h"
|
||||
#include "misc.h"
|
||||
#include "table.h"
|
||||
#include "team.h"
|
||||
#include "xml.h"
|
||||
#include "xml_loadsave_cup.h"
|
||||
@ -263,12 +264,6 @@ xml_loadsave_cup_write(const gchar *prefix, const Cup *cup)
|
||||
gchar buf[SMALL];
|
||||
FILE *fil = NULL;
|
||||
|
||||
for(i=0;i<cup->tables->len;i++)
|
||||
{
|
||||
sprintf(buf, "%s___cup_%d_table_%02d.xml", prefix, cup->id, i);
|
||||
xml_loadsave_table_write(buf, &g_array_index(cup->tables, Table, i));
|
||||
}
|
||||
|
||||
sprintf(buf, "%s___cup_%d_fixtures.xml", prefix, cup->id);
|
||||
xml_loadsave_fixtures_write(buf, cup->fixtures);
|
||||
|
||||
@ -317,8 +312,7 @@ xml_loadsave_cup_write(const gchar *prefix, const Cup *cup)
|
||||
&g_array_index(cup->choose_teams, CupChooseTeam, i));
|
||||
|
||||
for(i=0;i<cup->rounds->len;i++)
|
||||
xml_loadsave_cup_write_round(fil,
|
||||
&g_array_index(cup->rounds, CupRound, i));
|
||||
xml_loadsave_cup_write_round(fil, prefix, cup, i);
|
||||
|
||||
if(cup->bye != NULL)
|
||||
{
|
||||
@ -355,8 +349,12 @@ xml_loadsave_cup_write_choose_team(FILE *fil, const CupChooseTeam *choose_team)
|
||||
}
|
||||
|
||||
void
|
||||
xml_loadsave_cup_write_round(FILE *fil, const CupRound *cup_round)
|
||||
xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gint round)
|
||||
{
|
||||
gint i;
|
||||
gchar buf[SMALL];
|
||||
const CupRound *cup_round = &g_array_index(cup->rounds, CupRound, round);
|
||||
|
||||
fprintf(fil, "<_%d>\n", TAG_CUP_ROUND);
|
||||
|
||||
xml_write_int(fil, cup_round->home_away,
|
||||
@ -373,4 +371,10 @@ xml_loadsave_cup_write_round(FILE *fil, const CupRound *cup_round)
|
||||
TAG_CUP_ROUND_ROUND_ROBIN_NUMBER_OF_BEST_ADVANCE, I1);
|
||||
|
||||
fprintf(fil, "</_%d>\n", TAG_CUP_ROUND);
|
||||
|
||||
for(i=0;i<cup_round->tables->len;i++)
|
||||
{
|
||||
sprintf(buf, "%s___cup_%d_round_%02d_table_%02d.xml", prefix, cup->id, round, i);
|
||||
xml_loadsave_table_write(buf, &g_array_index(cup_round->tables, Table, i));
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ void
|
||||
xml_loadsave_cup_write(const gchar *prefix, const Cup *cup);
|
||||
|
||||
void
|
||||
xml_loadsave_cup_write_round(FILE *fil, const CupRound *cup_round);
|
||||
xml_loadsave_cup_write_round(FILE *fil, const gchar *prefix, const Cup *cup, gint round);
|
||||
|
||||
void
|
||||
xml_loadsave_cup_write_choose_team(FILE *fil, const CupChooseTeam *choose_team);
|
||||
|
@ -21,7 +21,7 @@ int_opt_player_precision 0
|
||||
int_opt_live_game_player_list_refresh 48
|
||||
|
||||
# whether some debugging info's shown (in the console)
|
||||
int_opt_debug 60
|
||||
int_opt_debug 0
|
||||
|
||||
string_opt_player_names_file player_names.xml
|
||||
string_opt_constants_file bygfoot_constants
|
||||
|
@ -774,3 +774,4 @@ string_treeview_helper_user_history_symbol_reach_cup_round
|
||||
string_treeview_helper_user_history_symbol_job_offer_accepted
|
||||
string_treeview_helper_user_history_symbol_promoted
|
||||
string_treeview_helper_user_history_symbol_relegated
|
||||
string_treeview_helper_user_history_symbol_champion
|
||||
|
@ -5,10 +5,27 @@
|
||||
<sid>belgium</sid>
|
||||
<type>national</type>
|
||||
<yellow_red>3</yellow_red>
|
||||
<last_week>38</last_week>
|
||||
<week_gap>2</week_gap>
|
||||
<last_week>35</last_week>
|
||||
<week_gap>3</week_gap>
|
||||
<cup_rounds>
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
@ -18,18 +35,8 @@
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
</cup_round>
|
||||
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
<neutral>1</neutral>
|
||||
</cup_round>
|
||||
</cup_rounds>
|
||||
|
||||
|
@ -8,11 +8,7 @@
|
||||
<cup_rounds>
|
||||
<cup_round>
|
||||
<number_of_groups>1</number_of_groups>
|
||||
<number_of_advance>2</number_of_advance>
|
||||
</cup_round>
|
||||
<cup_round>
|
||||
<home_away>0</home_away>
|
||||
<neutral>1</neutral>
|
||||
<number_of_advance>1</number_of_advance>
|
||||
</cup_round>
|
||||
</cup_rounds>
|
||||
<choose_teams>
|
||||
|
@ -30,11 +30,6 @@
|
||||
<prom_rel_type>promotion</prom_rel_type>
|
||||
</prom_rel_element>
|
||||
|
||||
<!-- <prom_games> -->
|
||||
<!-- <prom_games_dest_sid>belgium2</prom_games_dest_sid> -->
|
||||
<!-- <cup>belgium_eindronde3</cup> -->
|
||||
<!-- </prom_games> -->
|
||||
|
||||
</prom_rel>
|
||||
|
||||
<teams>
|
||||
|
@ -30,10 +30,6 @@
|
||||
<prom_rel_type>promotion</prom_rel_type>
|
||||
</prom_rel_element>
|
||||
|
||||
<!-- <prom_games> -->
|
||||
<!-- <prom_games_dest_sid>belgium2</prom_games_dest_sid> -->
|
||||
<!-- <cup>belgium_eindronde3</cup> -->
|
||||
<!-- </prom_games> -->
|
||||
</prom_rel>
|
||||
|
||||
<teams>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<league>
|
||||
<sid>belgium4d</sid>
|
||||
<name>Vierde klasse D</name>
|
||||
<name>Vierde klasse D</name>
|
||||
<short_name>4de kl. D</short_name>
|
||||
<symbol>flag_be.png</symbol>
|
||||
<first_week>1</first_week>
|
||||
|
Loading…
x
Reference in New Issue
Block a user