]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/snxtitem.c
Update copyright notice
[empserver] / src / lib / subs / snxtitem.c
index 47cb7dae4d294aa52210f6b91df3c973ad1e5797..88452951276815329d4c4dd9ecd339096f05136d 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -29,7 +28,7 @@
  *
  *  Known contributors to this file:
  *     Dave Pare, 1989
- *     Markus Armbruster, 2008
+ *     Markus Armbruster, 2009-2011
  */
 
 #include <config.h>
@@ -66,17 +65,17 @@ snxtitem(struct nstr_item *np, int type, char *str, char *prompt)
 
     np->type = EF_BAD;
     np->sel = NS_UNDEF;
-    if (str == 0) {
+    if (!str) {
        if (!prompt) {
            sprintf(promptbuf, "%s(s)? ", ef_nameof(type));
            prompt = promptbuf;
        }
        str = getstring(prompt, buf);
-       if (str == 0)
+       if (!str)
            return 0;
-    }
+    } else
+       make_stale_if_command_arg(str);
     if (*str == 0) {
-       /* empty string passed by player */
        return 0;
     }
     if (type == EF_NATION && isalpha(*str)) {
@@ -126,12 +125,7 @@ snxtitem(struct nstr_item *np, int type, char *str, char *prompt)
     default:
        return 0;
     }
-    if (player->condarg == 0)
-       return 1;
-    n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond), type,
-                 player->condarg);
-    np->ncond = n >= 0 ? n : 0;
-    return n >= 0;
+    return snxtitem_use_condarg(np);
 }
 
 void
@@ -147,8 +141,7 @@ snxtitem_area(struct nstr_item *np, int type, struct range *range)
 }
 
 void
-snxtitem_dist(struct nstr_item *np, int type, int cx, int cy,
-             int dist)
+snxtitem_dist(struct nstr_item *np, int type, int cx, int cy, int dist)
 {
     memset(np, 0, sizeof(*np));
     xydist_range(cx, cy, dist, &np->range);
@@ -241,3 +234,18 @@ snxtitem_cargo(struct nstr_item *np, int type,
     np->sel = NS_CARGO;
     np->next = unit_cargo_first(carrier_type, carrier_uid, type);
 }
+
+int
+snxtitem_use_condarg(struct nstr_item *np)
+{
+    int n;
+
+    if (!player->condarg)
+       return 1;
+    n = nstr_comp(np->cond, sizeof(np->cond) / sizeof(*np->cond),
+                 np->type, player->condarg);
+    if (n < 0)
+       return 0;
+    np->ncond = n;
+    return 1;
+}