]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/army.c
Update copyright notice
[empserver] / src / lib / commands / army.c
index d3fff23ddd47922fa3f52a1e6e3ff14fb0b568af..2dc8bc7cdfa51c598964cff3c0b1b40aa55f0277 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *  army.c: Add units to an army
- * 
+ *
  *  Known contributors to this file:
- *     
+ *
  */
 
+#include <config.h>
+
 #include <ctype.h>
-#include "misc.h"
-#include "player.h"
-#include "land.h"
-#include "nsc.h"
-#include "file.h"
 #include "commands.h"
+#include "land.h"
 
 int
 army(void)
 {
     struct lndstr land;
     int count;
-    s_char *cp;
-    s_char c;
+    char *cp;
+    char c;
     struct nstr_item nstr;
     struct nstr_item ni;
     struct lndstr land2;
-    int r;
-    s_char buf[1024];
+    char buf[1024];
 
     cp = getstarg(player->argp[1], "army? ", buf);
     if (cp == 0)
@@ -61,24 +58,31 @@ army(void)
        return RET_SYN;
     }
     if (c == '~')
-       c = ' ';
-    if (!snxtitem(&nstr, EF_LAND, player->argp[2]))
+       c = 0;
+    if (!snxtitem(&nstr, EF_LAND, player->argp[2], NULL))
        return RET_SYN;
     count = 0;
-    while (nxtitem(&nstr, (s_char *)&land)) {
+    while (nxtitem(&nstr, &land)) {
        if (!player->owner)
            continue;
-       land.lnd_army = c;
-       snxtitem(&ni, EF_LAND, cp);
-       while ((r = nxtitem(&ni, (s_char *)&land2)) &&
-              (land2.lnd_army != c)) ;
-       if (r) {
-           memcpy(land.lnd_rpath, land2.lnd_rpath, sizeof(land.lnd_rpath));
-           land.lnd_rflags = land2.lnd_rflags;
+       if (land.lnd_army == c)
+           continue;
+       land.lnd_rflags &= ~RET_GROUP;
+       snxtitem_group(&ni, EF_LAND, c);
+       while (nxtitem(&ni, &land2)) {
+           if ((land2.lnd_rflags & RET_GROUP) == 0)
+               continue;
+           if (land2.lnd_x == land.lnd_x && land2.lnd_y == land.lnd_y) {
+               memcpy(land.lnd_rpath, land2.lnd_rpath,
+                      sizeof(land.lnd_rpath));
+               land.lnd_rflags = land2.lnd_rflags;
+               break;
+           }
        }
+       land.lnd_army = c;
        putland(land.lnd_uid, &land);
        count++;
     }
-    pr("%d unit%s added to army `%c'\n", count, splur(count), c);
+    pr("%d unit%s added to army `%1.1s'\n", count, splur(count), &c);
     return RET_OK;
 }