]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/edit.c
Update copyright notice
[empserver] / src / lib / commands / edit.c
index 800da73215fcaf51d70c24295f59d2bd722f9d82..6d1fb9a43130be1ac43902431cdbfe902247abf8 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2012, 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/>.
  *
  *  ---
  *
  *  ---
  *
  *  edit.c: Edit things (sectors, ships, planes, units, nukes, countries)
- * 
+ *
  *  Known contributors to this file:
  *     David Muir Sharnoff
  *     Chad Zabel, 1994
  *     Steve McClure, 1998-2000
- *     Ron Koenderink, 2003-2004
- *     Markus Armbruster, 2003-2006
+ *     Ron Koenderink, 2003-2009
+ *     Markus Armbruster, 2003-2011
  */
 
 #include <config.h>
@@ -42,7 +41,6 @@
 #include "commands.h"
 #include "item.h"
 #include "land.h"
-#include "lost.h"
 #include "news.h"
 #include "optlist.h"
 #include "plague.h"
@@ -85,9 +83,10 @@ edit(void)
     char buf[1024];
     char ewhat;
 
-    if ((what = getstarg(player->argp[1],
-                        "Edit What (country, land, ship, plane, nuke, unit)? ",
-                        buf)) == 0)
+    what = getstarg(player->argp[1],
+                   "Edit what (country, land, ship, plane, nuke, unit)? ",
+                   buf);
+    if (!what)
        return RET_SYN;
     ewhat = what[0];
     switch (ewhat) {
@@ -129,7 +128,7 @@ edit(void)
        pr("huh?\n");
        return RET_SYN;
     }
