From de67801b0fd3dfa11777c1ef86cd617baf376b7b Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 1 Oct 2017 13:38:35 +0100 Subject: Use a proper union in struct config_item. This allows me to use different types for the mutable, dynamically allocated string value in a C_STRING control and the fixed constant list of option names in a C_CHOICES. --- towers.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'towers.c') diff --git a/towers.c b/towers.c index 06b7279..3892d8e 100644 --- a/towers.c +++ b/towers.c @@ -212,18 +212,15 @@ static config_item *game_configure(const game_params *params) ret[0].name = "Grid size"; ret[0].type = C_STRING; sprintf(buf, "%d", params->w); - ret[0].sval = dupstr(buf); - ret[0].ival = 0; + ret[0].u.string.sval = dupstr(buf); ret[1].name = "Difficulty"; ret[1].type = C_CHOICES; - ret[1].sval = DIFFCONFIG; - ret[1].ival = params->diff; + ret[1].u.choices.choicenames = DIFFCONFIG; + ret[1].u.choices.selected = params->diff; ret[2].name = NULL; ret[2].type = C_END; - ret[2].sval = NULL; - ret[2].ival = 0; return ret; } @@ -232,8 +229,8 @@ static game_params *custom_params(const config_item *cfg) { game_params *ret = snew(game_params); - ret->w = atoi(cfg[0].sval); - ret->diff = cfg[1].ival; + ret->w = atoi(cfg[0].u.string.sval); + ret->diff = cfg[1].u.choices.selected; return ret; } -- cgit v1.1