From 0f25c31ee5ac812c96f21e62d0f47daea6156135 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Sat, 20 Feb 2021 16:34:21 -0800 Subject: [PATCH] Fix bug in query_cup_begins() The function incorrectly assumed that cups where all the scheduled games had been played wre complete, and did not take into account the fact that games for later rounds may not have been scheduled yet. --- src/cup.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/cup.c b/src/cup.c index dd985086..696034c2 100644 --- a/src/cup.c +++ b/src/cup.c @@ -1235,19 +1235,34 @@ query_cup_begins(const Cup *cup) for(i=0;ichoose_teams->len;i++) if(!cup_choose_team_should_generate(&g_array_index(cup_round->choose_teams,CupChooseTeam, i))) { + const Fixture *last_fixture; cup_get_choose_team_league_cup( &g_array_index(cup_round->choose_teams, CupChooseTeam, i), &league, &cup_temp); - if((cup_temp == NULL && + if(cup_temp == NULL && query_league_active(league) && g_array_index(league->fixtures, Fixture, - league->fixtures->len - 1).attendance == -1) || - (league == NULL && - ((cup_temp->fixtures->len > 0 && - g_array_index(cup_temp->fixtures, Fixture, - cup_temp->fixtures->len - 1).attendance == -1) || - cup_temp->fixtures->len == 0))) + league->fixtures->len - 1).attendance == -1) + return FALSE; + + /* Handle cups */ + if (!cup_temp) + continue; + + if (!cup_temp->fixtures->len) + return FALSE; + + last_fixture = &g_array_index(cup_temp->fixtures, Fixture, + cup_temp->fixtures->len - 1); + + /* attendance == 1 means there are scheduled games that have + * not been played yet. If the last fixture is not for the + * last round of the cup that means there are still games + * that have not been scheduled yet. + */ + if (last_fixture->attendance == -1 || + last_fixture->round != cup_temp->rounds->len - 1) return FALSE; } }