]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/edit.c
edit: Drop pointless doland() variables old, des
[empserver] / src / lib / commands / edit.c
index b553a7973becf7cf3e0182574158049e2f093fe2..200c1eaaf34f3bebc2108390768767f7299776a1 100644 (file)
 #include "plane.h"
 #include "ship.h"
 
-#define END -1
-
-static int docountry(char, int, char *, struct natstr *);
-static int doland(char, int, char *, struct sctstr *);
-static int doplane(char, int, char *, struct plnstr *);
-static int doship(char, int, char *, struct shpstr *);
-static int dounit(char, int, char *, struct lndstr *);
+static void print_sect(struct sctstr *);
+static void print_nat(struct natstr *);
+static void print_plane(struct plnstr *);
+static void print_land(struct lndstr *);
+static void print_ship(struct shpstr *);
 static int getin(char *, char **);
-static void pr_land(struct lndstr *);
-static void pr_plane(struct plnstr *);
-static void pr_ship(struct shpstr *);
-static void prnat(struct natstr *);
-static void prsect(struct sctstr *);
-
+static int edit_sect(struct sctstr *, char, int, char *);
+static int edit_nat(struct natstr *, char, int, char *);
+static int edit_ship(struct shpstr *, char, int, char *);
+static int edit_land(struct lndstr *, char, int, char *);
+static int edit_plane(struct plnstr *, char, int, char *);
 
 int
 edit(void)
@@ -129,19 +126,19 @@ edit(void)
     if (!player->argp[3]) {
        switch (ewhat) {
        case 'l':
-           prsect(&sect);
+           print_sect(&sect);
            break;
        case 'c':
-           prnat(np);
+           print_nat(np);
            break;
        case 'p':
-           pr_plane(&plane);
+           print_plane(&plane);
            break;
        case 's':
-           pr_ship(&ship);
+           print_ship(&ship);
            break;
        case 'u':
-           pr_land(&land);
+           print_land(&land);
            break;
        }
     }
@@ -160,19 +157,19 @@ edit(void)
            if (err == 0) {
                switch (ewhat) {
                case 'c':
-                   prnat(np);
+                   print_nat(np);
                    break;
                case 'l':
-                   prsect(&sect);
+                   print_sect(&sect);
                    break;
                case 's':
-                   pr_ship(&ship);
+                   print_ship(&ship);
                    break;
                case 'u':
-                   pr_land(&land);
+                   print_land(&land);
                    break;
                case 'p':
-                   pr_plane(&plane);
+                   print_plane(&plane);
                    break;
                }
                return RET_OK;
@@ -184,13 +181,13 @@ edit(void)
 
        switch (ewhat) {
        case 'c':
-           if ((err = docountry(thing, arg, ptr, np)) != RET_OK)
+           if ((err = edit_nat(np, thing, arg, ptr)) != RET_OK)
                return err;
            break;
        case 'l':
            if (!check_sect_ok(&sect))
                return RET_FAIL;
-           if ((err = doland(thing, arg, ptr, &sect)) != RET_OK)
+           if ((err = edit_sect(&sect, thing, arg, ptr)) != RET_OK)
                return err;
            if (!putsect(&sect))
                return RET_FAIL;
@@ -198,7 +195,7 @@ edit(void)
        case 's':
            if (!check_ship_ok(&ship))
                return RET_FAIL;
-           if ((err = doship(thing, arg, ptr, &ship)) != RET_OK)
+           if ((err = edit_ship(&ship, thing, arg, ptr)) != RET_OK)
                return err;
            if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50))
                return RET_FAIL;
@@ -208,7 +205,7 @@ edit(void)
        case 'u':
            if (!check_land_ok(&land))
                return RET_FAIL;
-           if ((err = dounit(thing, arg, ptr, &land)) != RET_OK)
+           if ((err = edit_land(&land, thing, arg, ptr)) != RET_OK)
                return err;
            if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50))
                return RET_FAIL;
