]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/snxtitem.c
Update copyright notice
[empserver] / src / lib / subs / snxtitem.c
index cf45cacc63bef4070eb7bd00725893691927a81d..1d07bb417a81940eb1c9dee5ab951bf0d6dfdcba 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     Dave Pare, 1989
  */
 
+#include <config.h>
+
+#include <ctype.h>
 #include "misc.h"
 #include "player.h"
-#include "var.h"
 #include "xy.h"
-#include "sect.h"
 #include "nsc.h"
 #include "file.h"
-#include "com.h"
 #include "prototypes.h"
 
 /*
  * can select on NS_ALL, NS_AREA, NS_DIST, and NS_LIST.
  * iterate thru the "condarg" string looking
  * for arguments to compile into the nstr.
+ * Using this function for anything but command arguments is usually
+ * incorrect, because it respects conditionals.  Use the snxtitem_FOO()
+ * instead.
  */
 int
-snxtitem(register struct nstr_item *np, int type, s_char *str)
+snxtitem(struct nstr_item *np, int type, char *str)
 {
-    register s_char *cp;
     struct range range;
     int list[NS_LSIZE];
     int n;
     coord cx, cy;
     int dist;
     int flags;
-    s_char natnumber[16];
-    s_char prompt[128];
-    s_char buf[1024];
+    char natnumber[16];
+    char prompt[128];
+    char buf[1024];
 
-    np->type = NS_UNDEF;
+    np->type = EF_BAD;
     np->sel = NS_UNDEF;
     if (str == 0) {
        sprintf(prompt, "%s(s)? ", ef_nameof(type));
@@ -70,11 +72,11 @@ snxtitem(register struct nstr_item *np, int type, s_char *str)
            return 0;
     }
     if (*str == 0) {
-       /* str present, but only <cr>: nil string passed by player */
+       /* empty string passed by player */
        return 0;
     }
     if (type == EF_NATION && isalpha(*str)) {
-       sprintf(natnumber, "%d", natarg(str, ""));
+       sprintf(natnumber, "%d", natarg(str, NULL));
        str = natnumber;
     }
     flags = ef_flags(type);
@@ -120,16 +122,118 @@ snxtitem(register struct nstr_item *np, int type, s_char *str)
     np->flags = flags;
     if (player->condarg == 0)
        return 1;
-    cp = player->condarg;
-    while ((cp = nstr_comp(np->cond, &np->ncond, type, cp)) && *cp) ;
-    if (cp == 0)
+    n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond), type,
+                 player->condarg);
+    np->ncond = n >= 0 ? n : 0;
+    return n >= 0;
+}
+
+void
+snxtitem_area(struct nstr_item *np, int type, struct range *range)
+{
+    memset(np, 0, sizeof(*np));
+    np->cur = -1;
+    np->type = type;
+    np->sel = NS_AREA;
+    np->index = -1;
+    np->range = *range;
+    np->read = ef_read;
+    np->flags = ef_flags(type);
+    xysize_range(&np->range);
+}
+
+void
+snxtitem_dist(struct nstr_item *np, int type, int cx, int cy,
+             int dist)
+{
+    struct range range;
+
+    memset(np, 0, sizeof(*np));
+    xydist_range(cx, cy, dist, &range);
+    np->cur = -1;
+    np->type = type;
+    np->sel = NS_DIST;
+    np->cx = cx;
+    np->cy = cy;
+    np->index = -1;
+    np->range = range;
+    np->dist = dist;
+    np->read = ef_read;
+    np->flags = ef_flags(type);
+#if 0
+    /* This is no longer proper. */
+    /* It did the wrong thing for small, hitech worlds. */
+    xysize_range(&np->range);
+#endif
+}
+
+void
+snxtitem_xy(struct nstr_item *np, int type, coord x, coord y)
+{
+    memset(np, 0, sizeof(*np));
+    np->cur = -1;
+    np->type = type;
+    np->sel = NS_XY;
+    np->cx = xnorm(x);
+    np->cy = ynorm(y);
+    np->index = -1;
+    np->dist = 0;
+    np->read = ef_read;
+    np->flags = ef_flags(type);
+}
+
+void
+snxtitem_all(struct nstr_item *np, int type)
+{
+    memset(np, 0, sizeof(*np));
+    np->cur = -1;
+    np->sel = NS_ALL;
+    np->type = type;
+    np->index = -1;
+    np->read = ef_read;
+    np->flags = ef_flags(type);
+    xysize_range(&np->range);
+}
+
+void
+snxtitem_group(struct nstr_item *np, int type, char group)
+{
+    if (group == '~')
+       group = 0;
+    memset(np, 0, sizeof(*np));
+    np->cur = -1;
+    np->sel = NS_GROUP;
+    np->group = group;
+    np->type = type;
+    np->index = -1;
+    np->read = ef_read;
+    np->flags = ef_flags(type);
+    xysize_range(&np->range);
+}
+
+void
+snxtitem_rewind(struct nstr_item *np)
+{
+    np->cur = -1;
+    np->index = -1;
+}
+
+int
+snxtitem_list(struct nstr_item *np, int type, int *list, int len)
+{
+    int i;
+
+    memset(np, 0, sizeof(*np));
+    np->cur = -1;
+    np->type = type;
+    np->sel = NS_LIST;
+    np->index = -1;
+    np->read = ef_read;
+    np->flags = ef_flags(type);
+    if (len <= 0 || len > NS_LSIZE)
        return 0;
+    for (i = 0; i < len; i++)
+       np->list[i] = list[i];
+    np->size = len;
     return 1;
 }
-
-/*
- * The rest of these (snxtitem_area, snxtitem_dist, etc, have been moved
- * into the common lib, since they don't use condargs, and are useful
- * elsewhere (update, chiefly). ---ts
- *
- */