]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/edit.c
Make struct sctstr member sct_effic signed
[empserver] / src / lib / commands / edit.c
index 10bb62e7f3641e36d7e7c217a15aa1e579e0d8a3..5d9c767ac5ba40d5879b54ba64062d11e0af4b57 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, 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
  *  ---
  *
  *  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-2009
  */
 
 #include <config.h>
 
 #include <ctype.h>
 #include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include "misc.h"
-#include "player.h"
-#include "plague.h"
-#include "xy.h"
-#include "sect.h"
-#include "nat.h"
-#include "news.h"
-#include "nsc.h"
+#include "commands.h"
 #include "item.h"
-#include "file.h"
-#include "plane.h"
-#include "ship.h"
 #include "land.h"
+#include "lost.h"
+#include "news.h"
 #include "optlist.h"
-#include "commands.h"
+#include "plague.h"
+#include "plane.h"
+#include "ship.h"
 
 #define END -1
 
@@ -93,9 +85,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) {
@@ -108,12 +101,9 @@ edit(void)
            return RET_FAIL;
        break;
     case 'c':
-       if (!(ptr = getstarg(player->argp[2], "Country number? ", buf)))
+       np = natargp(player->argp[2], "Country? ");
+       if (!np)
            return RET_SYN;
-       if (isdigit(*ptr))
-           np = getnatp(atoi(ptr));
-       else
-           np = natargp(ptr, NULL);
        break;
     case 'p':
        if ((num = onearg(player->argp[2], "Plane number? ")) < 0)
@@ -140,7 +130,7 @@ edit(void)
        pr("huh?\n");
        return RET_SYN;
     }
-    if (player->argp[3] == 0) {
+    if (!player->argp[3]) {
        switch (ewhat) {
        case 'l':
            prsect(&sect);
@@ -160,8 +150,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);
@@ -202,12 +192,16 @@ edit(void)
                return err;
            break;
        case 'l':
+           if (!check_sect_ok(&sect))
+               return RET_FAIL;
            if ((err = doland(thing, arg, ptr, &sect)) != RET_OK)
                return err;
            if (!putsect(&sect))
                return RET_FAIL;
            break;
        case 's':
+           if (!check_ship_ok(&ship))
+               return RET_FAIL;
            if ((err = doship(thing, arg, ptr, &ship)) != RET_OK)
                return err;
            if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50))
@@ -216,6 +210,8 @@ edit(void)
                return RET_FAIL;
            break;
        case 'u':
+           if (!check_land_ok(&land))
+               return RET_FAIL;
            if ((err = dounit(thing, arg, ptr, &land)) != RET_OK)
                return err;
            if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50))
@@ -224,6 +220,8 @@ edit(void)
                return RET_FAIL;
            break;
        case 'p':
+           if (!check_plane_ok(&plane))
+               return RET_FAIL;
            if ((err = doplane(thing, arg, ptr, &plane)) != RET_OK)
                return err;
            if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50))
@@ -269,7 +267,7 @@ prsect(struct sctstr *sect)
     pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
     pr("Distribution sector <D>: %s\n",
        xyas(sect->sct_dist_x, sect->sct_dist_y, player->cnum));
-    pr("Designation <s>: %c\t New designation <S>: %c\n",
+    pr("Designation <s>: %c\tNew designation <S>: %c\n",
        dchr[sect->sct_type].d_mnem, dchr[sect->sct_newtype].d_mnem);
     pr("own  oo eff mob min gld frt oil urn wrk lty che ctg plg ptime fall avail\n");
     pr("  o   O   e   m   i   g   f   c   u   w   l   x   X   p     t    F     a\n");
@@ -281,7 +279,7 @@ prsect(struct sctstr *sect)
        sect->sct_pstage, sect->sct_ptime,
        sect->sct_fallout, sect->sct_avail);
 
-    pr("Mines <M>: %d\t", sect->sct_mines);
+    pr("Mines <M>: %d\n", sect->sct_mines);
     pr("Road %% <R>: %d\t", sect->sct_road);
     pr("Rail %% <r>: %d\t", sect->sct_rail);
     pr("Defense %% <d>: %d\n", sect->sct_defense);
@@ -303,15 +301,13 @@ 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]);
     pr("Happiness <H>: %.2f\n", np->nat_level[NAT_HLEV]);
     pr("Money <M>: $%6ld\n", np->nat_money);
     pr("Telegrams <t>: %6d\n", np->nat_tgms);
