]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/setsect.c
Update copyright notice
[empserver] / src / lib / commands / setsect.c
index 2496c4e7bfbdb0b70049fc3e50a69ab342433052..390c0f463cfc427acb9cdec8dfd692fc34e5a6c4 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2013, 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,
  *  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/>.
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *  setsect.c: Give resources to a country
- * 
+ *
  *  Known contributors to this file:
  *     David Muir Sharnoff
  *     Steve McClure, 1998
 
 #include <config.h>
 
-#include <stdio.h>
-#include <ctype.h>
-#include "misc.h"
-#include "player.h"
-#include "xy.h"
-#include "sect.h"
-#include "nat.h"
-#include "news.h"
-#include "nsc.h"
-#include "file.h"
 #include "commands.h"
+#include "news.h"
 #include "optlist.h"
 
 
@@ -55,29 +45,31 @@ int
 setsector(void)
 {
     struct sctstr sect;
-    s_char *what;
+    char *what;
     int amt, current;
-    s_char *p;
+    char *p;
     struct nstr_sect nstr;
-    s_char buf[1024];
-    s_char char0, char1;
+    char buf[1024];
+    char char0, char1;
 
-    if ((what = getstarg(player->argp[1],
-                        "Give What (iron, gold, oil, uranium, fertility, owner, eff., mob., work, avail., oldown, mines)? ",
-                        buf)) == 0)
+    what = getstarg(player->argp[1],
+                   "Give what (iron, gold, oil, uranium, fertility, owner, eff., mob., work, avail., oldown, mines)? ",
+                   buf);
+    if (!what)
        return RET_SYN;
     char0 = what[0];
     char1 = what[1];
 
-    switch (char0) {
-    case 'i':
-       if (!snxtsct(&nstr, player->argp[2]))
+    if (!snxtsct(&nstr, player->argp[2]))
+       return RET_SYN;
+    while (nxtsct(&nstr, &sect) > 0) {
+       p = getstarg(player->argp[3], "What value : ", buf);
+       if (!p || !*p)
            return RET_SYN;
-       while (nxtsct(&nstr, &sect) > 0) {
-           if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
-               (*p == '\0'))
-               return RET_SYN;
-           amt = atoi(p);
+       amt = atoi(p);
+       check_sect_ok(&sect);
+       switch (char0) {
+       case 'i':
            current = sect.sct_min;
            current += amt;
            if (current < 0)
@@ -87,18 +79,9 @@ setsector(void)
            if (sect.sct_own != 0)
                resnoise(&sect, 1, "Iron ore content",
                         (int)sect.sct_min, current);
-           sect.sct_min = (u_char)current;
-           putsect(&sect);
-       }
-       break;
-    case 'g':
-       if (!snxtsct(&nstr, player->argp[2]))
-           return RET_SYN;
-       while (nxtsct(&nstr, &sect) > 0) {
-           if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
-               (*p == '\0'))
-               return RET_SYN;
-           amt = atoi(p);
+           sect.sct_min = (unsigned char)current;
+           break;
+       case 'g':
            current = sect.sct_gmin;
            current += amt;
            if (current < 0)
@@ -108,20 +91,11 @@ setsector(void)
            if (sect.sct_own != 0)
                resnoise(&sect, 1, "Gold content",
                         (int)sect.sct_gmin, current);
-           sect.sct_gmin = (u_char)current;
-           putsect(&sect);
-       }
-       break;
-    case 'o':
-       switch (char1) {
-       case 'i':
-           if (!snxtsct(&nstr, player->argp[2]))
-               return RET_SYN;
-           while (nxtsct(&nstr, &sect) > 0) {
-               if (!(p = getstarg(player->argp[3], "What value : ", buf))
-                   || (*p == '\0'))
-                   return RET_SYN;
-               amt = atoi(p);
+           sect.sct_gmin = (unsigned char)current;
+           break;
+       case 'o':
+           switch (char1) {
+           case 'i':
                current = sect.sct_oil;
                current += amt;
                if (current < 0)
@@ -131,18 +105,9 @@ setsector(void)
                if (sect.sct_own != 0)
                    resnoise(&sect, 1, "Oil content",
                             (int)sect.sct_oil, current);
-               sect.sct_oil = (u_char)current;
-               putsect(&sect);
-           }
-           break;
-       case 'w':
-           if (!snxtsct(&nstr, player->argp[2]))
-               return RET_SYN;
-           while (nxtsct(&nstr, &sect) > 0) {
-               if (!(p = getstarg(player->argp[3], "What value : ", buf))
-                   || (*p == '\0'))
-                   return RET_SYN;
-               amt = atoi(p);
+               sect.sct_oil = (unsigned char)current;
+               break;
+           case 'w':
                if ((amt < 0) || (amt > MAXNOC - 1))
                    return RET_SYN;
                pr("Owner of %s changed from %s (#%d) to %s (#%d).\n",
@@ -157,22 +122,9 @@ setsector(void)
                    wu(player->cnum, amt,
                       "Sector %s gained from deity intervention\n",
                       xyas(sect.sct_x, sect.sct_y, amt));
-               makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x,
-                        sect.sct_y);
-               makenotlost(EF_SECTOR, amt, 0, sect.sct_x, sect.sct_y);
-
                sect.sct_own = (natid)amt;
-               putsect(&sect);
-           }
-           break;
-       case 'l':
-           if (!snxtsct(&nstr, player->argp[2]))
-               return RET_SYN;
-           while (nxtsct(&nstr, &sect) > 0) {
-               if (!(p = getstarg(player->argp[3], "What value : ", buf))
-                   || (*p == '\0'))
-                   return RET_SYN;
-               amt = atoi(p);
+               break;
+           case 'l':
                if ((amt < 0) || (amt > MAXNOC - 1))
                    return RET_SYN;
                pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
@@ -180,22 +132,13 @@ setsector(void)
                   cname(sect.sct_oldown),
                   sect.sct_oldown, cname(amt), amt);
                sect.sct_oldown = (natid)amt;
-               putsect(&sect);
+               break;
+           default:
+               pr("huh?\n");
+               return RET_SYN;
            }
            break;
-       default:
-           pr("huh?\n");
-           return RET_SYN;
-       }
-       break;
-    case 'e':
-       if (!snxtsct(&nstr, player->argp[2]))
-           return RET_SYN;
-       while (nxtsct(&nstr, &sect) > 0) {
-           if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
-               (*p == '\0'))
-               return RET_SYN;
-           amt = atoi(p);
+       case 'e':
            current = sect.sct_effic;
            current += amt;
            if (current < 0)
@@ -204,20 +147,11 @@ setsector(void)
                current = 100;
            pr("Efficiency in %s changed to %d.\n",
               xyas(sect.sct_x, sect.sct_y, player->cnum), current);
-           sect.sct_effic = (u_char)current;
-           putsect(&sect);
-       }
-       break;
-    case 'm':
-       switch (char1) {
-       case 'i':
-           if (!snxtsct(&nstr, player->argp[2]))
-               return RET_SYN;
-           while (nxtsct(&nstr, &sect) > 0) {
-               if (!(p = getstarg(player->argp[3], "What value : ", buf))
-                   || (*p == '\0'))
-                   return RET_SYN;
-               amt = atoi(p);
+           sect.sct_effic = current;
+           break;
+       case 'm':
+           switch (char1) {
+           case 'i':
                current = sect.sct_mines;
                current += amt;
                if (current < 0)
@@ -227,17 +161,8 @@ setsector(void)
                if (sect.sct_own != 0)
                    resnoise(&sect, 1, "Mines", sect.sct_mines, current);
                sect.sct_mines = current;
-               putsect(&sect);
-           }
-           break;
-       case 'o':
-           if (!snxtsct(&nstr, player->argp[2]))
-               return RET_SYN;
-           while (nxtsct(&nstr, &sect) > 0) {
-               if (!(p = getstarg(player->argp[3], "What value : ", buf))
-                   || (*p == '\0'))
-                   return RET_SYN;
-               amt = atoi(p);
+               break;
+           case 'o':
                current = sect.sct_mobil;
                current += amt;
                if (current < -127)
@@ -246,23 +171,14 @@ setsector(void)
                    current = 127;
                pr("Mobility in %s changed to %d.\n",
                   xyas(sect.sct_x, sect.sct_y, player->cnum), current);
-               sect.sct_mobil = (short)current;
-               putsect(&sect);
+               sect.sct_mobil = current;
+               break;
+           default:
+               pr("huh?\n");
+               return RET_SYN;
            }
            break;
-       default:
-           pr("huh?\n");
-           return RET_SYN;
-       }
-       break;
-    case 'a':
-       if (!snxtsct(&nstr, player->argp[2]))
-           return RET_SYN;
-       while (nxtsct(&nstr, &sect) > 0) {
-           if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
-               (*p == '\0'))
-               return RET_SYN;
-           amt = atoi(p);
+       case 'a':
            current = sect.sct_avail;
            current += amt;
            if (current < 0)
@@ -272,17 +188,8 @@ setsector(void)
            pr("Available in %s changed to %d.\n",
               xyas(sect.sct_x, sect.sct_y, player->cnum), current);
            sect.sct_avail = (short)current;
-           putsect(&sect);
-       }
-       break;
-    case 'w':
-       if (!snxtsct(&nstr, player->argp[2]))
-           return RET_SYN;
-       while (nxtsct(&nstr, &sect) > 0) {
-           if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
-               (*p == '\0'))
-               return RET_SYN;
-           amt = atoi(p);
+           break;
+       case 'w':
            current = sect.sct_work;
            current += amt;
            if (current < 0)
@@ -291,39 +198,21 @@ setsector(void)
                current = 100;
            pr("Work in %s changed to %d.\n",
               xyas(sect.sct_x, sect.sct_y, player->cnum), current);
-           sect.sct_work = (u_char)current;
-           putsect(&sect);
-       }
-       break;
-    case 'f':
-       if (!snxtsct(&nstr, player->argp[2]))
-           return RET_SYN;
-       while (nxtsct(&nstr, &sect) > 0) {
-           if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
-               (*p == '\0'))
-               return RET_SYN;
-           amt = atoi(p);
+           sect.sct_work = (unsigned char)current;
+           break;
+       case 'f':
            current = sect.sct_fertil;
            current += amt;
            if (current < 0)
                current = 0;
