Skip to content

Commit

Permalink
Add optional tag
Browse files Browse the repository at this point in the history
  • Loading branch information
tstellar committed Mar 6, 2021
1 parent a3a9e1b commit fdc15fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/cup_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions src/xml_cup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/xml_loadsave_cup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fdc15fd

Please sign in to comment.