Turn options into ordinary econfig keys:
(configkeys): Add options. (KM_OPTION): New. (vers): Find options in configkeys[] instead of Options[]. (xdump): Remove xdump opt syntax. (xdopt): Remove. (emp_config, print_config): Remove option special case. (option_list, Options, setoption): Remove.
This commit is contained in:
parent
373a08a0e0
commit
ade510f787
7 changed files with 86 additions and 173 deletions
|
@ -177,21 +177,24 @@ show_opts(int val)
|
|||
{
|
||||
int col;
|
||||
char *sep;
|
||||
struct option_list *op;
|
||||
struct keymatch *kp;
|
||||
|
||||
sep = "";
|
||||
col = 0;
|
||||
for (op = Options; op->opt_key; op++) {
|
||||
if (!*op->opt_valuep != !val)
|
||||
for (kp = configkeys; kp->km_key; kp++) {
|
||||
if (!(kp->km_flags & KM_OPTION))
|
||||
continue;
|
||||
|
||||
col += strlen(sep) + strlen(op->opt_key);
|
||||
if (CANT_HAPPEN(kp->km_type != NSC_INT))
|
||||
continue;
|
||||
if (!*(int *)kp->km_data != !val)
|
||||
continue;
|
||||
col += strlen(sep) + strlen(kp->km_key);
|
||||
if (col > 70) {
|
||||
pr(",\n ");
|
||||
sep = "";
|
||||
col = strlen(op->opt_key);
|
||||
col = strlen(kp->km_key);
|
||||
}
|
||||
pr("%s%s", sep, op->opt_key);
|
||||
pr("%s%s", sep, kp->km_key);
|
||||
sep = ", ";
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
* - News item characteristics: rpt[]
|
||||
* - News page headings: page_headings[] (TODO)
|
||||
* - Commands: player_coms[] (TODO)
|
||||
* - Options: Options[]
|
||||
* - Configuration: configkeys[]
|
||||
*
|
||||
* Dynamic game data:
|
||||
|
@ -247,46 +246,6 @@ xdmeta(int type)
|
|||
return RET_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump Options[], return RET_OK.
|
||||
* If META, dump meta-data rather than data.
|
||||
*/
|
||||
static int
|
||||
xdopt(int meta)
|
||||
{
|
||||
int i;
|
||||
char *sep;
|
||||
struct castr ca;
|
||||
|
||||
xdhdr("options", meta);
|
||||
|
||||
if (meta) {
|
||||
for (i = 0; Options[i].opt_key; ++i) {
|
||||
ca.ca_type = NSC_INT;
|
||||
ca.ca_flags = 0;
|
||||
ca.ca_len = 0;
|
||||
ca.ca_off = 0;
|
||||
ca.ca_name = Options[i].opt_key;
|
||||
ca.ca_table = EF_BAD;
|
||||
xdflds(mdchr_ca, &ca);
|
||||
pr("\n");
|
||||
}
|
||||
xdftr(i);
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
sep = "";
|
||||
for (i = 0; Options[i].opt_key; ++i) {
|
||||
pr("%s%d", sep, *Options[i].opt_valuep);
|
||||
sep = " ";
|
||||
}
|
||||
pr("\n");
|
||||
|
||||
xdftr(1);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Dump configkeys[], return RET_OK.
|
||||
* If META, dump meta-data rather than data.
|
||||
|
@ -363,8 +322,6 @@ xdump(void)
|
|||
return xdmeta(type);
|
||||
else
|
||||
return xditem(type, player->argp[2]);
|
||||
} else if (!strncmp(p, "opt", strlen(p))) {
|
||||
return xdopt(meta);
|
||||
} else if (!strncmp(p, "ver", strlen(p))) {
|
||||
return xdver(meta);
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ struct keymatch configkeys[] = {
|
|||
};
|
||||
|
||||
static struct keymatch *keylookup(s_char *key, struct keymatch tbl[]);
|
||||
static int set_option(const char *, int);
|
||||
|
||||
/*
|
||||
* read in empire configuration
|
||||
|
@ -135,15 +134,6 @@ emp_config(char *file)
|
|||
*(char **)kp->km_data = strdup(av[1]);
|
||||
kp->km_flags |= KM_ALLOC;
|
||||
break;
|
||||
case NSC_NOTYPE:
|
||||
for (i = 1; av[i]; ++i) {
|
||||
if (set_option(av[i], kp->km_key[0] != 'n') < 0) {
|
||||
fprintf(stderr, "%s:%d: Unknown option %s\n",
|
||||
file, lno, av[i]);
|
||||
errors = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
@ -177,7 +167,6 @@ keylookup(register s_char *command, struct keymatch *tbl)
|
|||
void
|
||||
print_config(FILE *fp)
|
||||
{
|
||||
struct option_list *op;
|
||||
struct keymatch *kp;
|
||||
|
||||
fprintf(fp, "# Empire Configuration File:\n");
|
||||
|
@ -205,11 +194,6 @@ print_config(FILE *fp)
|
|||
case NSC_LONG:
|
||||
fprintf(fp, "%s %ld\n", kp->km_key, *(long *)kp->km_data);
|
||||
break;
|
||||
case NSC_NOTYPE:
|
||||
for (op = Options; op->opt_key; op++)
|
||||
if (*op->opt_valuep != (kp->km_key[0] == 'n'))
|
||||
fprintf(fp, "%s %s\n", kp->km_key, op->opt_key);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
@ -217,19 +201,3 @@ print_config(FILE *fp)
|
|||
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
|
||||
/* Set option S to value VAL; return 0 on success, -1 on failure. */
|
||||
static int
|
||||
set_option(const char *s, int val)
|
||||
{
|
||||
struct option_list *op;
|
||||
|
||||
for (op = Options; op->opt_key; op++) {
|
||||
if (strcmp(op->opt_key, s) == 0) {
|
||||
*op->opt_valuep = val;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -242,41 +242,3 @@ int opt_TECH_POP = 1;
|
|||
#else
|
||||
int opt_TECH_POP = 0;
|
||||
#endif
|
||||
|
||||
struct option_list Options[] = {
|
||||
{"ALL_BLEED", &opt_ALL_BLEED},
|
||||
{"BIG_CITY", &opt_BIG_CITY},
|
||||
{"BLITZ", &opt_BLITZ},
|
||||
{"BRIDGETOWERS", &opt_BRIDGETOWERS},
|
||||
{"DEFENSE_INFRA", &opt_DEFENSE_INFRA},
|
||||
{"DEMANDUPDATE", &opt_DEMANDUPDATE},
|
||||
{"DRNUKE", &opt_DRNUKE},
|
||||
{"EASY_BRIDGES", &opt_EASY_BRIDGES},
|
||||
{"FALLOUT", &opt_FALLOUT},
|
||||
{"FUEL", &opt_FUEL},
|
||||
{"GODNEWS", &opt_GODNEWS},
|
||||
{"GO_RENEW", &opt_GO_RENEW},
|
||||
{"GUINEA_PIGS", &opt_GUINEA_PIGS},
|
||||
{"HIDDEN", &opt_HIDDEN},
|
||||
{"INTERDICT_ATT", &opt_INTERDICT_ATT},
|
||||
{"LANDSPIES", &opt_LANDSPIES},
|
||||
{"LOANS", &opt_LOANS},
|
||||
{"LOSE_CONTACT", &opt_LOSE_CONTACT},
|
||||
{"MARKET", &opt_MARKET},
|
||||
{"MOB_ACCESS", &opt_MOB_ACCESS},
|
||||
{"NO_FORT_FIRE", &opt_NO_FORT_FIRE},
|
||||
{"NO_PLAGUE", &opt_NO_PLAGUE},
|
||||
{"NOFOOD", &opt_NOFOOD},
|
||||
{"NOMOBCOST", &opt_NOMOBCOST},
|
||||
{"PINPOINTMISSILE", &opt_PINPOINTMISSILE},
|
||||
{"RES_POP", &opt_RES_POP},
|
||||
{"SAIL", &opt_SAIL},
|
||||
{"SHOWPLANE", &opt_SHOWPLANE},
|
||||
{"SLOW_WAR", &opt_SLOW_WAR},
|
||||
{"SUPER_BARS", &opt_SUPER_BARS},
|
||||
{"TECH_POP", &opt_TECH_POP},
|
||||
{"TRADESHIPS", &opt_TRADESHIPS},
|
||||
{"TREATIES", &opt_TREATIES},
|
||||
{"UPDATESCHED", &opt_UPDATESCHED},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue