]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/load.c
commands: Rename the command functions
[empserver] / src / lib / commands / load.c
index 96af9887de1bafb3224ae01c5c4df48266e79fcb..b3e9b60c1e4899945e214a21b44312359cc61eb7 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2021, 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/>.
  *
  *  ---
  *
  *     David Sharnoff, 1987
  *     Ken Stevens, 1995 (rewritten)
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2009
+ *     Markus Armbruster, 2004-2018
  */
 
 #include <config.h>
 
 #include <ctype.h>
 #include "commands.h"
-#include "empobj.h"
 #include "item.h"
 #include "land.h"
 #include "optlist.h"
 #include "ship.h"
 #include "unit.h"
 
-/*
- * The values 1 and -1 are important below, don't change them.
- */
-#define        LOAD    1
-#define        UNLOAD  -1
-
 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
-                          int noisy, int load_unload, int *nshipsp);
+                          int noisy, int loading, int *nshipsp);
 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
-                         int noisy, int load_unload, int *nshipsp);
+                         int noisy, int loading, int *nshipsp);
 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
-                         struct ichrstr *ich, int load_unload,
+                         struct ichrstr *ich, int loading,
                          int *nshipsp);
 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
-                          int noisy, int load_unload, int *nunitsp);
+                          int noisy, int loading, int *nunitsp);
 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
-                         int noisy, int load_unload, int *nunitsp);
+                         int noisy, int loading, int *nunitsp);
 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
-                         struct ichrstr *ich, int load_unload,
+                         struct ichrstr *ich, int loading,
                          int *nunitsp);
 
 int