-           if (current > 120)
-               current = 120;
+           if (current > 100)
+               current = 100;
            if (sect.sct_own != 0)
                resnoise(&sect, 1, "Fertility content",
                         (int)sect.sct_fertil, current);
-           sect.sct_fertil = (u_char)current;
-           putsect(&sect);
-       }
-       break;
-    case 'u':
-       if (!snxtsct(&nstr, player->argp[2]))
-           return RET_SYN;
-       while (nxtsct(&nstr, &sect) > 0) {
-           if (!(p = getstarg(player->argp[3], "What value : ", buf)) ||
-               (*p == '\0'))
-               return RET_SYN;
-           amt = atoi(p);
+           sect.sct_fertil = (unsigned char)current;
+           break;
+       case 'u':
            current = sect.sct_uran;
            current += amt;
            if (current < 0)
@@ -333,13 +222,13 @@ setsector(void)
            if (sect.sct_own != 0)
                resnoise(&sect, 1, "Uranium content",
                         (int)sect.sct_uran, current);
-           sect.sct_uran = (u_char)current;
-           putsect(&sect);
+           sect.sct_uran = (unsigned char)current;
+           break;
+       default:
+           pr("huh?\n");
+           return RET_SYN;
        }
-       break;
-    default:
-       pr("huh?\n");
-       return RET_SYN;
+       putsect(&sect);
     }
     return RET_OK;
 }
@@ -360,12 +249,12 @@ resbenefit(natid who, int good)
 }
 
 void
-resnoise(struct sctstr *sptr, int public_amt, s_char *name, int old,
+resnoise(struct sctstr *sptr, int public_amt, char *name, int old,
         int new)
 {
-    s_char p[100];
+    char p[100];
 
-    pr("%s of %s changed from %d to %d%%\n",
+    pr("%s of %s changed from %d to %d\n",
        name, xyas(sptr->sct_x, sptr->sct_y, player->cnum), old, new);
     if (public_amt)
        (void)sprintf(p, "changed from %d to %d", old, new);