-    if (player->argp[3] == 0) {
+    if (!player->argp[3]) {
        switch (ewhat) {
        case 'l':
            prsect(&sect);
@@ -149,8 +148,8 @@ edit(void)
        }
     }
     for (;;) {
-       if (player->argp[arg_index] != 0) {
-           if (player->argp[arg_index+1] != 0) {
+       if (player->argp[arg_index]) {
+           if (player->argp[arg_index+1]) {
                thing = player->argp[arg_index++][0];
                ptr = player->argp[arg_index++];
                arg = atoi(ptr);
@@ -300,7 +299,7 @@ prnat(struct natstr *np)
     pr("Origin <o>: %3s\n",
        xyas(np->nat_xorg, np->nat_yorg, player->cnum));
     pr("Status <s>: 0x%x\t\t\t", np->nat_stat);
-    pr("Min Used <u>: %3d\n", np->nat_minused);
+    pr("Seconds Used <u>: %3d\n", np->nat_timeused);
     pr("Technology <T>: %.2f\t\t", np->nat_level[NAT_TLEV]);
     pr("Research <R>: %.2f\n", np->nat_level[NAT_RLEV]);
     pr("Education <E>: %.2f\t\t", np->nat_level[NAT_ELEV]);
@@ -332,7 +331,6 @@ pr_plane(struct plnstr *plane)
     pr("Flags <f>: %d\n", plane->pln_flags);
     pr("Ship <s>: %d\t\t", plane->pln_ship);
     pr("Land Unit <y>: %d\t", plane->pln_land);
-    pr("Nuke Type <n>: %d\n", plane->pln_nuketype);
 }
 
 static void
@@ -348,7 +346,6 @@ pr_land(struct lndstr *land)
     pr("Fortification <F>: %d\t", land->lnd_harden);
     pr("Land unit <Y>: %d\n", land->lnd_land);
     pr("Ship <S>: %d\t\t", land->lnd_ship);
-    pr("Radius <P>: %d\n", land->lnd_rad_max);
     pr("Retreat percentage <Z>: %d\n", land->lnd_retreat);
     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
        land->lnd_rpath, land->lnd_rflags);
@@ -375,7 +372,7 @@ pr_ship(struct shpstr *ship)
 {
     struct natstr *natp;
 
-    if ((natp = getnatp(ship->shp_own)) == 0)
+    if (!(natp = getnatp(ship->shp_own)))
        return;
     pr("%s (#%d) %s\n", natp->nat_cnam, ship->shp_own, prship(ship));
     pr("UID <U>: %d\n", ship->shp_uid);
@@ -387,7 +384,7 @@ pr_ship(struct shpstr *ship)
     pr("Fleet <F>: %.1s\n", &ship->shp_fleet);
     pr("Retreat path <R>: '%s'\t\tRetreat Flags <W>: %d\n",
        ship->shp_rpath, ship->shp_rflags);
-    pr("Plague Stage <a>: %d\t\t",ship->shp_pstage);
+    pr("Plague Stage <a>: %d\t\t", ship->shp_pstage);
     pr("Plague Time <b>: %d\n", ship->shp_ptime);
     pr("civ mil  uw food shl gun  pet  irn  dst  oil  lcm  hcm rad\n");
     pr("  c   m   u    f   s   g    p    i    d    o    l    h   r\n");
@@ -440,11 +437,13 @@ getin(char *buf, char **valp)
     return thing;
 }
 
+#if 0  /* not needed right now */
 static void
 warn_deprecated(char key)
 {
     pr("Key <%c> is deprecated and will go away in a future release\n", key);
 }
+#endif
 
 static int
 doland(char op, int arg, char *p, struct sctstr *sect)
@@ -462,8 +461,6 @@ doland(char op, int arg, char *p, struct sctstr *sect)
           xyas(sect->sct_x, sect->sct_y, player->cnum),
           cname(sect->sct_own), sect->sct_own, cname(newown), newown);
        if (sect->sct_own) {
-           makelost(EF_SECTOR, sect->sct_own, 0,
-                    sect->sct_x, sect->sct_y);
            wu(player->cnum, sect->sct_own,
               "Sector %s lost to deity intervention\n",
               xyas(sect->sct_x, sect->sct_y, sect->sct_own));
@@ -471,10 +468,9 @@ doland(char op, int arg, char *p, struct sctstr *sect)
        benefit(sect->sct_own, 0);
        sect->sct_own = newown;
        if (newown) {
-           makenotlost(EF_SECTOR, newown, 0, sect->sct_x, sect->sct_y);
            wu(player->cnum, newown,
               "Sector %s gained from deity intervention\n",
-              xyas(sect->sct_x, sect->sct_y, sect->sct_own));
+              xyas(sect->sct_x, sect->sct_y, newown));
        }
        benefit(newown, 1);
        break;
@@ -491,7 +487,7 @@ doland(char op, int arg, char *p, struct sctstr *sect)
     case 'e':
        new = errcheck(arg, 0, 100);
        noise(sect, "Efficiency", sect->sct_effic, new);
-       sect->sct_effic = (unsigned char)new;
+       sect->sct_effic = new;
        break;
     case 'm':
        new = errcheck(arg, -127, 255);
@@ -593,7 +589,7 @@ doland(char op, int arg, char *p, struct sctstr *sect)
     case 'D':
        if (!sarg_xy(p, &newx, &newy))
            return RET_SYN;
-       pr("Distribution Location for sector %s changed from %s to %s\n",
+       pr("Distribution location for sector %s changed from %s to %s\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
           xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum),
           xyas(newx, newy, player->cnum));
@@ -614,7 +610,7 @@ doland(char op, int arg, char *p, struct sctstr *sect)
        des = sct_typematch(p);
        if (des < 0)
            return RET_SYN;
-       pr("New Designation for sector %s changed from %c to %c\n",
+       pr("New designation for sector %s changed from %c to %c\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
           dchr[sect->sct_newtype].d_mnem, dchr[des].d_mnem);
        sect->sct_newtype = des;
@@ -660,8 +656,10 @@ docountry(char op, int arg, char *p, struct natstr *np)
 
     switch (op) {
     case 'n':
+       if (!check_nat_name(p, nat))
+           return RET_SYN;
        pr("Country name changed from %s to %s\n", np->nat_cnam, p);
-       strncpy(np->nat_cnam, p, sizeof(np->nat_cnam) - 1);
+       strcpy(np->nat_cnam, p);
        break;
     case 'r':
        pr("Country representative changed from %s to %s\n",
@@ -678,10 +676,10 @@ docountry(char op, int arg, char *p, struct natstr *np)
        break;
     case 'm':
        benefit(nat, np->nat_reserve < arg);
-       pr("Military Reserves changed from %ld to %d\n",
+       pr("Military reserves changed from %ld to %d\n",
           np->nat_reserve, arg);
        wu(player->cnum, nat,
-          "Military Reserves changed from %ld to %d by divine intervention.\n",
+          "Military reserves changed from %ld to %d by divine intervention.\n",
           np->nat_reserve, arg);
        np->nat_reserve = arg;
        break;
@@ -707,10 +705,10 @@ docountry(char op, int arg, char *p, struct natstr *np)
        np->nat_stat = errcheck(arg, STAT_UNUSED, STAT_GOD);
        break;
     case 'u':
-       arg = errcheck(arg, 0, m_m_p_d);
-       pr("Number of minutes used changed from %d to %d.\n",
-          np->nat_minused, arg);
-       np->nat_minused = arg;
+       arg = errcheck(arg, 0, m_m_p_d * 60);
+       pr("Number of seconds used changed from %d to %d.\n",
+          np->nat_timeused, arg);
+       np->nat_timeused = arg;
        break;
     case 'M':
        pr("Money changed from %ld to %d\n", np->nat_money, arg);
@@ -739,9 +737,6 @@ docountry(char op, int arg, char *p, struct natstr *np)
           np->nat_level[NAT_HLEV], farg);
        np->nat_level[NAT_HLEV] = farg;
        break;
-    case 'U':
-       warn_deprecated(op);
-       break;
     default:
        pr("huh? (%c)\n", op);
        break;
@@ -780,11 +775,7 @@ doship(char op, int arg, char *p, struct shpstr *ship)
        if (arg && arg < MAXNOC) {
            wu(player->cnum, (natid)arg,
               "%s given to you by deity intervention!\n", prship(ship));
-           makelost(EF_SHIP, ship->shp_own, ship->shp_uid,
-                    ship->shp_x, ship->shp_y);
            ship->shp_own = (natid)arg;
-           makenotlost(EF_SHIP, ship->shp_own, ship->shp_uid,
-                       ship->shp_x, ship->shp_y);
        } else if (!arg)
            ship->shp_effic = 0;
        break;
@@ -805,9 +796,6 @@ doship(char op, int arg, char *p, struct shpstr *ship)
     case 'M':
        ship->shp_mobil = arg;
        break;
-    case 'B':
-       warn_deprecated(op);
-       break;
     case 'F':
        if (p[0] == '~')
            ship->shp_fleet = 0;
@@ -885,11 +873,7 @@ dounit(char op, int arg, char *p, struct lndstr *land)
        if (arg && arg < MAXNOC) {
            wu(player->cnum, (natid)arg,
               "%s given to you by deity intervention!\n", prland(land));
-           makelost(EF_LAND, land->lnd_own, land->lnd_uid,
-                    land->lnd_x, land->lnd_y);
            land->lnd_own = (natid)arg;
-           makenotlost(EF_LAND, land->lnd_own, land->lnd_uid,
-                       land->lnd_x, land->lnd_y);
        } else if (!arg)
            land->lnd_effic = 0;
        break;
@@ -923,15 +907,9 @@ dounit(char op, int arg, char *p, struct lndstr *land)
     case 'F':
        land->lnd_harden = errcheck(arg, 0, 255);
        break;
-    case 'B':
-       warn_deprecated(op);
-       break;
     case 'S':
        land->lnd_ship = arg;
        break;
-    case 'P':
-       land->lnd_rad_max = arg;
-       break;
     case 'Z':
        land->lnd_retreat = arg;
        break;
@@ -988,15 +966,12 @@ dounit(char op, int arg, char *p, struct lndstr *land)
 }
 
 
-int
+static int
 doplane(char op, int arg, char *p, struct plnstr *plane)
 {
     coord newx, newy;
 
     switch (op) {
-    case 'n':
-       plane->pln_nuketype = arg;
-       break;
     case 'U':
        ef_set_uid(EF_PLANE, plane, arg);
        break;
@@ -1012,11 +987,7 @@ doplane(char op, int arg, char *p, struct plnstr *plane)
               "%s taken from you by deity intervention!\n",
               prplane(plane));
        if (arg && arg < MAXNOC) {
-           makelost(EF_PLANE, plane->pln_own, plane->pln_uid,
-                    plane->pln_x, plane->pln_y);
            plane->pln_own = (natid)arg;
-           makenotlost(EF_PLANE, plane->pln_own, plane->pln_uid,
-                       plane->pln_x, plane->pln_y);
            wu(player->cnum, plane->pln_own,
               "%s given to you by deity intervention!\n", prplane(plane));
        } else if (!arg)