-load(void)
+c_load(void)
 {
+    int loading = **player->argp == 'l';
     int noisy;
-    int load_unload;
     int type;
     struct nstr_item nbst;
     struct ichrstr *ich;
@@ -83,9 +75,9 @@ load(void)
     char *p;
     char buf[1024];
 
-    if (!(p = getstarg(player->argp[1],
-                      "What commodity (or 'plane' or 'land')? ", buf))
-       || !*p)
+    p = getstarg(player->argp[1],
+                "What commodity (or 'plane' or 'land')? ", buf);
+    if (!p || !*p)
        return RET_SYN;
 
     if (!strncmp(p, "plane", 5))
@@ -95,43 +87,40 @@ load(void)
     else if (NULL != (ich = item_by_name(p)))
        type = EF_SECTOR;
     else {
-       pr("Can't load '%s'\n", p);
+       pr("Can't %sload '%s'\n", loading ? "" : "un", p);
        return RET_SYN;
     }
 
-    if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
+    p = getstarg(player->argp[2], "Ship(s): ", buf);
+    if (!p || !*p)
        return RET_SYN;
 
-    noisy = isdigit(*p);
-
     if (!snxtitem(&nbst, EF_SHIP, p, NULL))
        return RET_SYN;
 
-    load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
+    noisy = nbst.sel == NS_LIST;
 
     nships = 0;
     while (nxtitem(&nbst, &ship)) {
        if (!ship.shp_own)
            continue;
        if (!player->owner) {
-           if (load_unload == UNLOAD || !noisy)
+           if (!loading || !noisy)
                continue;
-           if (getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY)
+           if (relations_with(ship.shp_own, player->cnum) < FRIENDLY)
                continue;
        }
 
        if (!getsect(ship.shp_x, ship.shp_y, &sect))    /* XXX */
            continue;
-       if (!sect.sct_own)
-           continue;
        if (!player->owner) {
            if (ship.shp_own != player->cnum)
                continue;
            if (!sect_has_dock(&sect))
                continue;
-           if (load_unload == LOAD) {
+           if (loading) {
                if (noisy)
-                   pr("You don't own %s \n",
+                   pr("You don't own %s\n",
                       xyas(sect.sct_x, sect.sct_y, player->cnum));
                continue;
            }
@@ -142,8 +131,9 @@ load(void)
                   xyas(sect.sct_x, sect.sct_y, player->cnum));
            continue;
        }
-       if (!player->owner && load_unload == UNLOAD
-           && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
+       if (!loading
+           && !player->owner
+           && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
            if (noisy)
                pr("You can't unload into an unfriendly %s\n",
                   dchr[sect.sct_type].d_name);
@@ -159,30 +149,26 @@ load(void)
 
        if (opt_MARKET) {
            if (ontradingblock(EF_SHIP, &ship)) {
-               pr("You cannot load/unload an item on the trading block!\n");
+               if (noisy)
+                   pr("%s is on the trading block\n", prship(&ship));
                continue;
            }
        }
 
        switch (type) {
        case EF_PLANE:
-           if (0 !=
-               (retval =
-                load_plane_ship(&sect, &ship, noisy, load_unload,
-                                &nships)))
+           retval = load_plane_ship(&sect, &ship, noisy, loading, &nships);
+           if (retval != 0)
                return retval;
            break;
        case EF_LAND:
-           if (0 !=
-               (retval =
-                load_land_ship(&sect, &ship, noisy, load_unload,
-                               &nships)))
+           retval = load_land_ship(&sect, &ship, noisy, loading, &nships);
+           if (retval != 0)
                return retval;
            break;
        case EF_SECTOR:
-           if (0 !=
-               (retval =
-                load_comm_ship(&sect, &ship, ich, load_unload, &nships)))
+           retval = load_comm_ship(&sect, &ship, ich, loading, &nships);
+           if (retval != 0)
                return retval;
        }
        /* load/unload plague */
@@ -199,15 +185,15 @@ load(void)
        pr("No ships affected\n");
     else
        pr("%d ship%s %sloaded\n", nships, splur(nships),
-          load_unload == UNLOAD ? "un" : "");
+          loading ? "" : "un");
     return RET_OK;
 }
 
 int
-lload(void)
+c_lload(void)
 {
+    int loading = player->argp[0][1] == 'l';
     int noisy;
-    int load_unload;
     int type;
     struct nstr_item nbst;
     struct ichrstr *ich;
@@ -218,9 +204,9 @@ lload(void)
     char *p;
     char buf[1024];
 
-    if (!(p = getstarg(player->argp[1],
-                      "What commodity (or 'plane' or 'land')? ", buf))
-       || !*p)
+    p = getstarg(player->argp[1],
+                "What commodity (or 'plane' or 'land')? ", buf);
+    if (!p || !*p)
        return RET_SYN;
     if (!strncmp(p, "plane", 5))
        type = EF_PLANE;
@@ -229,28 +215,27 @@ lload(void)
     else if (NULL != (ich = item_by_name(p)))
        type = EF_SECTOR;
     else {
-       pr("Can't load '%s'\n", p);
+       pr("Can't %sload '%s'\n", loading ? "" : "un", p);
        return RET_SYN;
     }
 
-    if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
+    p = getstarg(player->argp[2], "Unit(s): ", buf);
+    if (!p || !*p)
        return RET_SYN;
 
-    noisy = isdigit(*p);
-
     if (!snxtitem(&nbst, EF_LAND, p, NULL))
        return RET_SYN;
 
-    load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
+    noisy = nbst.sel == NS_LIST;
 
     nunits = 0;
     while (nxtitem(&nbst, &land)) {
        if (land.lnd_own == 0)
            continue;
        if (!player->owner) {
-           if (load_unload == UNLOAD || !noisy)
+           if (!loading || !noisy)
                continue;
-           if (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)
+           if (relations_with(land.lnd_own, player->cnum) != ALLIED)
                continue;
        }
 
@@ -259,45 +244,42 @@ lload(void)
        if (!player->owner) {
            if (land.lnd_own != player->cnum)
                continue;
-           if (load_unload == LOAD) {
+           if (loading) {
                if (noisy)
                    pr("Sector %s is not yours.\n",
                       xyas(sect.sct_x, sect.sct_y, player->cnum));
                continue;
            }
-           if (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
-               pr("Sector %s is not yours.\n",
-                  xyas(sect.sct_x, sect.sct_y, player->cnum));
+           if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
+               if (noisy)
+                   pr("Sector %s is not yours.\n",
+                      xyas(sect.sct_x, sect.sct_y, player->cnum));
                continue;
            }
        }
 
        if (opt_MARKET) {
            if (ontradingblock(EF_LAND, &land)) {
-               pr("You cannot load/unload an item on the trading block!\n");
+               if (noisy)
+                   pr("%s is on the trading block\n", prland(&land));
                continue;
            }
        }
 
        switch (type) {
        case EF_LAND:
-           if (0 !=
-               (retval =
-                load_land_land(&sect, &land, noisy, load_unload,
-                               &nunits)))
+           retval = load_land_land(&sect, &land, noisy, loading, &nunits);
+           if (retval != 0)
                return retval;
            break;
        case EF_PLANE:
-           if (0 !=
-               (retval =
-                load_plane_land(&sect, &land, noisy, load_unload,
-                                &nunits)))
+           retval = load_plane_land(&sect, &land, noisy, loading, &nunits);
+           if (retval != 0)
                return retval;
            break;
        case EF_SECTOR:
-           if (0 !=
-               (retval =
-                load_comm_land(&sect, &land, ich, load_unload, &nunits)))
+           retval = load_comm_land(&sect, &land, ich, loading, &nunits);
+           if (retval != 0)
                return retval;
        }
        /* load/unload plague */
@@ -315,32 +297,26 @@ lload(void)
        pr("No units affected\n");
     else
        pr("%d unit%s %sloaded\n", nunits, splur(nunits),
-          load_unload == UNLOAD ? "un" : "");
+          loading ? "" : "un");
     return RET_OK;
 }
 
 static int
 move_amount(int sect_amt, int unit_amt, int unit_max,
-           int load_unload, int amount)
+          int loading, int amount)
 {
     int move_amt;
 
     if (amount < 0)
        move_amt = -amount - unit_amt;
     else
-       move_amt = load_unload == LOAD ? amount : -amount;
-    if (move_amt > unit_max - unit_amt)
-       move_amt = unit_max - unit_amt;
-    if (move_amt < -unit_amt)
-       move_amt = -unit_amt;
-    if (move_amt > sect_amt)
-       move_amt = sect_amt;
-    if (move_amt < sect_amt - ITEM_MAX)
-       move_amt = sect_amt - ITEM_MAX;
+       move_amt = loading ? amount : -amount;
+    move_amt = LIMIT_TO(move_amt, -unit_amt, unit_max - unit_amt);
+    move_amt = LIMIT_TO(move_amt, sect_amt - ITEM_MAX, sect_amt);
     return move_amt;
 }
 
-static int
+int
 load_comm_ok(struct sctstr *sectp, natid unit_own,
             i_type item, int move_amt)
 {
@@ -365,7 +341,7 @@ void
 gift(natid givee, natid giver, void *ptr, char *mesg)
 {
     if (giver != givee)
-       wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
+       wu(0, givee, "%s %s %s\n", cname(giver), unit_nameof(ptr), mesg);
     unit_give_away(ptr, givee, 0);
 }
 
@@ -389,9 +365,68 @@ still_ok_land(struct sctstr *sectp, struct lndstr *landp)
     return 1;
 }
 
+static int
+plane_loadable(struct plnstr *pp, int noisy)
+{
+    if (pp->pln_ship >= 0) {
+       if (noisy)
+           pr("%s is already on ship #%d!\n",
+              prplane(pp), pp->pln_ship);
+       return 0;
+    }
+    if (pp->pln_land >= 0) {
+       if (noisy)
+           pr("%s is already on land unit #%d!\n",
+              prplane(pp), pp->pln_land);
+       return 0;
+    }
+    if (pp->pln_harden) {
+       if (noisy)
+           pr("%s has been hardened and can't be loaded\n",
+              prplane(pp));
+       return 0;
+    }
+    if (pln_is_in_orbit(pp)) {
+       if (noisy)
+           pr("%s is in space\n", prplane(pp));
+       return 0;
+    }
+    return 1;
+}
+
+static int
+land_loadable(struct lndstr *lp, int noisy)
+{
+    if (lp->lnd_ship >= 0) {
+       if (noisy)
+           pr("%s is already on ship #%d!\n",
+              prland(lp), lp->lnd_ship);
+       return 0;
+    }
+    if (lp->lnd_land >= 0) {
+       if (noisy)
+           pr("%s is already on land #%d!\n",
+              prland(lp), lp->lnd_land);
+       return 0;
+    }
+    if (lnd_first_on_land(lp) >= 0) {
+       /* Outlawed to prevent arbitrarily deep recursion */
+       if (noisy)
+           pr("%s cannot be loaded since it is carrying units\n",
+              prland(lp));
+       return 0;
+    }
+    if (lchr[lp->lnd_type].l_flags & L_HEAVY) {
+       if (noisy)
+           pr("%s is too heavy to load.\n", prland(lp));
+       return 0;
+    }
+    return 1;
+}
+
 static int
 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
-               int load_unload, int *nshipsp)
+               int loading, int *nshipsp)
 {
     struct nstr_item ni;
     struct plnstr pln;
@@ -406,15 +441,14 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
            pr("%s cannot carry planes\n", prship(sp));
        return 0;
     }
-    if (load_unload == LOAD &&
+    if (loading &&
        shp_nplane(sp, NULL, NULL, NULL)
                >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
-       if (noisy)
-           pr("%s doesn't have room for any more planes\n", prship(sp));
+       pr("%s doesn't have room for any more planes\n", prship(sp));
        return 0;
     }
     sprintf(prompt, "Plane(s) to %s %s? ",
-           load_unload == LOAD ? "load onto" : "unload from", prship(sp));
+           loading ? "load onto" : "unload from", prship(sp));
     p = getstarg(player->argp[3], prompt, buf);
     if (!p)
        return RET_SYN;
@@ -424,8 +458,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
     if (!still_ok_ship(sectp, sp))
        return RET_SYN;
 
-    if (noisy && p && *p)
-       noisy = isdigit(*p);
+    noisy = ni.sel == NS_LIST;
 
     while (nxtitem(&ni, &pln)) {
        if (!player->owner)
@@ -439,53 +472,33 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
                pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
            continue;
        }
-       if (load_unload == LOAD && pln.pln_ship > -1) {
-           if (noisy)
-               pr("%s is already on ship #%d!\n",
-                  prplane(&pln), pln.pln_ship);
-           continue;
-       }
-       if (load_unload == LOAD && pln.pln_land > -1) {
-           if (noisy)
-               pr("%s is already on land unit #%d!\n",
-                  prplane(&pln), pln.pln_land);
+       if (loading && !plane_loadable(&pln, noisy))
            continue;
-       }
-       if (pln.pln_harden != 0) {
-           if (noisy)
-               pr("%s has been hardened and can't be loaded\n",
-                  prplane(&pln));
-           continue;
-       }
 
-       /* Plane sanity done */
-       /* Find the right ship */
-       if (load_unload == UNLOAD) {
+       if (!loading) {
            if (pln.pln_ship != sp->shp_uid)
                continue;
        } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
            continue;
 
-       /* ship to (plane or missle) sanity */
-       if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
-           if (plchr[(int)pln.pln_type].pl_flags & P_L) {
-               strcpy(buf, "planes");
-           } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
-               strcpy(buf, "choppers");
-           } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
-               strcpy(buf, "missiles");
-           } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
-               strcpy(buf, "extra light planes");
-           }                   /* else impossible */
-           if (noisy)
-               pr("%s cannot carry %s.\n", prship(sp), buf);
+       if (!could_be_on_ship(&pln, sp)) {
+           if (noisy) {
+               if (plchr[(int)pln.pln_type].pl_flags & P_K)
+                   p = "choppers";
+               else if (plchr[(int)pln.pln_type].pl_flags & P_E)
+                   p = "extra light planes";
+               else if (plchr[(int)pln.pln_type].pl_flags & P_M)
+                   p = "missiles";
+               else
+                   p = "planes";
+               pr("%s cannot carry %s.\n", prship(sp), p);
+           }
            continue;
        }
        /* Fit plane on ship */
