2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * load.c: load/unload goods from a sector onto a ship or land unit
30 * Known contributors to this file:
31 * David Sharnoff, 1987
32 * Ken Stevens, 1995 (rewritten)
33 * Steve McClure, 1998-2000
34 * Markus Armbruster, 2004-2009
51 * The values 1 and -1 are important below, don't change them.
56 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
57 int noisy, int load_unload, int *nshipsp);
58 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
59 int noisy, int load_unload, int *nshipsp);
60 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
61 struct ichrstr *ich, int load_unload,
63 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
64 int noisy, int load_unload, int *nunitsp);
65 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
66 int noisy, int load_unload, int *nunitsp);
67 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
68 struct ichrstr *ich, int load_unload,
77 struct nstr_item nbst;
86 p = getstarg(player->argp[1],
87 "What commodity (or 'plane' or 'land')? ", buf);
91 if (!strncmp(p, "plane", 5))
93 else if (!strncmp(p, "land", 4))
95 else if (NULL != (ich = item_by_name(p)))
98 pr("Can't load '%s'\n", p);
102 p = getstarg(player->argp[2], "Ship(s): ", buf);
108 if (!snxtitem(&nbst, EF_SHIP, p, NULL))
111 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
114 while (nxtitem(&nbst, &ship)) {
117 if (!player->owner) {
118 if (load_unload == UNLOAD || !noisy)
120 if (getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY)
124 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
128 if (!player->owner) {
129 if (ship.shp_own != player->cnum)
131 if (!sect_has_dock(§))
133 if (load_unload == LOAD) {
135 pr("You don't own %s \n",
136 xyas(sect.sct_x, sect.sct_y, player->cnum));
140 if (!sect_has_dock(§)) {
142 pr("Sector %s is not a harbor or canal.\n",
143 xyas(sect.sct_x, sect.sct_y, player->cnum));
146 if (!player->owner && load_unload == UNLOAD
147 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
149 pr("You can't unload into an unfriendly %s\n",
150 dchr[sect.sct_type].d_name);
153 if (sect.sct_effic < 2) {
155 pr("The %s at %s is not 2%% efficient yet.\n",
156 dchr[sect.sct_type].d_name,
157 xyas(sect.sct_x, sect.sct_y, player->cnum));
162 if (ontradingblock(EF_SHIP, &ship)) {
163 pr("You cannot load/unload an item on the trading block!\n");
170 retval = load_plane_ship(§, &ship, noisy, load_unload,
176 retval = load_land_ship(§, &ship, noisy, load_unload,
182 retval = load_comm_ship(§, &ship, ich, load_unload,
187 /* load/unload plague */
188 if (sect.sct_pstage == PLG_INFECT
189 && ship.shp_pstage == PLG_HEALTHY)
190 ship.shp_pstage = PLG_EXPOSED;
191 if (ship.shp_pstage == PLG_INFECT
192 && sect.sct_pstage == PLG_HEALTHY)
193 sect.sct_pstage = PLG_EXPOSED;
195 putship(ship.shp_uid, &ship);
198 pr("No ships affected\n");
200 pr("%d ship%s %sloaded\n", nships, splur(nships),
201 load_unload == UNLOAD ? "un" : "");
211 struct nstr_item nbst;
220 p = getstarg(player->argp[1],
221 "What commodity (or 'plane' or 'land')? ", buf);
224 if (!strncmp(p, "plane", 5))
226 else if (!strncmp(p, "land", 4))
228 else if (NULL != (ich = item_by_name(p)))
231 pr("Can't load '%s'\n", p);
235 p = getstarg(player->argp[2], "Unit(s): ", buf);
241 if (!snxtitem(&nbst, EF_LAND, p, NULL))
244 load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
247 while (nxtitem(&nbst, &land)) {
248 if (land.lnd_own == 0)
250 if (!player->owner) {
251 if (load_unload == UNLOAD || !noisy)
253 if (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)
257 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
259 if (!player->owner) {
260 if (land.lnd_own != player->cnum)
262 if (load_unload == LOAD) {
264 pr("Sector %s is not yours.\n",
265 xyas(sect.sct_x, sect.sct_y, player->cnum));
268 if (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
269 pr("Sector %s is not yours.\n",
270 xyas(sect.sct_x, sect.sct_y, player->cnum));
276 if (ontradingblock(EF_LAND, &land)) {
277 pr("You cannot load/unload an item on the trading block!\n");
284 retval = load_land_land(§, &land, noisy, load_unload,
290 retval = load_plane_land(§, &land, noisy, load_unload,
296 retval = load_comm_land(§, &land, ich, load_unload,
301 /* load/unload plague */
302 if (sect.sct_pstage == PLG_INFECT
303 && land.lnd_pstage == PLG_HEALTHY)
304 land.lnd_pstage = PLG_EXPOSED;
305 if (land.lnd_pstage == PLG_INFECT
306 && sect.sct_pstage == PLG_HEALTHY)
307 sect.sct_pstage = PLG_EXPOSED;
310 putland(land.lnd_uid, &land);
313 pr("No units affected\n");
315 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
316 load_unload == UNLOAD ? "un" : "");
321 move_amount(int sect_amt, int unit_amt, int unit_max,
322 int load_unload, int amount)
327 move_amt = -amount - unit_amt;
329 move_amt = load_unload == LOAD ? amount : -amount;
330 if (move_amt > unit_max - unit_amt)
331 move_amt = unit_max - unit_amt;
332 if (move_amt < -unit_amt)
333 move_amt = -unit_amt;
334 if (move_amt > sect_amt)
336 if (move_amt < sect_amt - ITEM_MAX)
337 move_amt = sect_amt - ITEM_MAX;
342 load_comm_ok(struct sctstr *sectp, natid unit_own,
343 i_type item, int move_amt)
347 if (move_amt < 0 && !player->god && unit_own != player->cnum)
349 if (move_amt > 0 && !player->god && sectp->sct_own != player->cnum)
351 if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
352 pr("%s civilians refuse to %s at %s!\n",
353 (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
354 ? "Your" : "Foreign",
355 move_amt < 0 ? "disembark" : "board",
356 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
363 gift(natid givee, natid giver, void *ptr, char *mesg)
366 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
367 unit_give_away(ptr, givee, 0);
371 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
373 if (!check_sect_ok(sectp))
375 if (!check_ship_ok(shipp))
381 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
383 if (!check_sect_ok(sectp))
385 if (!check_land_ok(landp))
391 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
392 int load_unload, int *nshipsp)
400 struct mchrstr *mcp = mchr + sp->shp_type;
402 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
404 pr("%s cannot carry planes\n", prship(sp));
407 if (load_unload == LOAD &&
408 shp_nplane(sp, NULL, NULL, NULL)
409 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
411 pr("%s doesn't have room for any more planes\n", prship(sp));
414 sprintf(prompt, "Plane(s) to %s %s? ",
415 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
416 p = getstarg(player->argp[3], prompt, buf);
419 if (!snxtitem(&ni, EF_PLANE, p, NULL))
422 if (!still_ok_ship(sectp, sp))
425 if (noisy && p && *p)
428 while (nxtitem(&ni, &pln)) {
431 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
432 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
433 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
434 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
437 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
440 if (load_unload == LOAD && pln.pln_ship > -1) {
442 pr("%s is already on ship #%d!\n",
443 prplane(&pln), pln.pln_ship);
446 if (load_unload == LOAD && pln.pln_land > -1) {
448 pr("%s is already on land unit #%d!\n",
449 prplane(&pln), pln.pln_land);
452 if (pln.pln_harden != 0) {
454 pr("%s has been hardened and can't be loaded\n",
459 /* Plane sanity done */
460 /* Find the right ship */
461 if (load_unload == UNLOAD) {
462 if (pln.pln_ship != sp->shp_uid)
464 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
467 /* ship to (plane or missle) sanity */
468 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
469 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
470 strcpy(buf, "planes");
471 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
472 strcpy(buf, "choppers");
473 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
474 strcpy(buf, "missiles");
475 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
476 strcpy(buf, "extra light planes");
477 } /* else impossible */
479 pr("%s cannot carry %s.\n", prship(sp), buf);
482 /* Fit plane on ship */
483 if (load_unload == LOAD) {
484 if (!put_plane_on_ship(&pln, sp)) {
486 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
489 sprintf(buf, "loaded on your %s at %s",
490 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
491 gift(sp->shp_own, player->cnum, &pln, buf);
492 putplane(pln.pln_uid, &pln);
495 sprintf(buf, "unloaded in your %s at %s",
496 dchr[sectp->sct_type].d_name,
497 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
498 gift(sectp->sct_own, player->cnum, &pln, buf);
499 putplane(pln.pln_uid, &pln);
501 pr("%s %s %s at %s.\n",
503 (load_unload == UNLOAD) ?
504 "unloaded from" : "loaded onto",
505 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
513 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
514 int load_unload, int *nshipsp)
524 if (load_unload == LOAD) {
526 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
527 (mchr[(int)sp->shp_type].m_nland == 0)) {
528 if (shp_nland(sp) >= 2) {
529 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
532 /* Eh, let 'em load a spy only */
536 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
538 if (mchr[(int)sp->shp_type].m_nland)
539 pr("%s doesn't have room for any more land units!\n",
542 pr("%s cannot carry land units!\n", prship(sp));
547 sprintf(prompt, "Land unit(s) to %s %s? ",
548 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
549 p = getstarg(player->argp[3], prompt, buf);
552 if (!snxtitem(&ni, EF_LAND, p, NULL))
555 if (!still_ok_ship(sectp, sp))
558 if (noisy && p && *p)
561 while (nxtitem(&ni, &land)) {
565 if (load_unload == LOAD) {
566 if (land.lnd_ship > -1) {
568 pr("%s is already on ship #%d!\n",
569 prland(&land), land.lnd_ship);
572 if (land.lnd_land > -1) {
574 pr("%s is already on land #%d!\n",
575 prland(&land), land.lnd_land);
578 if (lnd_first_on_land(&land) >= 0) {
580 pr("%s cannot be loaded since it is carrying units\n",
584 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
586 pr("%s is too heavy to load.\n", prland(&land));
589 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
591 pr("Subs can only carry spy units.\n");
596 /* Unit sanity done */
597 /* Find the right ship */
598 if (load_unload == UNLOAD) {
599 if (land.lnd_ship != sp->shp_uid)
601 if (land.lnd_land > -1)
603 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
606 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
607 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
608 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
610 pr("You can only load light units onto ships,\n");
611 pr("unless the ship is a non-sub supply ship\n");
612 pr("%s not loaded\n", prland(&land));
616 /* Fit unit on ship */
617 if (load_unload == LOAD) {
618 /* We have to check again, since it may have changed */
620 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
621 (mchr[(int)sp->shp_type].m_nland == 0)) {
622 if (shp_nland(sp) >= 2) {
623 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
626 /* Eh, let 'em load a spy only */
630 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
632 if (mchr[(int)sp->shp_type].m_nland)
633 pr("%s doesn't have room for any more land units!\n",
636 pr("%s cannot carry land units!\n", prship(sp));
640 sprintf(buf, "loaded on your %s at %s",
641 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
642 gift(sp->shp_own, player->cnum, &land, buf);
643 land.lnd_ship = sp->shp_uid;
645 putland(land.lnd_uid, &land);
648 * FIXME if this supplies from the sector, the putsect in
649 * load() / lload() duplicates those supplies, causing a
652 if (!lnd_supply_all(&land))
653 pr("WARNING: %s is out of supply!\n", prland(&land));
655 if (!lnd_in_supply(&land))
656 pr("WARNING: %s is out of supply!\n", prland(&land));
659 sprintf(buf, "unloaded in your %s at %s",
660 dchr[sectp->sct_type].d_name,
661 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
663 /* Spies are unloaded quietly, others aren't */
664 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
665 gift(sectp->sct_own, player->cnum, &land, buf);
667 putland(land.lnd_uid, &land);
669 pr("%s %s %s at %s.\n",
671 (load_unload == UNLOAD) ?
672 "unloaded from" : "loaded onto",
673 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
681 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
682 struct ichrstr *ich, int load_unload, int *nshipsp)
684 i_type item = ich->i_uid;
685 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
686 int ship_amt, sect_amt, move_amt;
691 sprintf(prompt, "Number of %s to %s %s at %s? ",
693 (load_unload == UNLOAD) ?
694 "unload from" : "load onto",
695 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
696 p = getstarg(player->argp[3], prompt, buf);
700 if (!still_ok_ship(sectp, sp))
703 ship_amt = sp->shp_item[item];
704 sect_amt = sectp->sct_item[item];
705 move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
706 load_unload, atoi(p));
707 if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
709 if (!want_to_abandon(sectp, item, move_amt, NULL))
711 if (!still_ok_ship(sectp, sp))
713 sectp->sct_item[item] = sect_amt - move_amt;
714 sp->shp_item[item] = ship_amt + move_amt;
717 pr("%d %s loaded onto %s at %s\n",
718 move_amt, ich->i_name,
719 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
720 if (sp->shp_own != player->cnum) {
721 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
722 cname(player->cnum), move_amt, ich->i_name,
723 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
726 pr("%d %s unloaded from %s at %s\n",
727 -move_amt, ich->i_name,
728 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
729 if (sectp->sct_own != player->cnum) {
730 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
731 cname(player->cnum), -move_amt, ich->i_name,
732 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
740 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
741 int load_unload, int *nunitsp)
749 struct lchrstr *lcp = lchr + lp->lnd_type;
751 if (!lcp->l_nxlight) {
753 pr("%s cannot carry extra-light planes.\n", prland(lp));
756 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
758 pr("%s doesn't have room for any more extra-light planes\n",
762 sprintf(prompt, "Plane(s) to %s %s? ",
763 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
764 p = getstarg(player->argp[3], prompt, buf);
767 if (!snxtitem(&ni, EF_PLANE, p, NULL))
770 if (!still_ok_land(sectp, lp))
773 if (noisy && p && *p)
776 while (nxtitem(&ni, &pln)) {
780 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
782 pr("You can only load xlight planes onto units.\n");
786 if (load_unload == LOAD && pln.pln_ship > -1) {
788 pr("%s is already on ship #%d!\n",
789 prplane(&pln), pln.pln_ship);
792 if (load_unload == LOAD && pln.pln_land > -1) {
794 pr("%s is already on unit #%d!\n",
795 prplane(&pln), pln.pln_land);
798 if (pln.pln_harden != 0) {
800 pr("%s has been hardened and can't be loaded\n",
805 /* Plane sanity done */
806 /* Find the right unit */
807 if (load_unload == UNLOAD) {
808 if (pln.pln_land != lp->lnd_uid)
810 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
813 /* Fit plane on unit */
814 if (load_unload == LOAD) {
815 if (!put_plane_on_land(&pln, lp)) {
817 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
820 sprintf(buf, "loaded on %s at %s",
821 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
822 gift(lp->lnd_own, player->cnum, &pln, buf);
823 putplane(pln.pln_uid, &pln);
826 sprintf(buf, "unloaded at your sector at %s",
827 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
828 gift(sectp->sct_own, player->cnum, &pln, buf);
829 putplane(pln.pln_uid, &pln);
831 pr("%s %s %s at %s.\n",
833 (load_unload == UNLOAD) ?
834 "unloaded from" : "loaded onto",
835 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
843 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
844 struct ichrstr *ich, int load_unload, int *nunitsp)
846 i_type item = ich->i_uid;
847 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
848 int land_amt, sect_amt, move_amt;
853 sprintf(prompt, "Number of %s to %s %s at %s? ",
855 (load_unload == UNLOAD) ?
856 "unload from" : "load onto",
857 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
858 p = getstarg(player->argp[3], prompt, buf);
862 if (!still_ok_land(sectp, lp))
865 land_amt = lp->lnd_item[item];
866 sect_amt = sectp->sct_item[item];
867 move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
868 load_unload, atoi(p));
869 if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
871 sectp->sct_item[item] = sect_amt - move_amt;
872 lp->lnd_item[item] = land_amt + move_amt;
874 /* Did we put mils onto this unit? If so, reset the fortification */
875 if (item == I_MILIT && move_amt > 0)
879 pr("%d %s loaded onto %s at %s\n",
880 move_amt, ich->i_name,
881 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
882 if (lp->lnd_own != player->cnum) {
883 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
884 cname(player->cnum), move_amt, ich->i_name,
885 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
888 pr("%d %s unloaded from %s at %s\n",
889 -move_amt, ich->i_name,
890 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
891 if (sectp->sct_own != player->cnum) {
892 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
893 cname(player->cnum), -move_amt, ich->i_name,
894 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
902 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
903 int load_unload, int *nunitsp)
912 if (load_unload == LOAD
913 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
915 if (lchr[lp->lnd_type].l_nland)
916 pr("%s doesn't have room for any more land units!\n",
919 pr("%s cannot carry land units!\n", prland(lp));
923 sprintf(prompt, "Land unit(s) to %s %s? ",
924 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
925 p = getstarg(player->argp[3], prompt, buf);
928 if (!snxtitem(&ni, EF_LAND, p, NULL))
931 if (!still_ok_land(sectp, lp))
934 if (noisy && p && *p)
937 while (nxtitem(&ni, &land)) {
941 if (load_unload == LOAD) {
942 if (land.lnd_ship > -1) {
944 pr("%s is already on ship #%d!\n",
945 prland(&land), land.lnd_ship);
948 if (land.lnd_land > -1) {
950 pr("%s is already on land #%d!\n",
951 prland(&land), land.lnd_land);
954 if (lnd_first_on_land(&land) >= 0) {
956 pr("%s cannot be loaded since it is carrying units\n",
960 if (land.lnd_uid == lp->lnd_uid) {
962 pr("%s can't be loaded onto itself!\n", prland(&land));
965 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
967 pr("%s is too heavy to load.\n", prland(&land));
972 /* Unit sanity done */
973 /* Find the right ship */
974 if (load_unload == UNLOAD) {
975 if (land.lnd_land != lp->lnd_uid)
977 if (land.lnd_ship > -1)
979 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
982 /* Fit unit on ship */
983 if (load_unload == LOAD) {
984 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
986 if (lchr[lp->lnd_type].l_nland)
987 pr("%s doesn't have room for any more land units!\n",
990 pr("%s cannot carry land units!\n", prland(lp));
994 sprintf(buf, "loaded on your %s at %s",
995 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
996 gift(lp->lnd_own, player->cnum, &land, buf);
997 land.lnd_land = lp->lnd_uid;
999 putland(land.lnd_uid, &land);
1001 /* FIXME same issue as in load_land_ship() */
1002 if (!lnd_supply_all(&land))
1003 pr("WARNING: %s is out of supply!\n", prland(&land));
1005 if (!lnd_in_supply(&land))
1006 pr("WARNING: %s is out of supply!\n", prland(&land));
1009 sprintf(buf, "unloaded in your %s at %s",
1010 dchr[sectp->sct_type].d_name,
1011 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1012 gift(sectp->sct_own, player->cnum, &land, buf);
1014 putland(land.lnd_uid, &land);
1016 pr("%s %s %s at %s.\n",
1018 (load_unload == UNLOAD) ?
1019 "unloaded from" : "loaded onto",
1020 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));