mirror of
https://github.com/tstellar/bygfoot.git
synced 2025-02-04 09:48:00 +01:00
Remove team_ids field from Fixture object
We can fetch the ids from the teams object instead.
This commit is contained in:
parent
47fa16ddcd
commit
a23db0b434
28
src/cup.c
28
src/cup.c
@ -723,10 +723,7 @@ cup_load_choose_team_generate(Cup *cup, CupRound *cup_round, const CupChooseTeam
|
||||
}
|
||||
|
||||
/** Return a pointer array of teams ordered corresponding to
|
||||
their success in the cup. A bit tricky because we have to
|
||||
fetch the team pointers corresponding to their name because
|
||||
the team pointers in the fixtures are partially invalid because
|
||||
of promotion relegation. */
|
||||
their success in the cup. */
|
||||
GPtrArray*
|
||||
cup_get_teams_sorted(const Cup *cup)
|
||||
{
|
||||
@ -736,21 +733,18 @@ cup_get_teams_sorted(const Cup *cup)
|
||||
|
||||
gint i, j;
|
||||
GPtrArray *teams = g_ptr_array_new();
|
||||
GArray *team_ids = g_array_new(FALSE, FALSE, sizeof(gint));
|
||||
|
||||
for(i=0;i<cup->fixtures->len;i++)
|
||||
for(j=0;j<2;j++)
|
||||
if(!query_misc_integer_is_in_g_array(
|
||||
g_array_index(cup->fixtures, Fixture, i).team_ids[j], team_ids))
|
||||
{
|
||||
g_array_append_val(team_ids, g_array_index(cup->fixtures, Fixture, i).team_ids[j]);
|
||||
g_ptr_array_add(teams, team_of_id(g_array_index(cup->fixtures, Fixture, i).team_ids[j]));
|
||||
for(i=0;i<cup->fixtures->len;i++) {
|
||||
const Fixture *fixture = &g_array_index(cup->fixtures, Fixture, i);
|
||||
for(j=0;j<2;j++) {
|
||||
Team *team = fixture->teams[j];
|
||||
if (misc_g_ptr_array_find(teams, team, NULL))
|
||||
continue;
|
||||
g_ptr_array_add(teams, team);
|
||||
}
|
||||
}
|
||||
|
||||
g_ptr_array_sort_with_data(teams, cup_compare_success, (gpointer)cup);
|
||||
|
||||
g_array_free(team_ids, TRUE);
|
||||
|
||||
return teams;
|
||||
}
|
||||
|
||||
@ -876,8 +870,8 @@ cup_get_round_reached(const Team *tm, const GArray *fixtures)
|
||||
gint i;
|
||||
|
||||
for(i=0;i<fixtures->len;i++)
|
||||
if(g_array_index(fixtures, Fixture, i).team_ids[0] == tm->id ||
|
||||
g_array_index(fixtures, Fixture, i).team_ids[1] == tm->id)
|
||||
if(g_array_index(fixtures, Fixture, i).teams[0] == tm ||
|
||||
g_array_index(fixtures, Fixture, i).teams[1] == tm)
|
||||
round = MAX(round, g_array_index(fixtures, Fixture, i).round);
|
||||
|
||||
return round;
|
||||
|
@ -317,7 +317,7 @@ fixture_winner_of(const Fixture *fix, gboolean team_id)
|
||||
{
|
||||
winner_idx = (fix->result[0][0] < fix->result[1][0]);
|
||||
if(team_id)
|
||||
return GINT_TO_POINTER(fix->team_ids[winner_idx]);
|
||||
return GINT_TO_POINTER(fix->teams[winner_idx]->id);
|
||||
else
|
||||
return (gpointer)fix->teams[winner_idx];
|
||||
}
|
||||
@ -350,7 +350,7 @@ fixture_winner_of(const Fixture *fix, gboolean team_id)
|
||||
}
|
||||
|
||||
if(team_id)
|
||||
return GINT_TO_POINTER(fix->team_ids[winner_idx]);
|
||||
return GINT_TO_POINTER(fix->teams[winner_idx]->id);
|
||||
else
|
||||
return (gpointer)fix->teams[winner_idx];
|
||||
}
|
||||
@ -521,7 +521,6 @@ fixture_write_round_robin(gpointer league_cup, gint cup_round,
|
||||
gint len = teams->len;
|
||||
GArray *fixtures = NULL;
|
||||
GArray **two_match_weeks;
|
||||
Team team_temp;
|
||||
gboolean odd_fixtures = FALSE;
|
||||
|
||||
teams = misc_randomise_g_pointer_array(teams);
|
||||
@ -795,8 +794,6 @@ fixture_write(GArray *fixtures, Team *home_team, Team *away_team, gint week_numb
|
||||
new.week_round_number = week_round_number;
|
||||
new.teams[0] = home_team;
|
||||
new.teams[1] = away_team;
|
||||
new.team_ids[0] = home_team->id;
|
||||
new.team_ids[1] = away_team->id;
|
||||
new.live_game = NULL;
|
||||
|
||||
for(i=0;i<3;i++)
|
||||
@ -999,8 +996,8 @@ fixture_get_first_leg(const Fixture *fix, gboolean silent)
|
||||
if(g_array_index(cup_from_clid(fix->clid)->rounds, CupRound, fix->round).round_robin_number_of_groups == 0)
|
||||
for(i=0;i<fixtures->len;i++)
|
||||
if(g_array_index(fixtures, Fixture, i).round == fix->round &&
|
||||
g_array_index(fixtures, Fixture, i).team_ids[0] == fix->team_ids[1] &&
|
||||
g_array_index(fixtures, Fixture, i).team_ids[1] == fix->team_ids[0])
|
||||
g_array_index(fixtures, Fixture, i).teams[0] == fix->teams[1] &&
|
||||
g_array_index(fixtures, Fixture, i).teams[1] == fix->teams[0])
|
||||
first_leg = &g_array_index(fixtures, Fixture, i);
|
||||
|
||||
if(first_leg == NULL && !silent)
|
||||
@ -1834,8 +1831,9 @@ fixture_refresh_team_pointers(GArray *fixtures)
|
||||
|
||||
for(i = 0; i < fixtures->len; i++)
|
||||
{
|
||||
for(j = 0; j < 2; j++)
|
||||
g_array_index(fixtures, Fixture, i).teams[j] =
|
||||
team_of_id(g_array_index(fixtures, Fixture, i).team_ids[j]);
|
||||
Fixture *fixture = &g_array_index(fixtures, Fixture, i);
|
||||
for(j = 0; j < 2; j++) {
|
||||
fixture->teams[j] = team_of_id(GPOINTER_TO_INT(fixture->teams[j]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ enum FixtureCompare
|
||||
};
|
||||
|
||||
/** Check whether the team with given id participates in the fixture. */
|
||||
#define query_fixture_team_involved(fix, team_id) (fix->team_ids[0] == team_id || fix->team_ids[1] == team_id)
|
||||
#define query_fixture_team_involved(fix, team_id) (fix->teams[0]->id == team_id || fix->teams[1]->id == team_id)
|
||||
|
||||
void
|
||||
fixture_write_league_fixtures(League *league);
|
||||
|
@ -45,9 +45,6 @@ typedef struct
|
||||
gint week_number, week_round_number;
|
||||
/** The teams involved. */
|
||||
Team *teams[2];
|
||||
/** Ids of the teams. Needed when the team
|
||||
pointers get invalid (e.g. after promotion/relegation). */
|
||||
gint team_ids[2];
|
||||
/** The number of goals for each team in
|
||||
regulation, extra time and penalty shoot-out. */
|
||||
gint result[2][3];
|
||||
|
@ -548,12 +548,10 @@ bygfoot_json_fixture_to_json(const Fixture *fixture)
|
||||
json_object_object_add(fixture_obj, "week", json_object_new_int64(fixture->week_number));
|
||||
json_object_object_add(fixture_obj, "round", json_object_new_int64(fixture->week_round_number));
|
||||
|
||||
json_object_object_add(home_team_obj, "id", json_object_new_int64(fixture->team_ids[0]));
|
||||
json_object_object_add(home_team_obj, "stats",
|
||||
bygfoot_json_fixture_stats_to_json(fixture, 0));
|
||||
json_object_object_add(fixture_obj, "home_team", home_team_obj);
|
||||
|
||||
json_object_object_add(away_team_obj, "id", json_object_new_int64(fixture->team_ids[1]));
|
||||
json_object_object_add(away_team_obj, "stats",
|
||||
bygfoot_json_fixture_stats_to_json(fixture, 1));
|
||||
json_object_object_add(fixture_obj, "away_team", away_team_obj);
|
||||
|
@ -1488,7 +1488,6 @@ bygfoot_json_serialize_fixture(const Fixture *fixture)
|
||||
SERIALIZE(week_number, json_object_new_int64);
|
||||
SERIALIZE(week_round_number, json_object_new_int64);
|
||||
SERIALIZE(teams, bygfoot_json_serialize_fixture_teams);
|
||||
json_object_object_add(fixture_obj, "team_ids", serialize_int_array(fixture->team_ids, 2));
|
||||
SERIALIZE(result, bygfoot_json_serialize_fixture_result);
|
||||
SERIALIZE(home_advantage, json_object_new_boolean);
|
||||
SERIALIZE(second_leg, json_object_new_boolean);
|
||||
|
20
src/misc.c
20
src/misc.c
@ -213,6 +213,26 @@ misc_g_ptr_array_insert(GPtrArray *array, gint _index, gpointer data)
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Search for \p needle in \p haystack. If \p needle is found \p index is
|
||||
* set to the index of \p neelde in \p haystack and TRUE is returned.
|
||||
* Otherwise, \p index_ is undefined and this function returns FALSE.*/
|
||||
gboolean
|
||||
misc_g_ptr_array_find(GPtrArray *haystack, gconstpointer needle, guint *index_)
|
||||
{
|
||||
#ifdef GLIB_VERSION_2_54
|
||||
return g_ptr_array_find(haystack, needle, index_);
|
||||
#else
|
||||
gint i;
|
||||
for (i = 0; i < haystack->len; i++) {
|
||||
if (g_ptr_array_index(haystack, i) == needle) {
|
||||
*index_ = i;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Print a thousands-grouped output of 'number' into 'buf',
|
||||
like 2 234 345 instead of 2234345.
|
||||
@param number The number to print.
|
||||
|
@ -101,6 +101,9 @@ misc_copy_ptr_array(const GPtrArray *array);
|
||||
void
|
||||
misc_extend_ptr_array(GPtrArray *dest, GPtrArray *src);
|
||||
|
||||
gboolean
|
||||
misc_g_ptr_array_find(GPtrArray *haystack, gconstpointer needle, guint *index_);
|
||||
|
||||
void
|
||||
misc_g_ptr_array_insert(GPtrArray *array, gint _index, gpointer data);
|
||||
|
||||
|
@ -233,11 +233,11 @@ table_element_compare_func(gconstpointer a,
|
||||
g_array_index(fixtures, Fixture, i).week_number <= week &&
|
||||
g_array_index(fixtures, Fixture, i).week_round_number <= week_round)
|
||||
{
|
||||
if(g_array_index(fixtures, Fixture, i).team_ids[0] == element1->team->id &&
|
||||
g_array_index(fixtures, Fixture, i).team_ids[1] == element2->team->id)
|
||||
if(g_array_index(fixtures, Fixture, i).teams[0] == element1->team &&
|
||||
g_array_index(fixtures, Fixture, i).teams[1] == element2->team)
|
||||
fix[0] = &g_array_index(fixtures, Fixture, i);
|
||||
else if(g_array_index(fixtures, Fixture, i).team_ids[1] == element1->team->id &&
|
||||
g_array_index(fixtures, Fixture, i).team_ids[0] == element2->team->id)
|
||||
else if(g_array_index(fixtures, Fixture, i).teams[1] == element1->team &&
|
||||
g_array_index(fixtures, Fixture, i).teams[0] == element2->team)
|
||||
fix[1] = &g_array_index(fixtures, Fixture, i);
|
||||
}
|
||||
}
|
||||
|
@ -1708,7 +1708,7 @@ treeview_helper_season_results(GtkTreeViewColumn *col,
|
||||
if(fix == NULL)
|
||||
return;
|
||||
|
||||
user_idx = (fix->team_ids[1] == current_user.tm->id);
|
||||
user_idx = (fix->teams[1] == current_user.tm);
|
||||
|
||||
if(column == 3)
|
||||
{
|
||||
|
@ -1217,7 +1217,7 @@ user_mm_add_last_match(gboolean load_file, gboolean save_file)
|
||||
|
||||
new.country_name = g_strdup(country.name);
|
||||
new.neutral = !(fix->home_advantage);
|
||||
new.user_team = (fix->team_ids[0] != current_user.team_id);
|
||||
new.user_team = (fix->teams[0]->id != current_user.team_id);
|
||||
new.lg = current_user.live_game;
|
||||
|
||||
/** This will tell the free function NOT
|
||||
|
@ -176,7 +176,7 @@ xml_loadsave_fixtures_text (GMarkupParseContext *context,
|
||||
else if(state == TAG_FIXTURE_RESULT)
|
||||
new_fixture.result[residx1][residx2] = int_value;
|
||||
else if(state == TAG_TEAM_ID)
|
||||
new_fixture.team_ids[teamidx] = int_value;
|
||||
new_fixture.teams[teamidx] = GINT_TO_POINTER(int_value);
|
||||
}
|
||||
|
||||
void
|
||||
@ -262,7 +262,7 @@ xml_loadsave_fixtures_write(const gchar *filename, const GArray *fixtures)
|
||||
TAG_FIXTURE_RESULT, I1);
|
||||
xml_write_int(fil, g_array_index(fixtures, Fixture, i).result[j][2],
|
||||
TAG_FIXTURE_RESULT, I1);
|
||||
xml_write_int(fil, g_array_index(fixtures, Fixture, i).team_ids[j],
|
||||
xml_write_int(fil, g_array_index(fixtures, Fixture, i).teams[j]->id,
|
||||
TAG_TEAM_ID, I1);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user