-       if (load_unload == LOAD) {
+       if (loading) {
            if (!put_plane_on_ship(&pln, sp)) {
-               if (noisy)
-                   pr("Can't put plane %d on this ship!\n", pln.pln_uid);
+               pr("Can't put plane %d on this ship!\n", pln.pln_uid);
                continue;
            }
            sprintf(buf, "loaded on your %s at %s",
@@ -502,8 +515,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
        }
        pr("%s %s %s at %s.\n",
           prplane(&pln),
-          (load_unload == UNLOAD) ?
-          "unloaded from" : "loaded onto",
+          loading ? "loaded onto" : "unloaded from",
           prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
        loaded = 1;
     }
@@ -513,7 +525,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
 
 static int
 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
-              int load_unload, int *nshipsp)
+              int loading, int *nshipsp)
 {
     struct nstr_item ni;
     struct lndstr land;
@@ -523,31 +535,30 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
     char buf[1024];
     int load_spy = 0;
 
-    if (load_unload == LOAD) {
-       if (opt_LANDSPIES) {
-           if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
-               (mchr[(int)sp->shp_type].m_nland == 0)) {
-               if (shp_nland(sp) >= 2) {
-                   pr("Non-land unit carrying subs can only carry up to two spy units.\n");
-                   return 0;
-               }
-               /* Eh, let 'em load a spy only */
-               load_spy = 1;
+    if (!mchr[(int)sp->shp_type].m_nland
+       && !(mchr[sp->shp_type].m_flags & M_SUB)) {
+       if (noisy)
+           pr("%s cannot carry land units!\n", prship(sp));
+       return 0;
+    }
+    if (loading) {
+       if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
+           (mchr[(int)sp->shp_type].m_nland == 0)) {
+           if (shp_nland(sp) >= 2) {
+               pr("Non-land unit carrying subs can only carry up to two spy units.\n");
+               return 0;
            }
+           /* Eh, let 'em load a spy only */
+           load_spy = 1;
        }
        if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
-           if (noisy) {
-               if (mchr[(int)sp->shp_type].m_nland)
-                   pr("%s doesn't have room for any more land units!\n",
-                      prship(sp));
-               else
-                   pr("%s cannot carry land units!\n", prship(sp));
-           }
+           pr("%s doesn't have room for any more land units!\n",
+              prship(sp));
            return 0;
        }
     }
     sprintf(prompt, "Land unit(s) to %s %s? ",
-           load_unload == LOAD ? "load onto" : "unload from", prship(sp));
+           loading ? "load onto" : "unload from", prship(sp));
     p = getstarg(player->argp[3], prompt, buf);
     if (!p)
        return RET_SYN;
