diff options
Diffstat (limited to 'web/web_match.c')
-rw-r--r-- | web/web_match.c | 34 |
1 files changed, 30 insertions, 4 deletions
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; } |