-    if (opt_DEMANDUPDATE)
-       pr("Updates missed <U>: %d\n", np->nat_missed);
     if (opt_HIDDEN) {
        pr("Countries contacted: ");
        for (i = 0; i < MAXNOC; i++) {
@@ -332,12 +328,11 @@ pr_plane(struct plnstr *plane)
     pr("Efficiency <e>: %d\t", plane->pln_effic);
     pr("Mobility <m>: %d\n", plane->pln_mobil);
     pr("Tech <t>: %d\t\t", plane->pln_tech);
-    pr("Wing <w>: %c\n", plane->pln_wing);
+    pr("Wing <w>: %.1s\n", &plane->pln_wing);
     pr("Range <r>: %d\t\t", plane->pln_range);
     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
@@ -349,13 +344,10 @@ pr_land(struct lndstr *land)
     pr("Efficiency <e>: %d\t", land->lnd_effic);
     pr("Mobility <M>: %d\n", land->lnd_mobil);
     pr("Tech <t>: %d\t\t", land->lnd_tech);
-    pr("Army <a>: %c\n", land->lnd_army);
+    pr("Army <a>: %.1s\n", &land->lnd_army);
     pr("Fortification <F>: %d\t", land->lnd_harden);
-    pr("Fuel <B>: %d\n", land->lnd_fuel);
-    count_land_planes(land);
     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);
@@ -382,7 +374,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);
@@ -391,12 +383,7 @@ pr_ship(struct shpstr *ship)
     pr("Tech <T>: %d\t\t\t", ship->shp_tech);
     pr("Efficiency <E>: %d\n", ship->shp_effic);
     pr("Mobility <M>: %d\t\t", ship->shp_mobil);
-    pr("Fleet <F>: %c\n", ship->shp_fleet);
-    count_planes(ship);
-    count_units(ship);
-    /* could depend on opt_FUEL - but a deity might want to set this
-       up before enabling the option */
-    pr("Fuel <B>: %d\t\t\t", ship->shp_fuel);
+    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);
@@ -466,15 +453,6 @@ doland(char op, int arg, char *p, struct sctstr *sect)
     int new, old;
     int des;
     switch (op) {
-    case 'C':
-       warn_deprecated(op);
-       if (arg < 0)
-           return RET_SYN;
-       sect->sct_coastal = (arg ? 1 : 0);
-       pr("Coastal flag of %s changed to %d\n",
-          xyas(sect->sct_x, sect->sct_y, player->cnum),
-          sect->sct_coastal);
-       break;
     case 'o':
        if (arg < 0)
            return RET_SYN;
@@ -483,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));
@@ -492,7 +468,6 @@ 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));
@@ -512,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);
@@ -566,10 +541,12 @@ doland(char op, int arg, char *p, struct sctstr *sect)
     case 'X':
        old = sect->sct_che_target;
        new = errcheck(arg, 0, MAXNOC - 1);
-       pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
+       pr("Che target of %s changed from %s (#%d) to %s (#%d).\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
           cname(old), old, cname(new), new);
        sect->sct_che_target = new;
+       if (new == 0)
+           sect->sct_che = 0;
        break;
     case 'p':
        old = sect->sct_pstage;
@@ -607,6 +584,7 @@ doland(char op, int arg, char *p, struct sctstr *sect)
            return RET_SYN;
        sect->sct_x = newx;
        sect->sct_y = newy;
+       ef_set_uid(EF_SECTOR, &sect, XYOFFSET(newx, newy));
        break;
     case 'D':
        if (!sarg_xy(p, &newx, &newy))
@@ -625,7 +603,7 @@ doland(char op, int arg, char *p, struct sctstr *sect)
        pr("Designation for sector %s changed from %c to %c\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
           dchr[sect->sct_type].d_mnem, dchr[des].d_mnem);
-       set_coastal(sect, des);
+       set_coastal(sect, sect->sct_type, des);
        sect->sct_type = des;
        break;
     case 'S':
@@ -678,8 +656,10 @@ docountry(char op, int arg, char *p, struct natstr *np)
 
     switch (op) {
     case 'n':
+       if (!check_nat_name(p))
+           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",
@@ -722,13 +702,13 @@ docountry(char op, int arg, char *p, struct natstr *np)
        np->nat_yorg = newy;
        break;
     case 's':
-       np->nat_stat = (nat_status)errcheck(arg, STAT_UNUSED, STAT_GOD);
+       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);
@@ -757,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':
-       np->nat_missed = arg;
-       break;
     default:
        pr("huh? (%c)\n", op);
        break;
@@ -788,16 +765,8 @@ doship(char op, int arg, char *p, struct shpstr *ship)
     case 'W':
        ship->shp_rflags = arg;
        break;
-    case 'H':
-       warn_deprecated(op);
-       ship->shp_nchoppers = arg;
-       break;
-    case 'X':
-       warn_deprecated(op);
-       ship->shp_nxlight = arg;
-       break;
     case 'U':
