(natargp): New, factored out of natarg().
This commit is contained in:
parent
ba554cbb1f
commit
402c47b66e
2 changed files with 40 additions and 22 deletions
|
@ -545,6 +545,7 @@ extern int msl_launch_mindam(struct emp_qelem *, coord, coord, int,
|
|||
/* mtch.c */
|
||||
extern int comtch(register s_char *, struct cmndstr *, int);
|
||||
/* natarg.c */
|
||||
extern struct natstr *natargp(char *, char *);
|
||||
extern int natarg(char *, char *);
|
||||
/* neigh.c */
|
||||
extern int neigh(coord, coord, natid);
|
||||
|
|
|
@ -42,6 +42,41 @@
|
|||
#include "prototypes.h"
|
||||
#include "optlist.h"
|
||||
|
||||
/*
|
||||
* Get nation argument.
|
||||
* If ARG is not empty, use it, else prompt for input using PROMPT.
|
||||
* If no input is provided, return NULL.
|
||||
* If the argument identifies a country, return its getnatp() value.
|
||||
* Else complain and return NULL.
|
||||
* Caution: this function doesn't care for lack of contact.
|
||||
*/
|
||||
struct natstr *
|
||||
natargp(char *arg, char *prompt)
|
||||
{
|
||||
char buf[1024];
|
||||
int n;
|
||||
struct natstr *np;
|
||||
|
||||
arg = getstarg(arg, prompt, buf);
|
||||
if (arg == 0 || *arg == 0)
|
||||
return NULL;
|
||||
if (isdigit(*arg))
|
||||
n = atoi(arg);
|
||||
else {
|
||||
n = cnumb(arg);
|
||||
if (n == M_NOTUNIQUE) {
|
||||
pr("Country '%s' is ambiguous\n", arg);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
np = getnatp(n);
|
||||
if (!np) {
|
||||
pr("Country '%s' doesn't exist.\n", arg);
|
||||
return NULL;
|
||||
}
|
||||
return np;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get nation argument.
|
||||
* If ARG is not empty, use it, else prompt for input using PROMPT.
|
||||
|
@ -55,34 +90,16 @@
|
|||
int
|
||||
natarg(char *arg, char *prompt)
|
||||
{
|
||||
char buf[1024];
|
||||
int n;
|
||||
struct natstr *np;
|
||||
|
||||
arg = getstarg(arg, prompt, buf);
|
||||
if (arg == 0 || *arg == 0)
|
||||
struct natstr *np = natargp(arg, prompt);
|
||||
if (!np)
|
||||
return -1;
|
||||
if (isdigit(*arg))
|
||||
n = atoi(arg);
|
||||
else {
|
||||
n = cnumb(arg);
|
||||
if (n == M_NOTUNIQUE) {
|
||||
pr("Country '%s' is ambiguous\n", arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
np = getnatp(n);
|
||||
if (!np) {
|
||||
pr("Country '%s' doesn't exist.\n", arg);
|
||||
return -1;
|
||||
}
|
||||
if (opt_HIDDEN) {
|
||||
if (!player->god && !getcontact(getnatp(player->cnum), n)) {
|
||||
if (!player->god && !getcontact(getnatp(player->cnum), np->nat_cnum)) {
|
||||
if (np->nat_stat != STAT_GOD) {
|
||||
pr("Country '%s' has not been contacted.\n", arg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
return np->nat_cnum;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue