mirror of
https://github.com/tstellar/bygfoot.git
synced 2025-02-14 02:20:44 +01:00
Allow using rank_start and rank_end tags for prom_games
This adds the same functionality already supported by the prom_rel tags to support reserve team promotion rules for promotion games. This allows you to specify a larger range of teams to promte than the number of teams defined with the number_of_teams tag, so that if a team is ineligible for promotion than other teams can be substituted. For example, if you wanted to promote at most 2 of the top 3 teams, you could do: <prom_games> <prom_games_number_of_advance>2</prom_games_number_of_advance> <rank_start>1</rank_start> <rank_end>3</rank_end> </prom_games> Note that the rank_start and rank_end tags are not supported when using the prom_games_loser_sid tag.
This commit is contained in:
parent
a5363a98f5
commit
eb15df7cd9
@ -125,6 +125,7 @@ prom_games_new(void)
|
||||
new.loser_sid = NULL;
|
||||
new.cup_sid = NULL;
|
||||
new.number_of_advance = 1;
|
||||
new.ranks[0] = new.ranks[1] = 0;
|
||||
|
||||
return new;
|
||||
}
|
||||
@ -1040,8 +1041,8 @@ league_get_team_movements_prom_games(const League *league, const PromGames *prom
|
||||
GArray *dest_idcs = NULL;
|
||||
gint dest_idcs_int[dest_sids->len];
|
||||
gint dest_idcs_order[dest_sids->len];
|
||||
gint start_idx = 0,
|
||||
end_idx = prom_games->number_of_advance;
|
||||
gint start_idx = prom_games->ranks[0] - 1,
|
||||
end_idx = prom_games->ranks[1];
|
||||
gint prom_type = PROM_REL_PROMOTION;
|
||||
|
||||
if(!up)
|
||||
|
@ -63,6 +63,8 @@ typedef struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
gint ranks[2]; /**< The range of teams; default 0 and 0. This is only valid
|
||||
loser_sid == NULL. */
|
||||
/** The id of the league the promotion games winner gets promoted to. Default "" */
|
||||
gchar *dest_sid;
|
||||
/** The id of the league the promotion games losers get moved to. Default "" */
|
||||
|
@ -101,6 +101,8 @@ enum XmlLeagueStates
|
||||
STATE_PROM_GAMES_LOSER_SID,
|
||||
STATE_PROM_GAMES_NUMBER_OF_ADVANCE,
|
||||
STATE_PROM_GAMES_CUP_SID,
|
||||
STATE_PROM_GAMES_RANK_START,
|
||||
STATE_PROM_GAMES_RANK_END,
|
||||
STATE_PROM_REL_ELEMENT,
|
||||
STATE_PROM_REL_ELEMENT_RANK_START,
|
||||
STATE_PROM_REL_ELEMENT_RANK_END,
|
||||
@ -249,11 +251,17 @@ xml_league_read_start_element (GMarkupParseContext *context,
|
||||
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_NUMBER_OF_TEAMS) == 0)
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_RANK_START) == 0) {
|
||||
if (state == STATE_PROM_GAMES)
|
||||
state = STATE_PROM_GAMES_RANK_START;
|
||||
else
|
||||
state = STATE_PROM_REL_ELEMENT_RANK_START;
|
||||
} else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_RANK_END) == 0) {
|
||||
if (state == STATE_PROM_GAMES)
|
||||
state = STATE_PROM_GAMES_RANK_END;
|
||||
else
|
||||
state = STATE_PROM_REL_ELEMENT_RANK_END;
|
||||
} else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_NUMBER_OF_TEAMS) == 0)
|
||||
state = STATE_PROM_REL_ELEMENT_NUMBER_OF_TEAMS;
|
||||
else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_DEST_SID) == 0)
|
||||
state = STATE_PROM_REL_ELEMENT_DEST_SID;
|
||||
@ -338,8 +346,12 @@ xml_league_read_end_element (GMarkupParseContext *context,
|
||||
strcmp(element_name, TAG_PROM_GAMES_CUP_SID) == 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_NUMBER_OF_TEAMS) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT_RANK_END) == 0) {
|
||||
if (state == STATE_PROM_GAMES_RANK_START || state == STATE_PROM_GAMES_RANK_END)
|
||||
state = STATE_PROM_GAMES;
|
||||
else
|
||||
state = STATE_PROM_REL_ELEMENT;
|
||||
} else if(strcmp(element_name, TAG_PROM_REL_ELEMENT_NUMBER_OF_TEAMS) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT_DEST_SID) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT_FROM_TABLE) == 0 ||
|
||||
strcmp(element_name, TAG_PROM_REL_ELEMENT_TYPE) == 0)
|
||||
@ -441,6 +453,12 @@ xml_league_read_text (GMarkupParseContext *context,
|
||||
else if(state == STATE_PROM_GAMES_CUP_SID)
|
||||
g_array_index(new_league.prom_rel.prom_games, PromGames,
|
||||
new_league.prom_rel.prom_games->len - 1).cup_sid = g_strdup(buf);
|
||||
else if(state == STATE_PROM_GAMES_RANK_START)
|
||||
g_array_index(new_league.prom_rel.prom_games, PromGames,
|
||||
new_league.prom_rel.prom_games->len - 1).ranks[0] = int_value;
|
||||
else if(state == STATE_PROM_GAMES_RANK_END)
|
||||
g_array_index(new_league.prom_rel.prom_games, PromGames,
|
||||
new_league.prom_rel.prom_games->len - 1).ranks[1] = int_value;
|
||||
else if(state == STATE_PROM_REL_ELEMENT_RANK_START)
|
||||
g_array_index(new_league.prom_rel.elements,
|
||||
PromRelElement,
|
||||
@ -562,6 +580,23 @@ xml_league_read(const gchar *league_name, GArray *leagues)
|
||||
elem->num_teams = (elem->ranks[1] - elem->ranks[0]) + 1;
|
||||
}
|
||||
|
||||
for(i = 0; i < new_league.prom_rel.prom_games->len; i++) {
|
||||
PromGames *prom_games =
|
||||
&g_array_index(new_league.prom_rel.prom_games, PromGames, i);
|
||||
|
||||
/* Specifying ranks and loser_sid is not supported. */
|
||||
if (prom_games->loser_sid &&
|
||||
(prom_games->ranks[0] || prom_games->ranks[1]))
|
||||
g_critical("%s: Cannot specify ranks (%d, %d) and loser_sid (%s)",
|
||||
buf, prom_games->ranks[0], prom_games->ranks[1],
|
||||
prom_games->loser_sid);
|
||||
|
||||
/* Compute the values for rank when it is not specified. */
|
||||
if (!prom_games->ranks[0] && !prom_games->ranks[1]) {
|
||||
prom_games->ranks[0] = 1;
|
||||
prom_games->ranks[1] = prom_games->number_of_advance;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -50,6 +50,7 @@ enum
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_CUP_SID,
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_LOSER_SID,
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_NUMBER_OF_ADVANCE,
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_RANK,
|
||||
TAG_LEAGUE_PROM_REL_ELEMENTS,
|
||||
TAG_LEAGUE_PROM_REL_ELEMENT,
|
||||
TAG_LEAGUE_PROM_REL_ELEMENT_RANK,
|
||||
@ -113,8 +114,10 @@ xml_loadsave_league_start_element (GMarkupParseContext *context,
|
||||
promrankidx = 0;
|
||||
}
|
||||
|
||||
if(tag == TAG_LEAGUE_PROM_GAMES)
|
||||
if(tag == TAG_LEAGUE_PROM_GAMES) {
|
||||
new_prom_games = prom_games_new();
|
||||
promrankidx = 0;
|
||||
}
|
||||
|
||||
if(tag == TAG_LEAGUE_JOINED_LEAGUE_SID)
|
||||
g_array_append_val(new_league->joined_leagues, new_joined_league);
|
||||
@ -179,9 +182,12 @@ xml_loadsave_league_end_element (GMarkupParseContext *context,
|
||||
else if(tag == TAG_LEAGUE_PROM_REL_PROM_GAMES_DEST_SID ||
|
||||
tag == TAG_LEAGUE_PROM_REL_PROM_GAMES_CUP_SID ||
|
||||
tag == TAG_LEAGUE_PROM_REL_PROM_GAMES_LOSER_SID ||
|
||||
tag == TAG_LEAGUE_PROM_REL_PROM_GAMES_NUMBER_OF_ADVANCE)
|
||||
tag == TAG_LEAGUE_PROM_REL_PROM_GAMES_RANK ||
|
||||
tag == TAG_LEAGUE_PROM_REL_PROM_GAMES_NUMBER_OF_ADVANCE) {
|
||||
state = TAG_LEAGUE_PROM_GAMES;
|
||||
else if(tag == TAG_LEAGUE_PROM_REL_ELEMENT)
|
||||
if(tag == TAG_LEAGUE_PROM_REL_PROM_GAMES_RANK)
|
||||
promrankidx++;
|
||||
} else if(tag == TAG_LEAGUE_PROM_REL_ELEMENT)
|
||||
{
|
||||
state = TAG_LEAGUE_PROM_REL_ELEMENTS;
|
||||
g_array_append_val(new_league->prom_rel.elements, new_element);
|
||||
@ -296,6 +302,8 @@ xml_loadsave_league_text (GMarkupParseContext *context,
|
||||
new_prom_games.number_of_advance = int_value;
|
||||
else if(state == TAG_LEAGUE_PROM_REL_PROM_GAMES_LOSER_SID)
|
||||
new_prom_games.loser_sid = g_strdup(buf);
|
||||
else if(state == TAG_LEAGUE_PROM_REL_PROM_GAMES_RANK)
|
||||
new_prom_games.ranks[promrankidx] = int_value;
|
||||
else if(state == TAG_LEAGUE_PROM_REL_ELEMENT_RANK)
|
||||
new_element.ranks[promrankidx] = int_value;
|
||||
else if(state == TAG_LEAGUE_PROM_REL_ELEMENT_NUMBER_OF_TEAMS)
|
||||
@ -466,6 +474,10 @@ xml_loadsave_league_prom_rel_write(FILE *fil, const League *league)
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_NUMBER_OF_ADVANCE, I2);
|
||||
xml_write_string(fil, g_array_index(league->prom_rel.prom_games, PromGames, i).loser_sid,
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_LOSER_SID, I2);
|
||||
xml_write_int(fil, g_array_index(league->prom_rel.prom_games, PromGames, i).ranks[0],
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_RANK, I2);
|
||||
xml_write_int(fil, g_array_index(league->prom_rel.prom_games, PromGames, i).ranks[1],
|
||||
TAG_LEAGUE_PROM_REL_PROM_GAMES_RANK, I2);
|
||||
|
||||
fprintf(fil, "%s</_%d>\n", I1, TAG_LEAGUE_PROM_GAMES);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user