mirror of https://github.com/tstellar/bygfoot.git
Allow the user's country's league sids in choose_team tags
This allows for consistent and accurate international cup definitions, because the draws will be the same no matter what the country a user has choosen. So now if a user is playing Faroe Islands, for example, a choose_team with an sid of faroe_islands1, will select a team from the Faroe Islands. Previously, this sid would have been ignored and the only way for a user team to play in an international cup was if it used the special LEAGUE* or CUP* sid. As a result of this change, the 'generate' property of CupChooseTeam is now infered based on the sid, so the generated tag no longer has an effect in the definition files.
This commit is contained in:
parent
306482d403
commit
4248c08b7a
17
src/cup.c
17
src/cup.c
|
@ -201,6 +201,19 @@ query_cup_choose_team_is_league(const gchar *sid)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/** @return TRUE if the team(s) referenced by \p sid need to be
|
||||
* generated.
|
||||
*/
|
||||
static gboolean
|
||||
cup_choose_team_should_generate(const CupChooseTeam *ct)
|
||||
{
|
||||
if (g_str_has_prefix(ct->sid, "LEAGUE") || g_str_has_prefix(ct->sid, "CUP"))
|
||||
return FALSE;
|
||||
|
||||
return !country_get_league_sid(&country, ct->sid) &&
|
||||
!country_get_cup_sid(&country, ct->sid);
|
||||
}
|
||||
|
||||
/** Write the cup or league of the chooseteam into the appropriate pointer
|
||||
and return TRUE; return FALSE if no cup/league is found. */
|
||||
void
|
||||
|
@ -298,7 +311,7 @@ cup_get_team_pointers(Cup *cup, gint round, GPtrArray *teams_sorted, gboolean pr
|
|||
|
||||
if(choose_team->preload == preload)
|
||||
{
|
||||
if(choose_team->generate)
|
||||
if(cup_choose_team_should_generate(choose_team))
|
||||
cup_load_choose_team_generate(cup, cup_round, choose_team);
|
||||
else
|
||||
cup_load_choose_team(cup, teams, teams_sorted, choose_team);
|
||||
|
@ -1169,7 +1182,7 @@ query_cup_begins(const Cup *cup)
|
|||
cup_round = &g_array_index(cup->rounds, CupRound, j);
|
||||
|
||||
for(i=0;i<cup_round->choose_teams->len;i++)
|
||||
if(!g_array_index(cup_round->choose_teams,CupChooseTeam, i).generate)
|
||||
if(!cup_choose_team_should_generate(&g_array_index(cup_round->choose_teams,CupChooseTeam, i)))
|
||||
{
|
||||
cup_get_choose_team_league_cup(
|
||||
&g_array_index(cup_round->choose_teams,
|
||||
|
|
57
src/league.c
57
src/league.c
|
@ -380,6 +380,25 @@ league_cup_average_capacity(gint clid)
|
|||
return sum / (gfloat)cnt;
|
||||
}
|
||||
|
||||
|
||||
/** This is the same as @see league_index_from_sid, except it does not exit
|
||||
* the program if the sid is not found.
|
||||
* @returns The index of the league in the country's league array or -1 if
|
||||
* not found.
|
||||
*/
|
||||
gint
|
||||
country_get_index_from_sid(const Country *country, const gchar *sid)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < country->leagues->len; i++) {
|
||||
const League *league = &g_array_index(country->leagues, League, i);
|
||||
if (!strcmp(league->sid, sid))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** Get the index of the league with the specified string id. */
|
||||
gint
|
||||
league_index_from_sid(const gchar *sid)
|
||||
|
@ -400,6 +419,44 @@ league_index_from_sid(const gchar *sid)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/** @returns TRUE if the league with \p sid is in \p country. */
|
||||
gboolean
|
||||
country_has_league_sid(const Country *country, const gchar *sid)
|
||||
{
|
||||
return country_get_index_from_sid(country, sid) != -1;
|
||||
}
|
||||
|
||||
|
||||
/** @return A Cup object if the cup with \p sid belongs to \p country.
|
||||
* NULL otherwise.
|
||||
*/
|
||||
Cup *
|
||||
country_get_cup_sid(const Country *country, const gchar *sid)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < country->cups->len; i++) {
|
||||
Cup *cup = &g_array_index(country->cups, Cup, i);
|
||||
if (!strcmp(cup->sid, sid))
|
||||
return cup;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** @return A League object if the league with \p sid belongs to \p country.
|
||||
* NULL otherwise.
|
||||
*/
|
||||
League *
|
||||
country_get_league_sid(Country *country, const gchar *sid)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < country->leagues->len; i++) {
|
||||
League *league = &g_array_index(country->leagues, League, i);
|
||||
if (!strcmp(league->sid, sid))
|
||||
return league;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** Remove the team with the specified id from the teams
|
||||
array without freeing the memory (used in promotion/relegation). */
|
||||
void
|
||||
|
|
12
src/league.h
12
src/league.h
|
@ -94,9 +94,21 @@ league_cup_average_capacity(gint clid);
|
|||
void
|
||||
league_get_team_movements(League *league, GArray *team_movements);
|
||||
|
||||
gint
|
||||
country_get_index_from_sid(const Country *country, const gchar *sid);
|
||||
|
||||
gint
|
||||
league_index_from_sid(const gchar *sid);
|
||||
|
||||
gboolean
|
||||
country_has_league_sid(const Country *country, const gchar *sid);
|
||||
|
||||
Cup *
|
||||
country_get_cup_sid(const Country *country, const gchar *sid);
|
||||
|
||||
League *
|
||||
country_get_league_sid(Country *country, const gchar *sid);
|
||||
|
||||
void
|
||||
league_remove_team_with_id(League *league, gint id);
|
||||
|
||||
|
|
Loading…
Reference in New Issue