load: Replace variable load_unload by variable loading

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2017-09-16 09:46:47 +02:00
parent 7d2c09668c
commit 3aa6c1b263

View file

@ -30,7 +30,7 @@
* David Sharnoff, 1987 * David Sharnoff, 1987
* Ken Stevens, 1995 (rewritten) * Ken Stevens, 1995 (rewritten)
* Steve McClure, 1998-2000 * Steve McClure, 1998-2000
* Markus Armbruster, 2004-2014 * Markus Armbruster, 2004-2017
*/ */
#include <config.h> #include <config.h>
@ -45,32 +45,26 @@
#include "ship.h" #include "ship.h"
#include "unit.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, 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, 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, static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
struct ichrstr *ich, int load_unload, struct ichrstr *ich, int loading,
int *nshipsp); int *nshipsp);
static int load_plane_land(struct sctstr *sectp, struct lndstr *lp, 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, 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, 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 *nunitsp);
int int
load(void) load(void)
{ {
int loading = **player->argp == 'l';
int noisy; int noisy;
int load_unload;
int type; int type;
struct nstr_item nbst; struct nstr_item nbst;
struct ichrstr *ich; struct ichrstr *ich;
@ -106,14 +100,12 @@ load(void)
if (!snxtitem(&nbst, EF_SHIP, p, NULL)) if (!snxtitem(&nbst, EF_SHIP, p, NULL))
return RET_SYN; return RET_SYN;
load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
nships = 0; nships = 0;
while (nxtitem(&nbst, &ship)) { while (nxtitem(&nbst, &ship)) {
if (!ship.shp_own) if (!ship.shp_own)
continue; continue;
if (!player->owner) { if (!player->owner) {
if (load_unload == UNLOAD || !noisy) if (!loading || !noisy)
continue; continue;
if (relations_with(ship.shp_own, player->cnum) < FRIENDLY) if (relations_with(ship.shp_own, player->cnum) < FRIENDLY)
continue; continue;
@ -128,7 +120,7 @@ load(void)
continue; continue;
if (!sect_has_dock(&sect)) if (!sect_has_dock(&sect))
continue; continue;
if (load_unload == LOAD) { if (loading) {
if (noisy) 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)); xyas(sect.sct_x, sect.sct_y, player->cnum));
@ -141,7 +133,7 @@ load(void)
xyas(sect.sct_x, sect.sct_y, player->cnum)); xyas(sect.sct_x, sect.sct_y, player->cnum));
continue; continue;
} }
if (load_unload == UNLOAD if (!loading
&& !player->owner && !player->owner
&& relations_with(sect.sct_own, player->cnum) < FRIENDLY) { && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
if (noisy) if (noisy)
@ -166,20 +158,17 @@ load(void)
switch (type) { switch (type) {
case EF_PLANE: case EF_PLANE:
retval = load_plane_ship(&sect, &ship, noisy, load_unload, retval = load_plane_ship(&sect, &ship, noisy, loading, &nships);
&nships);
if (retval != 0) if (retval != 0)
return retval; return retval;
break; break;
case EF_LAND: case EF_LAND:
retval = load_land_ship(&sect, &ship, noisy, load_unload, retval = load_land_ship(&sect, &ship, noisy, loading, &nships);
&nships);
if (retval != 0) if (retval != 0)
return retval; return retval;
break; break;
case EF_SECTOR: case EF_SECTOR:
retval = load_comm_ship(&sect, &ship, ich, load_unload, retval = load_comm_ship(&sect, &ship, ich, loading, &nships);
&nships);
if (retval != 0) if (retval != 0)
return retval; return retval;
} }
@ -197,15 +186,15 @@ load(void)
pr("No ships affected\n"); pr("No ships affected\n");
else else
pr("%d ship%s %sloaded\n", nships, splur(nships), pr("%d ship%s %sloaded\n", nships, splur(nships),
load_unload == UNLOAD ? "un" : ""); loading ? "" : "un");
return RET_OK; return RET_OK;
} }
int int
lload(void) lload(void)
{ {
int loading = player->argp[0][1] == 'l';
int noisy; int noisy;
int load_unload;
int type; int type;
struct nstr_item nbst; struct nstr_item nbst;
struct ichrstr *ich; struct ichrstr *ich;
@ -240,14 +229,12 @@ lload(void)
if (!snxtitem(&nbst, EF_LAND, p, NULL)) if (!snxtitem(&nbst, EF_LAND, p, NULL))
return RET_SYN; return RET_SYN;
load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
nunits = 0; nunits = 0;
while (nxtitem(&nbst, &land)) { while (nxtitem(&nbst, &land)) {
if (land.lnd_own == 0) if (land.lnd_own == 0)
continue; continue;
if (!player->owner) { if (!player->owner) {
if (load_unload == UNLOAD || !noisy) if (!loading || !noisy)
continue; continue;
if (relations_with(land.lnd_own, player->cnum) != ALLIED) if (relations_with(land.lnd_own, player->cnum) != ALLIED)
continue; continue;
@ -258,7 +245,7 @@ lload(void)
if (!player->owner) { if (!player->owner) {
if (land.lnd_own != player->cnum) if (land.lnd_own != player->cnum)
continue; continue;
if (load_unload == LOAD) { if (loading) {
if (noisy) if (noisy)
pr("Sector %s is not yours.\n", pr("Sector %s is not yours.\n",
xyas(sect.sct_x, sect.sct_y, player->cnum)); xyas(sect.sct_x, sect.sct_y, player->cnum));
@ -280,20 +267,17 @@ lload(void)
switch (type) { switch (type) {
case EF_LAND: case EF_LAND:
retval = load_land_land(&sect, &land, noisy, load_unload, retval = load_land_land(&sect, &land, noisy, loading, &nunits);
&nunits);
if (retval != 0) if (retval != 0)
return retval; return retval;
break; break;
case EF_PLANE: case EF_PLANE:
retval = load_plane_land(&sect, &land, noisy, load_unload, retval = load_plane_land(&sect, &land, noisy, loading, &nunits);
&nunits);
if (retval != 0) if (retval != 0)
return retval; return retval;
break; break;
case EF_SECTOR: case EF_SECTOR:
retval = load_comm_land(&sect, &land, ich, load_unload, retval = load_comm_land(&sect, &land, ich, loading, &nunits);
&nunits);
if (retval != 0) if (retval != 0)
return retval; return retval;
} }
@ -312,20 +296,20 @@ lload(void)
pr("No units affected\n"); pr("No units affected\n");
else else
pr("%d unit%s %sloaded\n", nunits, splur(nunits), pr("%d unit%s %sloaded\n", nunits, splur(nunits),
load_unload == UNLOAD ? "un" : ""); loading ? "" : "un");
return RET_OK; return RET_OK;
} }
static int static int
move_amount(int sect_amt, int unit_amt, int unit_max, move_amount(int sect_amt, int unit_amt, int unit_max,
int load_unload, int amount) int loading, int amount)
{ {
int move_amt; int move_amt;
if (amount < 0) if (amount < 0)
move_amt = -amount - unit_amt; move_amt = -amount - unit_amt;
else else
move_amt = load_unload == LOAD ? amount : -amount; move_amt = loading ? amount : -amount;
move_amt = LIMIT_TO(move_amt, -unit_amt, unit_max - unit_amt); move_amt = LIMIT_TO(move_amt, -unit_amt, unit_max - unit_amt);
move_amt = LIMIT_TO(move_amt, sect_amt - ITEM_MAX, sect_amt); move_amt = LIMIT_TO(move_amt, sect_amt - ITEM_MAX, sect_amt);
return move_amt; return move_amt;
@ -382,7 +366,7 @@ still_ok_land(struct sctstr *sectp, struct lndstr *landp)
static int static int
load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, 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 nstr_item ni;
struct plnstr pln; struct plnstr pln;
@ -397,7 +381,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
pr("%s cannot carry planes\n", prship(sp)); pr("%s cannot carry planes\n", prship(sp));
return 0; return 0;
} }
if (load_unload == LOAD && if (loading &&
shp_nplane(sp, NULL, NULL, NULL) shp_nplane(sp, NULL, NULL, NULL)
>= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) { >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
if (noisy) if (noisy)
@ -405,7 +389,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
return 0; return 0;
} }
sprintf(prompt, "Plane(s) to %s %s? ", 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); p = getstarg(player->argp[3], prompt, buf);
if (!p) if (!p)
return RET_SYN; return RET_SYN;
@ -430,13 +414,13 @@ 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"); pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
continue; continue;
} }
if (load_unload == LOAD && pln.pln_ship > -1) { if (loading && pln.pln_ship > -1) {
if (noisy) if (noisy)
pr("%s is already on ship #%d!\n", pr("%s is already on ship #%d!\n",
prplane(&pln), pln.pln_ship); prplane(&pln), pln.pln_ship);
continue; continue;
} }
if (load_unload == LOAD && pln.pln_land > -1) { if (loading && pln.pln_land > -1) {
if (noisy) if (noisy)
pr("%s is already on land unit #%d!\n", pr("%s is already on land unit #%d!\n",
prplane(&pln), pln.pln_land); prplane(&pln), pln.pln_land);
@ -449,7 +433,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
continue; continue;
} }
if (load_unload == UNLOAD) { if (!loading) {
if (pln.pln_ship != sp->shp_uid) if (pln.pln_ship != sp->shp_uid)
continue; continue;
} else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y) } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
@ -470,7 +454,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
continue; continue;
} }
/* Fit plane on ship */ /* Fit plane on ship */
if (load_unload == LOAD) { if (loading) {
if (!put_plane_on_ship(&pln, sp)) { if (!put_plane_on_ship(&pln, sp)) {
if (noisy) 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);
@ -490,8 +474,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
} }
pr("%s %s %s at %s.\n", pr("%s %s %s at %s.\n",
prplane(&pln), prplane(&pln),
(load_unload == UNLOAD) ? loading ? "loaded onto" : "unloaded from",
"unloaded from" : "loaded onto",
prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
loaded = 1; loaded = 1;
} }
@ -501,7 +484,7 @@ load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
static int static int
load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, 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 nstr_item ni;
struct lndstr land; struct lndstr land;
@ -511,7 +494,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
char buf[1024]; char buf[1024];
int load_spy = 0; int load_spy = 0;
if (load_unload == LOAD) { if (loading) {
if ((mchr[(int)sp->shp_type].m_flags & M_SUB) && if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
(mchr[(int)sp->shp_type].m_nland == 0)) { (mchr[(int)sp->shp_type].m_nland == 0)) {
if (shp_nland(sp) >= 2) { if (shp_nland(sp) >= 2) {
@ -533,7 +516,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
} }
} }
sprintf(prompt, "Land unit(s) to %s %s? ", 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); p = getstarg(player->argp[3], prompt, buf);
if (!p) if (!p)
return RET_SYN; return RET_SYN;
@ -550,7 +533,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
if (!player->owner) if (!player->owner)
continue; continue;
if (load_unload == LOAD) { if (loading) {
if (land.lnd_ship > -1) { if (land.lnd_ship > -1) {
if (noisy) if (noisy)
pr("%s is already on ship #%d!\n", pr("%s is already on ship #%d!\n",
@ -583,7 +566,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
/* Unit sanity done */ /* Unit sanity done */
/* Find the right ship */ /* Find the right ship */
if (load_unload == UNLOAD) { if (!loading) {
if (land.lnd_ship != sp->shp_uid) if (land.lnd_ship != sp->shp_uid)
continue; continue;
if (land.lnd_land > -1) if (land.lnd_land > -1)
@ -602,7 +585,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
continue; continue;
} }
/* Fit unit on ship */ /* Fit unit on ship */
if (load_unload == LOAD) { if (loading) {
/* We have to check again, since it may have changed */ /* We have to check again, since it may have changed */
if ((mchr[(int)sp->shp_type].m_flags & M_SUB) && if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
(mchr[(int)sp->shp_type].m_nland == 0)) { (mchr[(int)sp->shp_type].m_nland == 0)) {
@ -654,8 +637,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
} }
pr("%s %s %s at %s.\n", pr("%s %s %s at %s.\n",
prland(&land), prland(&land),
(load_unload == UNLOAD) ? loading ? "loaded onto" : "unloaded from",
"unloaded from" : "loaded onto",
prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
loaded = 1; loaded = 1;
} }
@ -665,7 +647,7 @@ load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
static int static int
load_comm_ship(struct sctstr *sectp, struct shpstr *sp, 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; i_type item = ich->i_uid;
struct mchrstr *mcp = &mchr[(int)sp->shp_type]; struct mchrstr *mcp = &mchr[(int)sp->shp_type];
@ -676,8 +658,7 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
sprintf(prompt, "Number of %s to %s %s at %s? ", sprintf(prompt, "Number of %s to %s %s at %s? ",
ich->i_name, ich->i_name,
(load_unload == UNLOAD) ? loading ? "load onto" : "unload from",
"unload from" : "load onto",
prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum)); prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
p = getstarg(player->argp[3], prompt, buf); p = getstarg(player->argp[3], prompt, buf);
if (!p || !*p) if (!p || !*p)
@ -689,7 +670,7 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
ship_amt = sp->shp_item[item]; ship_amt = sp->shp_item[item];
sect_amt = sectp->sct_item[item]; sect_amt = sectp->sct_item[item];
move_amt = move_amount(sect_amt, ship_amt, mcp->m_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)) if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
return RET_OK; return RET_OK;
if (!abandon_askyn(sectp, item, move_amt, NULL)) if (!abandon_askyn(sectp, item, move_amt, NULL))
@ -724,7 +705,7 @@ load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
static int static int
load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, 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 nstr_item ni;
struct plnstr pln; struct plnstr pln;
@ -739,14 +720,14 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
pr("%s cannot carry extra-light planes.\n", prland(lp)); pr("%s cannot carry extra-light planes.\n", prland(lp));
return 0; return 0;
} }
if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) { if (loading && lnd_nxlight(lp) >= lcp->l_nxlight) {
if (noisy) if (noisy)
pr("%s doesn't have room for any more extra-light planes\n", pr("%s doesn't have room for any more extra-light planes\n",
prland(lp)); prland(lp));
return 0; return 0;
} }
sprintf(prompt, "Plane(s) to %s %s? ", 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); p = getstarg(player->argp[3], prompt, buf);
if (!p) if (!p)
return RET_SYN; return RET_SYN;
@ -769,13 +750,13 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
continue; continue;
} }
if (load_unload == LOAD && pln.pln_ship > -1) { if (loading && pln.pln_ship > -1) {
if (noisy) if (noisy)
pr("%s is already on ship #%d!\n", pr("%s is already on ship #%d!\n",
prplane(&pln), pln.pln_ship); prplane(&pln), pln.pln_ship);
continue; continue;
} }
if (load_unload == LOAD && pln.pln_land > -1) { if (loading && pln.pln_land > -1) {
if (noisy) if (noisy)
pr("%s is already on unit #%d!\n", pr("%s is already on unit #%d!\n",
prplane(&pln), pln.pln_land); prplane(&pln), pln.pln_land);
@ -790,14 +771,14 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
/* Plane sanity done */ /* Plane sanity done */
/* Find the right unit */ /* Find the right unit */
if (load_unload == UNLOAD) { if (!loading) {
if (pln.pln_land != lp->lnd_uid) if (pln.pln_land != lp->lnd_uid)
continue; continue;
} else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y) } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
continue; continue;
/* Fit plane on unit */ /* Fit plane on unit */
if (load_unload == LOAD) { if (loading) {
if (!put_plane_on_land(&pln, lp)) { if (!put_plane_on_land(&pln, lp)) {
if (noisy) 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);
@ -816,8 +797,7 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
} }
pr("%s %s %s at %s.\n", pr("%s %s %s at %s.\n",
prplane(&pln), prplane(&pln),
(load_unload == UNLOAD) ? loading ? "loaded onto" : "unloaded from",
"unloaded from" : "loaded onto",
prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
loaded = 1; loaded = 1;
} }
@ -827,7 +807,7 @@ load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
static int static int
load_comm_land(struct sctstr *sectp, struct lndstr *lp, 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; i_type item = ich->i_uid;
struct lchrstr *lcp = &lchr[(int)lp->lnd_type]; struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
@ -838,8 +818,7 @@ load_comm_land(struct sctstr *sectp, struct lndstr *lp,
sprintf(prompt, "Number of %s to %s %s at %s? ", sprintf(prompt, "Number of %s to %s %s at %s? ",
ich->i_name, ich->i_name,
(load_unload == UNLOAD) ? loading ? "load onto" : "unload from",
"unload from" : "load onto",
prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
p = getstarg(player->argp[3], prompt, buf); p = getstarg(player->argp[3], prompt, buf);
if (!p || !*p) if (!p || !*p)
@ -851,7 +830,7 @@ load_comm_land(struct sctstr *sectp, struct lndstr *lp,
land_amt = lp->lnd_item[item]; land_amt = lp->lnd_item[item];
sect_amt = sectp->sct_item[item]; sect_amt = sectp->sct_item[item];
move_amt = move_amount(sect_amt, land_amt, lcp->l_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)) if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
return RET_OK; return RET_OK;
sectp->sct_item[item] = sect_amt - move_amt; sectp->sct_item[item] = sect_amt - move_amt;
@ -886,7 +865,7 @@ load_comm_land(struct sctstr *sectp, struct lndstr *lp,
static int static int
load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, 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 nstr_item ni;
struct lndstr land; struct lndstr land;
@ -895,8 +874,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
char prompt[512]; char prompt[512];
char buf[1024]; char buf[1024];
if (load_unload == LOAD if (loading && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
&& lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
if (noisy) { if (noisy) {
if (lchr[lp->lnd_type].l_nland) if (lchr[lp->lnd_type].l_nland)
pr("%s doesn't have room for any more land units!\n", pr("%s doesn't have room for any more land units!\n",
@ -907,7 +885,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
return 0; return 0;
} }
sprintf(prompt, "Land unit(s) to %s %s? ", 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); p = getstarg(player->argp[3], prompt, buf);
if (!p) if (!p)
return RET_SYN; return RET_SYN;
@ -924,7 +902,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
if (!player->owner) if (!player->owner)
continue; continue;
if (load_unload == LOAD) { if (loading) {
if (land.lnd_ship > -1) { if (land.lnd_ship > -1) {
if (noisy) if (noisy)
pr("%s is already on ship #%d!\n", pr("%s is already on ship #%d!\n",
@ -957,7 +935,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
/* Unit sanity done */ /* Unit sanity done */
/* Find the right ship */ /* Find the right ship */
if (load_unload == UNLOAD) { if (!loading) {
if (land.lnd_land != lp->lnd_uid) if (land.lnd_land != lp->lnd_uid)
continue; continue;
if (land.lnd_ship > -1) if (land.lnd_ship > -1)
@ -966,7 +944,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
continue; continue;
/* Fit unit on ship */ /* Fit unit on ship */
if (load_unload == LOAD) { if (loading) {
if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) { if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
if (noisy) { if (noisy) {
if (lchr[lp->lnd_type].l_nland) if (lchr[lp->lnd_type].l_nland)
@ -1001,8 +979,7 @@ load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
} }
pr("%s %s %s at %s.\n", pr("%s %s %s at %s.\n",
prland(&land), prland(&land),
(load_unload == UNLOAD) ? loading ? "loaded onto" : "unloaded from",
"unloaded from" : "loaded onto",
prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum)); prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
loaded = 1; loaded = 1;
} }