-       ship->shp_uid = arg;
+       ef_set_uid(EF_SHIP, ship, arg);
        break;
     case 'O':
        if (ship->shp_own)
@@ -806,17 +775,9 @@ 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) {
+       } else if (!arg)
            ship->shp_effic = 0;
-           makelost(EF_SHIP, ship->shp_own, ship->shp_uid,
-                    ship->shp_x, ship->shp_y);
-           ship->shp_own = (natid)0;
-       }
        break;
     case 'L':
        if (!sarg_xy(p, &newx, &newy))
@@ -836,11 +797,11 @@ doship(char op, int arg, char *p, struct shpstr *ship)
        ship->shp_mobil = arg;
        break;
     case 'B':
-       ship->shp_fuel = errcheck(arg, 0, 255);
+       warn_deprecated(op);
        break;
     case 'F':
        if (p[0] == '~')
-           ship->shp_fleet = ' ';
+           ship->shp_fleet = 0;
        else if (isalpha(p[0]))
            ship->shp_fleet = p[0];
        else {
@@ -848,14 +809,6 @@ doship(char op, int arg, char *p, struct shpstr *ship)
            return RET_FAIL;
        }
        break;
-    case 'Y':
-       warn_deprecated(op);
-       ship->shp_nland = errcheck(arg, 0, 100);
-       break;
-    case 'P':
-       warn_deprecated(op);
-       ship->shp_nplane = errcheck(arg, 0, 100);
-       break;
     case 'c':
        ship->shp_item[I_CIVIL] = arg;
        break;
@@ -913,7 +866,7 @@ dounit(char op, int arg, char *p, struct lndstr *land)
        land->lnd_land = arg;
        break;
     case 'U':
-       land->lnd_uid = arg;
+       ef_set_uid(EF_LAND, land, arg);
        break;
     case 'O':
        if (land->lnd_own)
@@ -923,17 +876,9 @@ 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) {
-           makelost(EF_LAND, land->lnd_own, land->lnd_uid,
-                    land->lnd_x, land->lnd_y);
+       } else if (!arg)
            land->lnd_effic = 0;
-           land->lnd_own = (natid)0;
-       }
        break;
     case 'L':
        if (!sarg_xy(p, &newx, &newy))
@@ -954,7 +899,7 @@ dounit(char op, int arg, char *p, struct lndstr *land)
        break;
     case 'a':
        if (p[0] == '~')
-           land->lnd_army = ' ';
+           land->lnd_army = 0;
        else if (isalpha(p[0]))
            land->lnd_army = p[0];
        else {
@@ -966,17 +911,13 @@ dounit(char op, int arg, char *p, struct lndstr *land)
        land->lnd_harden = errcheck(arg, 0, 255);
        break;
     case 'B':
-       land->lnd_fuel = errcheck(arg, 0, 255);
-       break;
-    case 'X':
        warn_deprecated(op);
-       land->lnd_nxlight = arg;
        break;
     case 'S':
        land->lnd_ship = arg;
        break;
     case 'P':
-       land->lnd_rad_max = arg;
+       warn_deprecated(op);
        break;
     case 'Z':
        land->lnd_retreat = arg;
@@ -1034,17 +975,17 @@ 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;
+       warn_deprecated(op);
        break;
     case 'U':
-       plane->pln_uid = arg;
+       ef_set_uid(EF_PLANE, plane, arg);
        break;
     case 'l':
        if (!sarg_xy(p, &newx, &newy))
@@ -1058,19 +999,11 @@ 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) {
+       } else if (!arg)
            plane->pln_effic = 0;
-           makelost(EF_PLANE, plane->pln_own, plane->pln_uid,
-                    plane->pln_x, plane->pln_y);
-           plane->pln_own = (natid)0;
-       }
        break;
     case 'e':
        plane->pln_effic = errcheck(arg, PLANE_MINEFF, 100);
@@ -1085,7 +1018,7 @@ doplane(char op, int arg, char *p, struct plnstr *plane)
        break;
     case 'w':
        if (p[0] == '~')
-           plane->pln_wing = ' ';
+           plane->pln_wing = 0;
        else if (isalpha(p[0]))
            plane->pln_wing = p[0];
        else {
@@ -1093,14 +1026,6 @@ doplane(char op, int arg, char *p, struct plnstr *plane)
            return RET_FAIL;
        }
        break;
-    case 'a':
-       warn_deprecated(op);
-       plane->pln_att = arg;
-       break;
-    case 'd':
-       warn_deprecated(op);
-       plane->pln_def = arg;
-       break;
     case 'r':
        plane->pln_range = (unsigned char)arg;
        break;