]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/load.c
Update copyright notice
[empserver] / src / lib / commands / load.c
index 8ab83e088ec5113af28a64282ede6a1ecd532fba..0cae81bc70a29eaf46c195c717e97119b7980ce6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
  *     David Sharnoff, 1987
  *     Ken Stevens, 1995 (rewritten)
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2011
+ *     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)
 {
+    int loading = **player->argp == 'l';
     int noisy;
-    int load_unload;
     int type;
     struct nstr_item nbst;
     struct ichrstr *ich;
@@ -94,7 +87,7 @@ 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;
     }
 
@@ -102,19 +95,17 @@ load(void)
     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 (relations_with(ship.shp_own, player->cnum) < FRIENDLY)
                continue;
@@ -122,16 +113,14 @@ load(void)
 
        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,7 +131,7 @@ load(void)
                   xyas(sect.sct_x, sect.sct_y, player->cnum));
            continue;
        }
-       if (load_unload == UNLOAD
+       if (!loading
            && !player->owner
            && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
            if (noisy)
@@ -160,27 +149,25 @@ 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:
-           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:
-           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:
-           retval = load_comm_ship(&sect, &ship, ich, load_unload,
-                                   &nships);
+           retval = load_comm_ship(&sect, &ship, ich, loading, &nships);
            if (retval != 0)
                return retval;
        }
@@ -198,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)
 {
+    int loading = player->argp[0][1] == 'l';
     int noisy;
-    int load_unload;
     int type;
     struct nstr_item nbst;
     struct ichrstr *ich;
@@ -228,7 +215,7 @@ 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;
     }
 
@@ -236,19 +223,17 @@ lload(void)
     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 (relations_with(land.lnd_own, player->cnum) != ALLIED)
                continue;
@@ -259,42 +244,41 @@ 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 (relations_with(sect.sct_own, player->cnum) != ALLIED) {
-               pr("Sector %s is not yours.\n",
-                  xyas(sect.sct_x, sect.sct_y, player->cnum));
+               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:
-           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:
-           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:
-           retval = load_comm_land(&sect, &land, ich, load_unload,
-                                   &nunits);
+           retval = load_comm_land(&sect, &land, ich, loading, &nunits);
            if (retval != 0)
                return retval;
        }
@@ -313,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)
 {
@@ -363,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);
 }
 
@@ -387,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;
@@ -404,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;
@@ -422,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)
@@ -437,32 +472,16 @@ 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;
-       }
 
-       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;
 
-       if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
+       if (!could_be_on_ship(&pln, sp)) {
            if (noisy) {
                if (plchr[(int)pln.pln_type].pl_flags & P_K)
                    p = "choppers";
@@ -477,10 +496,9 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
            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",
@@ -497,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;
     }
@@ -508,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;
@@ -518,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;
@@ -552,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);
-               continue;
-           }
-           if (land.lnd_land > -1) {
-               if (noisy)
-                   pr("%s is already on land #%d!\n",
-                      prland(&land), land.lnd_land);
+       if (loading) {
+           if (!land_loadable(&land, noisy))
                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");
@@ -592,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)
@@ -611,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));
@@ -665,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;
     }
@@ -676,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];
@@ -687,8 +670,7 @@ 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));
     p = getstarg(player->argp[3], prompt, buf);
     if (!p || !*p)
@@ -700,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, NULL))
+    if (!abandon_askyn(sectp, item, move_amt, NULL))
        return RET_FAIL;
     if (!still_ok_ship(sectp, sp))
        return RET_SYN;
@@ -735,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;
@@ -750,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;
@@ -767,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)
@@ -779,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",
@@ -827,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;
     }
@@ -838,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];
@@ -849,8 +810,7 @@ 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));
     p = getstarg(player->argp[3], prompt, buf);
     if (!p || !*p)
@@ -862,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;
@@ -897,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;
@@ -906,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;
@@ -928,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)
@@ -977,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",
@@ -1012,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;
     }