From 7797f45a97681ca513cb75a7e6a322be3ec5003a Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 21 May 2022 02:03:13 -0700 Subject: web: remove hard-coded match modes --- web/web_match.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'web/web_match.c') diff --git a/web/web_match.c b/web/web_match.c index f200f11..0ebc56e 100644 --- a/web/web_match.c +++ b/web/web_match.c @@ -16,7 +16,6 @@ void match_new() state = calloc(1, sizeof(*state)); state->id = ++curr_id; - state->mode = match_opts->mode; state->size_players = 2; state->legs = malloc(state->size_players * sizeof(*(state->legs))); @@ -56,8 +55,38 @@ void free_state() state = NULL; } +void match_opts_new() +{ + if (match_opts) match_opts_free(); + + match_opts = calloc(1, sizeof(*match_opts)); + + match_opts->size_players = 2; + match_opts->players = malloc( + match_opts->size_players * sizeof(*(match_opts->players))); +} + +void match_opts_add_player(enum player_type type, char *name) +{ + if (match_opts->num_players == match_opts->size_players) { + match_opts->size_players += + match_opts->size_players ? + match_opts->size_players : 1; + match_opts->players = realloc(match_opts->players, + match_opts->size_players * + sizeof(*(match_opts->players))); + } + + match_opts->players[match_opts->num_players].type = type; + match_opts->players[match_opts->num_players++].name = name; +} + void match_opts_free() { + if (!match_opts) + return; + + free(match_opts->players); free(match_opts); match_opts = NULL; } @@ -69,9 +98,6 @@ struct leg *state_active_leg() int match_num_players() { - if (state->mode == M_P) - return 1; - return state->num_players; } -- cgit v1.2.3-70-g09d2