]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/setsect.c
License upgrade to GPL version 3 or later
[empserver] / src / lib / commands / setsect.c
index 777847fbef8862fb2c2f3b944886b453f01560fc..68d0027b71e5c93ba6305753cb22f44435494706 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-2011, 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/>.
  *
  *  ---
  *
@@ -26,7 +25,7 @@
  *  ---
  *
  *  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 "lost.h"
+#include "news.h"
 #include "optlist.h"
 
 
@@ -55,16 +46,17 @@ 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];
@@ -74,8 +66,8 @@ setsector(void)
        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'))
+           p = getstarg(player->argp[3], "What value : ", buf);
+           if (!p || !*p)
                return RET_SYN;
            amt = atoi(p);
            current = sect.sct_min;
@@ -95,8 +87,8 @@ setsector(void)
        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'))
+           p = getstarg(player->argp[3], "What value : ", buf);
+           if (!p || !*p)
                return RET_SYN;
            amt = atoi(p);
            current = sect.sct_gmin;
@@ -118,8 +110,8 @@ setsector(void)
            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'))
+               p = getstarg(player->argp[3], "What value : ", buf);
+               if (!p || !*p)
                    return RET_SYN;
                amt = atoi(p);
                current = sect.sct_oil;
@@ -139,8 +131,8 @@ setsector(void)
            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'))
+               p = getstarg(player->argp[3], "What value : ", buf);
+               if (!p || !*p)
                    return RET_SYN;
                amt = atoi(p);
                if ((amt < 0) || (amt > MAXNOC - 1))
@@ -157,10 +149,6 @@ 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);
            }
@@ -169,8 +157,8 @@ setsector(void)
            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'))
+               p = getstarg(player->argp[3], "What value : ", buf);
+               if (!p || !*p)
                    return RET_SYN;
                amt = atoi(p);
                if ((amt < 0) || (amt > MAXNOC - 1))
@@ -192,8 +180,8 @@ setsector(void)
        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'))
+           p = getstarg(player->argp[3], "What value : ", buf);
+           if (!p || !*p)
                return RET_SYN;
            amt = atoi(p);
            current = sect.sct_effic;
@@ -204,7 +192,7 @@ 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 = (unsigned char)current;
+           sect.sct_effic = current;
            putsect(&sect);
        }
        break;
@@ -214,8 +202,8 @@ setsector(void)
            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'))
+               p = getstarg(player->argp[3], "What value : ", buf);
+               if (!p || !*p)
                    return RET_SYN;
                amt = atoi(p);
                current = sect.sct_mines;
@@ -234,8 +222,8 @@ setsector(void)
            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'))
+               p = getstarg(player->argp[3], "What value : ", buf);
+               if (!p || !*p)
                    return RET_SYN;
                amt = atoi(p);
                current = sect.sct_mobil;
@@ -246,7 +234,7 @@ 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;
+               sect.sct_mobil = current;
                putsect(&sect);
            }
            break;
@@ -259,8 +247,8 @@ setsector(void)
        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'))
+           p = getstarg(player->argp[3], "What value : ", buf);
+           if (!p || !*p)
                return RET_SYN;
            amt = atoi(p);
            current = sect.sct_avail;
@@ -279,8 +267,8 @@ setsector(void)
        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'))
+           p = getstarg(player->argp[3], "What value : ", buf);
+           if (!p || !*p)
                return RET_SYN;
            amt = atoi(p);
            current = sect.sct_work;
@@ -299,16 +287,16 @@ setsector(void)
        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'))
+           p = getstarg(player->argp[3], "What value : ", buf);
+           if (!p || !*p)
                return RET_SYN;
            amt = atoi(p);
            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);
@@ -320,8 +308,8 @@ setsector(void)
        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'))
+           p = getstarg(player->argp[3], "What value : ", buf);
+           if (!p || !*p)
                return RET_SYN;
            amt = atoi(p);
            current = sect.sct_uran;
@@ -360,12 +348,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);