@@ -218,7 +215,7 @@ edit(void)
        case 'p':
            if (!check_plane_ok(&plane))
                return RET_FAIL;
-           if ((err = doplane(thing, arg, ptr, &plane)) != RET_OK)
+           if ((err = edit_plane(&plane, thing, arg, ptr)) != RET_OK)
                return err;
            if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50))
                return RET_FAIL;
@@ -258,7 +255,7 @@ noise(struct sctstr *sptr, char *name, int old, int new)
 }
 
 static void
-prsect(struct sctstr *sect)
+print_sect(struct sctstr *sect)
 {
     pr("Location <L>: %s\t", xyas(sect->sct_x, sect->sct_y, player->cnum));
     pr("Distribution sector <D>: %s\n",
@@ -281,9 +278,8 @@ prsect(struct sctstr *sect)
     pr("Defense %% <d>: %d\n", sect->sct_defense);
 }
 
-
 static void
-prnat(struct natstr *np)
+print_nat(struct natstr *np)
 {
     int i;
 
@@ -315,8 +311,9 @@ prnat(struct natstr *np)
 }
 
 static void
-pr_plane(struct plnstr *plane)
+print_plane(struct plnstr *plane)
 {
+    pr("%s %s\n", prnatid(plane->pln_own), prplane(plane));
     pr("UID <U>: %d\t\t", plane->pln_uid);
     pr("Owner <O>: %d\t\t", plane->pln_own);
     pr("Location <l>: %s\n",
@@ -332,8 +329,9 @@ pr_plane(struct plnstr *plane)
 }
 
 static void
-pr_land(struct lndstr *land)
+print_land(struct lndstr *land)
 {
+    pr("%s %s\n", prnatid(land->lnd_own), prland(land));
     pr("UID <U>: %d\n", land->lnd_uid);
     pr("Owner <O>: %d\n", land->lnd_own);
     pr("Location <L>: %s\n", xyas(land->lnd_x, land->lnd_y, player->cnum));
@@ -366,13 +364,9 @@ pr_land(struct lndstr *land)
 }
 
 static void
-pr_ship(struct shpstr *ship)
+print_ship(struct shpstr *ship)
 {
-    struct natstr *natp;
-
-    if (!(natp = getnatp(ship->shp_own)))
-       return;
-    pr("%s (#%d) %s\n", natp->nat_cnam, ship->shp_own, prship(ship));
+    pr("%s %s\n", prnatid(ship->shp_own), prship(ship));
     pr("UID <U>: %d\n", ship->shp_uid);
     pr("Owner <O>: %d\t\t\t", ship->shp_own);
     pr("Location <L>: %s\n", xyas(ship->shp_x, ship->shp_y, player->cnum));
@@ -434,43 +428,39 @@ warn_deprecated(char key)
 #endif
 
 static int
-doland(char op, int arg, char *p, struct sctstr *sect)
+edit_sect(struct sctstr *sect, char op, int arg, char *p)
 {
-    natid newown, oldown;
     coord newx, newy;
-    int new, old;
-    int des;
+    int new;
+
     switch (op) {
     case 'o':
-       if (arg < 0)
+       if (arg < 0 || arg >= MAXNOC)
            return RET_SYN;
-       newown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
-       pr("Owner of %s changed from %s (#%d) to %s (#%d).\n",
+       pr("Owner of %s changed from %s to %s.\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
-          cname(sect->sct_own), sect->sct_own, cname(newown), newown);
+          prnatid(sect->sct_own), prnatid(arg));
        if (sect->sct_own) {
            wu(player->cnum, sect->sct_own,
               "Sector %s lost to deity intervention\n",
               xyas(sect->sct_x, sect->sct_y, sect->sct_own));
        }
        benefit(sect->sct_own, 0);
-       sect->sct_own = newown;
-       if (newown) {
-           wu(player->cnum, newown,
+       sect->sct_own = arg;
+       if (arg) {
+           wu(player->cnum, arg,
               "Sector %s gained from deity intervention\n",
-              xyas(sect->sct_x, sect->sct_y, newown));
+              xyas(sect->sct_x, sect->sct_y, arg));
        }
-       benefit(newown, 1);
+       benefit(arg, 1);
        break;
     case 'O':
-       if (arg < 0)
+       if (arg < 0 || arg >= MAXNOC)
            return RET_SYN;
-       oldown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
-       pr("Old owner of %s changed from %s (#%d) to %s (#%d).\n",
+       pr("Old owner of %s changed from %s to %s.\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
-          cname(sect->sct_oldown),
-          sect->sct_oldown, cname(oldown), oldown);
-       sect->sct_oldown = oldown;
+          prnatid(sect->sct_oldown), prnatid(arg));
+       sect->sct_oldown = arg;
        break;
     case 'e':
        new = LIMIT_TO(arg, 0, 100);
@@ -514,47 +504,47 @@ doland(char op, int arg, char *p, struct sctstr *sect)
        break;
     case 'l':
        new = LIMIT_TO(arg, 0, 127);
-       pr("Loyalty of %s changed from %d to %d%%\n",
+       pr("Loyalty of %s changed from %d to %d\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
           sect->sct_loyal, new);
        sect->sct_loyal = (unsigned char)new;
        break;
     case 'x':
-       old = sect->sct_che;
        new = LIMIT_TO(arg, 0, CHE_MAX);
        pr("Guerillas in %s changed from %d to %d\n",
-          xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
+          xyas(sect->sct_x, sect->sct_y, player->cnum),
+          sect->sct_che, new);
        sect->sct_che = new;
        break;
     case 'X':
-       old = sect->sct_che_target;
-       new = LIMIT_TO(arg, 0, MAXNOC - 1);
-       pr("Che target of %s changed from %s (#%d) to %s (#%d).\n",
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
+       pr("Che target of %s changed from %s to %s.\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
-          cname(old), old, cname(new), new);
-       sect->sct_che_target = new;
-       if (new == 0)
+          prnatid(sect->sct_che_target), prnatid(arg));
+       sect->sct_che_target = arg;
+       if (arg == 0)
            sect->sct_che = 0;
        break;
     case 'p':
-       old = sect->sct_pstage;
        new = LIMIT_TO(arg, 0, PLG_EXPOSED);
-       pr("Plague stage of %s changed from %d to %d%%\n",
-          xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
+       pr("Plague stage of %s changed from %d to %d\n",
+          xyas(sect->sct_x, sect->sct_y, player->cnum),
+          sect->sct_pstage, new);
        sect->sct_pstage = new;
        break;
     case 't':
-       old = sect->sct_ptime;
        new = LIMIT_TO(arg, 0, 255);
-       pr("Plague time of %s changed from %d to %d%%\n",
-          xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
+       pr("Plague time of %s changed from %d to %d\n",
+          xyas(sect->sct_x, sect->sct_y, player->cnum),
+          sect->sct_ptime, new);
        sect->sct_ptime = new;
        break;
     case 'F':
-       old = sect->sct_fallout;
        new = LIMIT_TO(arg, 0, FALLOUT_MAX);
        pr("Fallout for sector %s changed from %d to %d\n",
-          xyas(sect->sct_x, sect->sct_y, player->cnum), old, new);
+          xyas(sect->sct_x, sect->sct_y, player->cnum),
+          sect->sct_fallout, new);
        sect->sct_fallout = new;
        break;
     case 'a':
@@ -585,23 +575,23 @@ doland(char op, int arg, char *p, struct sctstr *sect)
        sect->sct_dist_y = newy;
        break;
     case 's':
-       des = sct_typematch(p);
-       if (des < 0)
+       new = sct_typematch(p);
+       if (new < 0)
            return RET_SYN;
        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, sect->sct_type, des);
-       sect->sct_type = des;
+          dchr[sect->sct_type].d_mnem, dchr[new].d_mnem);
+       set_coastal(sect, sect->sct_type, new);
+       sect->sct_type = new;
        break;
     case 'S':
-       des = sct_typematch(p);
-       if (des < 0)
+       new = sct_typematch(p);
+       if (new < 0)
            return RET_SYN;
        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;
+          dchr[sect->sct_newtype].d_mnem, dchr[new].d_mnem);
+       sect->sct_newtype = new;
        break;
     case 'R':
        new = LIMIT_TO(arg, 0, 100);
@@ -625,9 +615,8 @@ doland(char op, int arg, char *p, struct sctstr *sect)
     return RET_OK;
 }
 
-
 static int
-docountry(char op, int arg, char *p, struct natstr *np)
+edit_nat(struct natstr *np, char op, int arg, char *p)
 {
     coord newx, newy;
     natid nat = np->nat_cnum;
@@ -724,9 +713,8 @@ docountry(char op, int arg, char *p, struct natstr *np)
     return RET_OK;
 }
 
-
 static int
-doship(char op, int arg, char *p, struct shpstr *ship)
+edit_ship(struct shpstr *ship, char op, int arg, char *p)
 {
     coord newx, newy;
 
@@ -748,15 +736,15 @@ doship(char op, int arg, char *p, struct shpstr *ship)
        ef_set_uid(EF_SHIP, ship, arg);
        break;
     case 'O':
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
        if (ship->shp_own)
            wu(player->cnum, ship->shp_own,
               "%s taken from you by deity intervention!\n", prship(ship));
-       if (arg && arg < MAXNOC) {
+       if (arg)
            wu(player->cnum, (natid)arg,
               "%s given to you by deity intervention!\n", prship(ship));
-           ship->shp_own = (natid)arg;
-       } else if (!arg)
-           ship->shp_effic = 0;
+       ship->shp_own = arg;
        break;
     case 'L':
        if (!sarg_xy(p, &newx, &newy))
@@ -831,7 +819,7 @@ doship(char op, int arg, char *p, struct shpstr *ship)
 }
 
 static int
-dounit(char op, int arg, char *p, struct lndstr *land)
+edit_land(struct lndstr *land, char op, int arg, char *p)
 {
     coord newx, newy;
 
@@ -844,16 +832,15 @@ dounit(char op, int arg, char *p, struct lndstr *land)
        ef_set_uid(EF_LAND, land, arg);
        break;
     case 'O':
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
        if (land->lnd_own)
            wu(player->cnum, land->lnd_own,
               "%s taken from you by deity intervention!\n", prland(land));
-
-       if (arg && arg < MAXNOC) {
+       if (arg)
            wu(player->cnum, (natid)arg,
               "%s given to you by deity intervention!\n", prland(land));
-           land->lnd_own = (natid)arg;
-       } else if (!arg)
-           land->lnd_effic = 0;
+       land->lnd_own = arg;
        break;
     case 'L':
        if (!sarg_xy(p, &newx, &newy))
@@ -942,9 +929,8 @@ dounit(char op, int arg, char *p, struct lndstr *land)
     return RET_OK;
 }
 
-
 static int
-doplane(char op, int arg, char *p, struct plnstr *plane)
+edit_plane(struct plnstr *plane, char op, int arg, char *p)
 {
     coord newx, newy;
 
@@ -959,16 +945,16 @@ doplane(char op, int arg, char *p, struct plnstr *plane)
        plane->pln_y = newy;
        break;
     case 'O':
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
        if (plane->pln_own)
            wu(player->cnum, plane->pln_own,
               "%s taken from you by deity intervention!\n",
               prplane(plane));
-       if (arg && arg < MAXNOC) {
-           plane->pln_own = (natid)arg;
-           wu(player->cnum, plane->pln_own,
+       if (arg)
+           wu(player->cnum, arg,
               "%s given to you by deity intervention!\n", prplane(plane));
-       } else if (!arg)
-           plane->pln_effic = 0;
+       plane->pln_own = arg;
        break;
     case 'e':
        plane->pln_effic = LIMIT_TO(arg, PLANE_MINEFF, 100);