@@ -557,37 +568,15 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
     if (!still_ok_ship(sectp, sp))
        return RET_SYN;
 
-    if (noisy && p && *p)
-       noisy = isdigit(*p);
+    noisy = ni.sel == NS_LIST;
 
     while (nxtitem(&ni, &land)) {
        if (!player->owner)
            continue;
 
-       if (load_unload == LOAD) {
-           if (land.lnd_ship > -1) {
-               if (noisy)
-                   pr("%s is already on ship #%d!\n",
-                      prland(&land), land.lnd_ship);
+       if (loading) {
+           if (!land_loadable(&land, noisy))
                continue;
-           }
-           if (land.lnd_land > -1) {
-               if (noisy)
-                   pr("%s is already on land #%d!\n",
-                      prland(&land), land.lnd_land);
-               continue;
-           }
-           if (lnd_first_on_land(&land) >= 0) {
-               if (noisy)
-                   pr("%s cannot be loaded since it is carrying units\n",
-                      prland(&land));
-               continue;
-           }
-           if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
-               if (noisy)
-                   pr("%s is too heavy to load.\n", prland(&land));
-               continue;
-           }
            if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
                if (noisy)
                    pr("Subs can only carry spy units.\n");
@@ -597,7 +586,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
 
        /* Unit sanity done */
        /* Find the right ship */
-       if (load_unload == UNLOAD) {
+       if (!loading) {
            if (land.lnd_ship != sp->shp_uid)
                continue;
            if (land.lnd_land > -1)
@@ -616,28 +605,18 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
            continue;
        }
        /* Fit unit on ship */
-       if (load_unload == LOAD) {
-           /* We have to check again, since it may have changed */
-           if (opt_LANDSPIES) {
-               if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
-                   (mchr[(int)sp->shp_type].m_nland == 0)) {
-                   if (shp_nland(sp) >= 2) {
-                       pr("Non-land unit carrying subs can only carry up to two spy units.\n");
-                       return 0;
-                   }
-                   /* Eh, let 'em load a spy only */
-                   load_spy = 1;
+       if (loading) {
+           if (load_spy) {
+               if (shp_nland(sp) >= 2) {
+                   pr("Non-land unit carrying subs can only carry up to two spy units.\n");
+                   return 0;
                }
-           }
-           if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
-               if (noisy) {
-                   if (mchr[(int)sp->shp_type].m_nland)
-                       pr("%s doesn't have room for any more land units!\n",
-                          prship(sp));
-                   else
-                       pr("%s cannot carry land units!\n", prship(sp));
+           } else {
+               if (shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
+                   pr("%s doesn't have room for any more land units!\n",
+                      prship(sp));
+                   return 0;
                }
-               return 0;
            }
            sprintf(buf, "loaded on your %s at %s",
                    prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
@@ -646,11 +625,11 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
            land.lnd_harden = 0;
            putland(land.lnd_uid, &land);
 #if 0
-           /*
-            * FIXME if this supplies from the sector, the putsect in
-            * load() / lload() duplicates those supplies, causing a
-            * seqno mismatch
-            */
+          /*
+           * FIXME if this supplies from the sector, the putsect in
+           * load() / lload() duplicates those supplies, causing a
+           * seqno mismatch
+           */
            if (!lnd_supply_all(&land))
                pr("WARNING: %s is out of supply!\n", prland(&land));
 #else
@@ -670,8 +649,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
        }
        pr("%s %s %s at %s.\n",
           prland(&land),
-          (load_unload == UNLOAD) ?
-          "unloaded from" : "loaded onto",
+          loading ? "loaded onto" : "unloaded from",
           prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
        loaded = 1;
     }
@@ -681,7 +659,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
 
 static int
 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
-              struct ichrstr *ich, int load_unload, int *nshipsp)
+              struct ichrstr *ich, int loading, int *nshipsp)
 {
     i_type item = ich->i_uid;
     struct mchrstr *mcp = &mchr[(int)sp->shp_type];
@@ -692,10 +670,10 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
 
     sprintf(prompt, "Number of %s to %s %s at %s? ",
            ich->i_name,
-           (load_unload == UNLOAD) ?
-           "unload from" : "load onto",
+           loading ? "load onto" : "unload from",
            prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
-    if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+    p = getstarg(player->argp[3], prompt, buf);
+    if (!p || !*p)
        return RET_SYN;
 
     if (!still_ok_ship(sectp, sp))
@@ -704,10 +682,10 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
     ship_amt = sp->shp_item[item];
     sect_amt = sectp->sct_item[item];
     move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
-                          load_unload, atoi(p));
+                          loading, atoi(p));
     if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
        return RET_OK;
-    if (!want_to_abandon(sectp, item, move_amt, 0))
+    if (!abandon_askyn(sectp, item, move_amt, NULL))
        return RET_FAIL;
     if (!still_ok_ship(sectp, sp))
        return RET_SYN;
@@ -739,7 +717,7 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
 
 static int
 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
-               int load_unload, int *nunitsp)
+               int loading, int *nunitsp)
 {
     struct nstr_item ni;
     struct plnstr pln;
@@ -754,14 +732,13 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
            pr("%s cannot carry extra-light planes.\n", prland(lp));
        return 0;
     }
-    if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
-       if (noisy)
-           pr("%s doesn't have room for any more extra-light planes\n",
-              prland(lp));
+    if (loading && lnd_nxlight(lp) >= lcp->l_nxlight) {
+       pr("%s doesn't have room for any more extra-light planes\n",
+          prland(lp));
        return 0;
     }
     sprintf(prompt, "Plane(s) to %s %s? ",
-           load_unload == LOAD ? "load onto" : "unload from", prland(lp));
+           loading ? "load onto" : "unload from", prland(lp));
     p = getstarg(player->argp[3], prompt, buf);
     if (!p)
        return RET_SYN;
@@ -771,8 +748,7 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
     if (!still_ok_land(sectp, lp))
        return RET_SYN;
 
-    if (noisy && p && *p)
-       noisy = isdigit(*p);
+    noisy = ni.sel == NS_LIST;
 
     while (nxtitem(&ni, &pln)) {
        if (!player->owner)
@@ -783,39 +759,21 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
                pr("You can only load xlight planes onto units.\n");
            continue;
        }
-
-       if (load_unload == LOAD && pln.pln_ship > -1) {
-           if (noisy)
-               pr("%s is already on ship #%d!\n",
-                  prplane(&pln), pln.pln_ship);
-           continue;
-       }
-       if (load_unload == LOAD && pln.pln_land > -1) {
-           if (noisy)
-               pr("%s is already on unit #%d!\n",
-                  prplane(&pln), pln.pln_land);
-           continue;
-       }
-       if (pln.pln_harden != 0) {
-           if (noisy)
-               pr("%s has been hardened and can't be loaded\n",
-                  prplane(&pln));
+       if (loading && !plane_loadable(&pln, noisy))
            continue;
-       }
 
        /* Plane sanity done */
        /* Find the right unit */
-       if (load_unload == UNLOAD) {
+       if (!loading) {
            if (pln.pln_land != lp->lnd_uid)
                continue;
        } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
            continue;
 
        /* Fit plane on unit */
-       if (load_unload == LOAD) {
+       if (loading) {
            if (!put_plane_on_land(&pln, lp)) {
-               if (noisy)
-                   pr("Can't put plane %d on this unit!\n", pln.pln_uid);
+               pr("Can't put plane %d on this unit!\n", pln.pln_uid);
                continue;
            }
            sprintf(buf, "loaded on %s at %s",
@@ -831,8 +789,7 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
        }
        pr("%s %s %s at %s.\n",
           prplane(&pln),
-          (load_unload == UNLOAD) ?
-          "unloaded from" : "loaded onto",
+          loading ? "loaded onto" : "unloaded from",
           prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
        loaded = 1;
     }
@@ -842,7 +799,7 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
 
 static int
 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
-              struct ichrstr *ich, int load_unload, int *nunitsp)
+              struct ichrstr *ich, int loading, int *nunitsp)
 {
     i_type item = ich->i_uid;
     struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
@@ -853,10 +810,10 @@ load_comm_land(struct sctstr *sectp, struct lndstr *lp,
 
     sprintf(prompt, "Number of %s to %s %s at %s? ",
            ich->i_name,
-           (load_unload == UNLOAD) ?
-           "unload from" : "load onto",
+           loading ? "load onto" : "unload from",
            prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
-    if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+    p = getstarg(player->argp[3], prompt, buf);
+    if (!p || !*p)
        return RET_SYN;
 
     if (!still_ok_land(sectp, lp))
@@ -865,7 +822,7 @@ load_comm_land(struct sctstr *sectp, struct lndstr *lp,
     land_amt = lp->lnd_item[item];
     sect_amt = sectp->sct_item[item];
     move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
-                          load_unload, atoi(p));
+                          loading, atoi(p));
     if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
        return RET_OK;
     sectp->sct_item[item] = sect_amt - move_amt;
@@ -900,7 +857,7 @@ load_comm_land(struct sctstr *sectp, struct lndstr *lp,
 
 static int
 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
-              int load_unload, int *nunitsp)
+              int loading, int *nunitsp)
 {
     struct nstr_item ni;
     struct lndstr land;
@@ -909,19 +866,18 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
     char prompt[512];
     char buf[1024];
 
-    if (load_unload == LOAD
-       && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
-       if (noisy) {
-           if (lchr[lp->lnd_type].l_nland)
-               pr("%s doesn't have room for any more land units!\n",
-                  prland(lp));
-           else
-               pr("%s cannot carry land units!\n", prland(lp));
-       }
+    if (!lchr[lp->lnd_type].l_nland) {
+       if (noisy)
+           pr("%s cannot carry land units!\n", prland(lp));
+       return 0;
+    }
+    if (loading && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
+       pr("%s doesn't have room for any more land units!\n",
+          prland(lp));
        return 0;
     }
     sprintf(prompt, "Land unit(s) to %s %s? ",
-           load_unload == LOAD ? "load onto" : "unload from", prland(lp));
+           loading ? "load onto" : "unload from", prland(lp));
     p = getstarg(player->argp[3], prompt, buf);
     if (!p)
        return RET_SYN;
@@ -931,47 +887,25 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
     if (!still_ok_land(sectp, lp))
        return RET_SYN;
 
-    if (noisy && p && *p)
-       noisy = isdigit(*p);
+    noisy = ni.sel == NS_LIST;
 
     while (nxtitem(&ni, &land)) {
        if (!player->owner)
            continue;
 
-       if (load_unload == LOAD) {
-           if (land.lnd_ship > -1) {
-               if (noisy)
-                   pr("%s is already on ship #%d!\n",
-                      prland(&land), land.lnd_ship);
-               continue;
-           }
-           if (land.lnd_land > -1) {
-               if (noisy)
-                   pr("%s is already on land #%d!\n",
-                      prland(&land), land.lnd_land);
-               continue;
-           }
-           if (lnd_first_on_land(&land) >= 0) {
-               if (noisy)
-                   pr("%s cannot be loaded since it is carrying units\n",
-                      prland(&land));
-               continue;
-           }
+       if (loading) {
            if (land.lnd_uid == lp->lnd_uid) {
                if (noisy)
                    pr("%s can't be loaded onto itself!\n", prland(&land));
                continue;
            }
-           if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
-               if (noisy)
-                   pr("%s is too heavy to load.\n", prland(&land));
+           if (!land_loadable(&land, noisy))
                continue;
-           }
        }
 
        /* Unit sanity done */
        /* Find the right ship */
-       if (load_unload == UNLOAD) {
+       if (!loading) {
            if (land.lnd_land != lp->lnd_uid)
                continue;
            if (land.lnd_ship > -1)
@@ -980,15 +914,10 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
            continue;
 
        /* Fit unit on ship */
-       if (load_unload == LOAD) {
+       if (loading) {
            if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
-               if (noisy) {
-                   if (lchr[lp->lnd_type].l_nland)
-                       pr("%s doesn't have room for any more land units!\n",
-                          prland(lp));
-                   else
-                       pr("%s cannot carry land units!\n", prland(lp));
-               }
+               pr("%s doesn't have room for any more land units!\n",
+                  prland(lp));
                break;
            }
            sprintf(buf, "loaded on your %s at %s",
@@ -998,7 +927,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
            land.lnd_harden = 0;
            putland(land.lnd_uid, &land);
 #if 0
-           /* FIXME same issue as in load_land_ship() */
+          /* FIXME same issue as in load_land_ship() */
            if (!lnd_supply_all(&land))
                pr("WARNING: %s is out of supply!\n", prland(&land));
 #else
@@ -1015,8 +944,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
        }
        pr("%s %s %s at %s.\n",
           prland(&land),
-          (load_unload == UNLOAD) ?
-          "unloaded from" : "loaded onto",
+          loading ? "loaded onto" : "unloaded from",
           prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
        loaded = 1;
     }