1
1
mirror of https://github.com/tstellar/bygfoot.git synced 2025-01-24 21:01:12 +01:00

Add optional tag

This commit is contained in:
Tom Stellard 2021-02-18 07:41:04 -08:00 committed by Tom Stellard
parent a3a9e1bacc
commit fdc15fdf8a
4 changed files with 23 additions and 1 deletions

View File

@ -102,6 +102,7 @@ cup_choose_team_new(void)
new.skip_group_check = FALSE;
new.from_table = 0;
new.preload = TRUE;
new.optional = FALSE;
new.next = NULL;
return new;
@ -703,7 +704,9 @@ cup_load_choose_team_generate(Cup *cup, CupRound *cup_round, const CupChooseTeam
g_ptr_array_free(teams_local, TRUE);
if (ct->next)
return cup_load_choose_team_generate(cup, cup_round, ct->next);
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
if (ct->optional)
return;
main_exit_program(EXIT_CHOOSE_TEAM_ERROR,
"cup_load_choose_team_generate: not enough teams (that don't participate in international cups yet) found in chooseteam %s for cup %s (%d specified, %d found).\n ",
ct->sid, cup->name,
ct->number_of_teams, number_of_teams);

View File

@ -142,6 +142,12 @@ typedef struct CupChooseTeam
belongs to is scheduled. Default: TRUE. */
gboolean preload;
/** If this is FALSE, then bygfoot will exit with an error if it can't
* find a team that meets the criteria. Set this to TRUE if a cup position
* will be vaccated if the team qualifies for a higher round in the cup.
* Default: FALSE. */
gboolean optional;
/** Whether to load the team from the results of the previous season. */
gboolean previous_season;

View File

@ -71,6 +71,7 @@
#define TAG_CHOOSE_TEAM_SKIP_GROUP_CHECK "skip_group_check"
#define TAG_CHOOSE_TEAM_FROM_TABLE "from_table"
#define TAG_CHOOSE_TEAM_PRELOAD "preload"
#define TAG_CHOOSE_TEAM_OPTIONAL "optional"
#define TAG_CHOOSE_TEAM_ALTERNATIVES "alternatives"
#define ATT_NAME_CUP_ROUND_WAIT_ROUND "round"
@ -124,6 +125,7 @@ enum XmlCupStates
STATE_CHOOSE_TEAM_SKIP_GROUP_CHECK,
STATE_CHOOSE_TEAM_FROM_TABLE,
STATE_CHOOSE_TEAM_PRELOAD,
STATE_CHOOSE_TEAM_OPTIONAL,
STATE_CHOOSE_TEAM_ALTERNATIVES,
STATE_END
};
@ -280,6 +282,8 @@ xml_cup_read_start_element (GMarkupParseContext *context,
state = STATE_CHOOSE_TEAM_FROM_TABLE;
else if(strcmp(element_name, TAG_CHOOSE_TEAM_PRELOAD) == 0)
state = STATE_CHOOSE_TEAM_PRELOAD;
else if(strcmp(element_name, TAG_CHOOSE_TEAM_OPTIONAL) == 0)
state = STATE_CHOOSE_TEAM_OPTIONAL;
else if(strcmp(element_name, TAG_CHOOSE_TEAM_ALTERNATIVES) == 0) {
state = STATE_CHOOSE_TEAM_ALTERNATIVES;
alternatives = TRUE;
@ -374,6 +378,7 @@ xml_cup_read_end_element (GMarkupParseContext *context,
strcmp(element_name, TAG_CHOOSE_TEAM_SKIP_GROUP_CHECK) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_FROM_TABLE) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_PRELOAD) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_OPTIONAL) == 0 ||
strcmp(element_name, TAG_CHOOSE_TEAM_GENERATE) == 0)
state = STATE_CHOOSE_TEAM;
else if(strcmp(element_name, TAG_CUP) != 0)
@ -487,6 +492,8 @@ xml_cup_read_text (GMarkupParseContext *context,
new_choose_team->from_table = int_value;
else if(state == STATE_CHOOSE_TEAM_PRELOAD)
new_choose_team->preload = int_value;
else if(state == STATE_CHOOSE_TEAM_OPTIONAL)
new_choose_team->optional = int_value;
}
/**

View File

@ -78,6 +78,7 @@ enum
TAG_CUP_NEXT_FIXTURE_UPDATE_WEEK_ROUND,
TAG_CUP_ROUND_DELAY,
TAG_CUP_CHOOSE_TEAM_ALTERNATIVES,
TAG_CUP_CHOOSE_TEAM_OPTIONAL,
TAG_END
};
@ -190,6 +191,7 @@ xml_loadsave_cup_end_element (GMarkupParseContext *context,
tag == TAG_CUP_CHOOSE_TEAM_SKIP_GROUP_CHECK ||
tag == TAG_CUP_CHOOSE_TEAM_FROM_TABLE ||
tag == TAG_CUP_CHOOSE_TEAM_PRELOAD ||
tag == TAG_CUP_CHOOSE_TEAM_OPTIONAL ||
tag == TAG_CUP_CHOOSE_TEAM_RANDOMLY)
state = TAG_CUP_CHOOSE_TEAM;
else if(tag == TAG_CUP_ROUND_HOME_AWAY ||
@ -304,6 +306,8 @@ xml_loadsave_cup_text (GMarkupParseContext *context,
new_choose_team->from_table = int_value;
else if(state == TAG_CUP_CHOOSE_TEAM_PRELOAD)
new_choose_team->preload = int_value;
else if(state == TAG_CUP_CHOOSE_TEAM_OPTIONAL)
new_choose_team->optional = int_value;
else if(state == TAG_CUP_ROUND_HOME_AWAY)
new_round.home_away = int_value;
else if(state == TAG_CUP_ROUND_NEW_TEAMS)
@ -577,6 +581,8 @@ xml_loadsave_cup_write_choose_team(FILE *fil, const CupChooseTeam *choose_team,
TAG_CUP_CHOOSE_TEAM_FROM_TABLE, I2);
xml_write_int(fil, choose_team->preload,
TAG_CUP_CHOOSE_TEAM_PRELOAD, I2);
xml_write_int(fil, choose_team->optional,
TAG_CUP_CHOOSE_TEAM_OPTIONAL, I2);
if (choose_team->next) {