summaryrefslogtreecommitdiff
path: root/web/web_match.c
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-21 02:03:13 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2022-05-21 02:03:35 -0700
commit7797f45a97681ca513cb75a7e6a322be3ec5003a (patch)
treeb8b3e4e8a6482064aab345f82469ebcafeba0d9f /web/web_match.c
parentdc7c6379f0ef9db382a5445954a4be37e2ec5640 (diff)
downloaddartboat-7797f45a97681ca513cb75a7e6a322be3ec5003a.tar.gz
dartboat-7797f45a97681ca513cb75a7e6a322be3ec5003a.tar.xz
web: remove hard-coded match modes
Diffstat (limited to 'web/web_match.c')
-rw-r--r--web/web_match.c34
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;
}