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 if (!(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 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
107 if (!snxtitem(&nbst, EF_SHIP, p, NULL))
110 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
113 while (nxtitem(&nbst, &ship)) {
116 if (!player->owner) {
117 if (load_unload == UNLOAD || !noisy)
119 if (getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY)
123 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
127 if (!player->owner) {
128 if (ship.shp_own != player->cnum)
130 if (!sect_has_dock(§))
132 if (load_unload == LOAD) {
134 pr("You don't own %s \n",
135 xyas(sect.sct_x, sect.sct_y, player->cnum));
139 if (!sect_has_dock(§)) {
141 pr("Sector %s is not a harbor or canal.\n",
142 xyas(sect.sct_x, sect.sct_y, player->cnum));
145 if (!player->owner && load_unload == UNLOAD
146 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
148 pr("You can't unload into an unfriendly %s\n",
149 dchr[sect.sct_type].d_name);
152 if (sect.sct_effic < 2) {
154 pr("The %s at %s is not 2%% efficient yet.\n",
155 dchr[sect.sct_type].d_name,
156 xyas(sect.sct_x, sect.sct_y, player->cnum));
161 if (ontradingblock(EF_SHIP, &ship)) {
162 pr("You cannot load/unload an item on the trading block!\n");
169 retval = load_plane_ship(§, &ship, noisy, load_unload,
175 retval = load_land_ship(§, &ship, noisy, load_unload,
181 retval = load_comm_ship(§, &ship, ich, load_unload,
186 /* load/unload plague */
187 if (sect.sct_pstage == PLG_INFECT
188 && ship.shp_pstage == PLG_HEALTHY)
189 ship.shp_pstage = PLG_EXPOSED;
190 if (ship.shp_pstage == PLG_INFECT
191 && sect.sct_pstage == PLG_HEALTHY)
192 sect.sct_pstage = PLG_EXPOSED;
194 putship(ship.shp_uid, &ship);
197 pr("No ships affected\n");
199 pr("%d ship%s %sloaded\n", nships, splur(nships),
200 load_unload == UNLOAD ? "un" : "");
210 struct nstr_item nbst;
219 if (!(p = getstarg(player->argp[1],
220 "What commodity (or 'plane' or 'land')? ", buf))
223 if (!strncmp(p, "plane", 5))
225 else if (!strncmp(p, "land", 4))
227 else if (NULL != (ich = item_by_name(p)))
230 pr("Can't load '%s'\n", p);
234 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
239 if (!snxtitem(&nbst, EF_LAND, p, NULL))
242 load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
245 while (nxtitem(&nbst, &land)) {
246 if (land.lnd_own == 0)
248 if (!player->owner) {
249 if (load_unload == UNLOAD || !noisy)
251 if (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)
255 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
257 if (!player->owner) {
258 if (land.lnd_own != player->cnum)
260 if (load_unload == LOAD) {
262 pr("Sector %s is not yours.\n",
263 xyas(sect.sct_x, sect.sct_y, player->cnum));
266 if (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
267 pr("Sector %s is not yours.\n",
268 xyas(sect.sct_x, sect.sct_y, player->cnum));
274 if (ontradingblock(EF_LAND, &land)) {
275 pr("You cannot load/unload an item on the trading block!\n");
282 retval = load_land_land(§, &land, noisy, load_unload,
288 retval = load_plane_land(§, &land, noisy, load_unload,
294 retval = load_comm_land(§, &land, ich, load_unload,
299 /* load/unload plague */
300 if (sect.sct_pstage == PLG_INFECT
301 && land.lnd_pstage == PLG_HEALTHY)
302 land.lnd_pstage = PLG_EXPOSED;
303 if (land.lnd_pstage == PLG_INFECT
304 && sect.sct_pstage == PLG_HEALTHY)
305 sect.sct_pstage = PLG_EXPOSED;
308 putland(land.lnd_uid, &land);
311 pr("No units affected\n");
313 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
314 load_unload == UNLOAD ? "un" : "");
319 move_amount(int sect_amt, int unit_amt, int unit_max,
320 int load_unload, int amount)
325 move_amt = -amount - unit_amt;
327 move_amt = load_unload == LOAD ? amount : -amount;
328 if (move_amt > unit_max - unit_amt)
329 move_amt = unit_max - unit_amt;
330 if (move_amt < -unit_amt)
331 move_amt = -unit_amt;
332 if (move_amt > sect_amt)
334 if (move_amt < sect_amt - ITEM_MAX)
335 move_amt = sect_amt - ITEM_MAX;
340 load_comm_ok(struct sctstr *sectp, natid unit_own,
341 i_type item, int move_amt)
345 if (move_amt < 0 && !player->god && unit_own != player->cnum)
347 if (move_amt > 0 && !player->god && sectp->sct_own != player->cnum)
349 if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
350 pr("%s civilians refuse to %s at %s!\n",
351 (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
352 ? "Your" : "Foreign",
353 move_amt < 0 ? "disembark" : "board",
354 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
361 gift(natid givee, natid giver, void *ptr, char *mesg)
364 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
365 unit_give_away(ptr, givee, 0);
369 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
371 if (!check_sect_ok(sectp))
373 if (!check_ship_ok(shipp))
379 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
381 if (!check_sect_ok(sectp))
383 if (!check_land_ok(landp))
389 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
390 int load_unload, int *nshipsp)
398 struct mchrstr *mcp = mchr + sp->shp_type;
400 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
402 pr("%s cannot carry planes\n", prship(sp));
405 if (load_unload == LOAD &&
406 shp_nplane(sp, NULL, NULL, NULL)
407 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
409 pr("%s doesn't have room for any more planes\n", prship(sp));
412 sprintf(prompt, "Plane(s) to %s %s? ",
413 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
414 p = getstarg(player->argp[3], prompt, buf);
417 if (!snxtitem(&ni, EF_PLANE, p, NULL))
420 if (!still_ok_ship(sectp, sp))
423 if (noisy && p && *p)
426 while (nxtitem(&ni, &pln)) {
429 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
430 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
431 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
432 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
435 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
438 if (load_unload == LOAD && pln.pln_ship > -1) {
440 pr("%s is already on ship #%d!\n",
441 prplane(&pln), pln.pln_ship);
444 if (load_unload == LOAD && pln.pln_land > -1) {
446 pr("%s is already on land unit #%d!\n",
447 prplane(&pln), pln.pln_land);
450 if (pln.pln_harden != 0) {
452 pr("%s has been hardened and can't be loaded\n",
457 /* Plane sanity done */
458 /* Find the right ship */
459 if (load_unload == UNLOAD) {
460 if (pln.pln_ship != sp->shp_uid)
462 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
465 /* ship to (plane or missle) sanity */
466 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
467 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
468 strcpy(buf, "planes");
469 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
470 strcpy(buf, "choppers");
471 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
472 strcpy(buf, "missiles");
473 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
474 strcpy(buf, "extra light planes");
475 } /* else impossible */
477 pr("%s cannot carry %s.\n", prship(sp), buf);
480 /* Fit plane on ship */
481 if (load_unload == LOAD) {
482 if (!put_plane_on_ship(&pln, sp)) {
484 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
487 sprintf(buf, "loaded on your %s at %s",
488 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
489 gift(sp->shp_own, player->cnum, &pln, buf);
490 putplane(pln.pln_uid, &pln);
493 sprintf(buf, "unloaded in your %s at %s",
494 dchr[sectp->sct_type].d_name,
495 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
496 gift(sectp->sct_own, player->cnum, &pln, buf);
497 putplane(pln.pln_uid, &pln);
499 pr("%s %s %s at %s.\n",
501 (load_unload == UNLOAD) ?
502 "unloaded from" : "loaded onto",
503 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
511 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
512 int load_unload, int *nshipsp)
522 if (load_unload == LOAD) {
524 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
525 (mchr[(int)sp->shp_type].m_nland == 0)) {
526 if (shp_nland(sp) >= 2) {
527 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
530 /* Eh, let 'em load a spy only */
534 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
536 if (mchr[(int)sp->shp_type].m_nland)
537 pr("%s doesn't have room for any more land units!\n",
540 pr("%s cannot carry land units!\n", prship(sp));
545 sprintf(prompt, "Land unit(s) to %s %s? ",
546 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
547 p = getstarg(player->argp[3], prompt, buf);
550 if (!snxtitem(&ni, EF_LAND, p, NULL))
553 if (!still_ok_ship(sectp, sp))
556 if (noisy && p && *p)
559 while (nxtitem(&ni, &land)) {
563 if (load_unload == LOAD) {
564 if (land.lnd_ship > -1) {
566 pr("%s is already on ship #%d!\n",
567 prland(&land), land.lnd_ship);
570 if (land.lnd_land > -1) {
572 pr("%s is already on land #%d!\n",
573 prland(&land), land.lnd_land);
576 if (lnd_first_on_land(&land) >= 0) {
578 pr("%s cannot be loaded since it is carrying units\n",
582 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
584 pr("%s is too heavy to load.\n", prland(&land));
587 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
589 pr("Subs can only carry spy units.\n");
594 /* Unit sanity done */
595 /* Find the right ship */
596 if (load_unload == UNLOAD) {
597 if (land.lnd_ship != sp->shp_uid)
599 if (land.lnd_land > -1)
601 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
604 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
605 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
606 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
608 pr("You can only load light units onto ships,\n");
609 pr("unless the ship is a non-sub supply ship\n");
610 pr("%s not loaded\n", prland(&land));
614 /* Fit unit on ship */
615 if (load_unload == LOAD) {
616 /* We have to check again, since it may have changed */
618 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
619 (mchr[(int)sp->shp_type].m_nland == 0)) {
620 if (shp_nland(sp) >= 2) {
621 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
624 /* Eh, let 'em load a spy only */
628 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
630 if (mchr[(int)sp->shp_type].m_nland)
631 pr("%s doesn't have room for any more land units!\n",
634 pr("%s cannot carry land units!\n", prship(sp));
638 sprintf(buf, "loaded on your %s at %s",
639 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
640 gift(sp->shp_own, player->cnum, &land, buf);
641 land.lnd_ship = sp->shp_uid;
643 putland(land.lnd_uid, &land);
646 * FIXME if this supplies from the sector, the putsect in
647 * load() / lload() duplicates those supplies, causing a
650 if (!lnd_supply_all(&land))
651 pr("WARNING: %s is out of supply!\n", prland(&land));
653 if (!lnd_in_supply(&land))
654 pr("WARNING: %s is out of supply!\n", prland(&land));
657 sprintf(buf, "unloaded in your %s at %s",
658 dchr[sectp->sct_type].d_name,
659 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
661 /* Spies are unloaded quietly, others aren't */
662 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
663 gift(sectp->sct_own, player->cnum, &land, buf);
665 putland(land.lnd_uid, &land);
667 pr("%s %s %s at %s.\n",
669 (load_unload == UNLOAD) ?
670 "unloaded from" : "loaded onto",
671 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
679 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
680 struct ichrstr *ich, int load_unload, int *nshipsp)
682 i_type item = ich->i_uid;
683 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
684 int ship_amt, sect_amt, move_amt;
689 sprintf(prompt, "Number of %s to %s %s at %s? ",
691 (load_unload == UNLOAD) ?
692 "unload from" : "load onto",
693 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
694 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
697 if (!still_ok_ship(sectp, sp))
700 ship_amt = sp->shp_item[item];
701 sect_amt = sectp->sct_item[item];
702 move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
703 load_unload, atoi(p));
704 if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
706 if (!want_to_abandon(sectp, item, move_amt, 0))
708 if (!still_ok_ship(sectp, sp))
710 sectp->sct_item[item] = sect_amt - move_amt;
711 sp->shp_item[item] = ship_amt + move_amt;
714 pr("%d %s loaded onto %s at %s\n",
715 move_amt, ich->i_name,
716 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
717 if (sp->shp_own != player->cnum) {
718 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
719 cname(player->cnum), move_amt, ich->i_name,
720 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
723 pr("%d %s unloaded from %s at %s\n",
724 -move_amt, ich->i_name,
725 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
726 if (sectp->sct_own != player->cnum) {
727 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
728 cname(player->cnum), -move_amt, ich->i_name,
729 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
737 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
738 int load_unload, int *nunitsp)
746 struct lchrstr *lcp = lchr + lp->lnd_type;
748 if (!lcp->l_nxlight) {
750 pr("%s cannot carry extra-light planes.\n", prland(lp));
753 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
755 pr("%s doesn't have room for any more extra-light planes\n",
759 sprintf(prompt, "Plane(s) to %s %s? ",
760 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
761 p = getstarg(player->argp[3], prompt, buf);
764 if (!snxtitem(&ni, EF_PLANE, p, NULL))
767 if (!still_ok_land(sectp, lp))
770 if (noisy && p && *p)
773 while (nxtitem(&ni, &pln)) {
777 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
779 pr("You can only load xlight planes onto units.\n");
783 if (load_unload == LOAD && pln.pln_ship > -1) {
785 pr("%s is already on ship #%d!\n",
786 prplane(&pln), pln.pln_ship);
789 if (load_unload == LOAD && pln.pln_land > -1) {
791 pr("%s is already on unit #%d!\n",
792 prplane(&pln), pln.pln_land);
795 if (pln.pln_harden != 0) {
797 pr("%s has been hardened and can't be loaded\n",
802 /* Plane sanity done */
803 /* Find the right unit */
804 if (load_unload == UNLOAD) {
805 if (pln.pln_land != lp->lnd_uid)
807 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
810 /* Fit plane on unit */
811 if (load_unload == LOAD) {
812 if (!put_plane_on_land(&pln, lp)) {
814 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
817 sprintf(buf, "loaded on %s at %s",
818 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
819 gift(lp->lnd_own, player->cnum, &pln, buf);
820 putplane(pln.pln_uid, &pln);
823 sprintf(buf, "unloaded at your sector at %s",
824 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
825 gift(sectp->sct_own, player->cnum, &pln, buf);
826 putplane(pln.pln_uid, &pln);
828 pr("%s %s %s at %s.\n",
830 (load_unload == UNLOAD) ?
831 "unloaded from" : "loaded onto",
832 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
840 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
841 struct ichrstr *ich, int load_unload, int *nunitsp)
843 i_type item = ich->i_uid;
844 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
845 int land_amt, sect_amt, move_amt;
850 sprintf(prompt, "Number of %s to %s %s at %s? ",
852 (load_unload == UNLOAD) ?
853 "unload from" : "load onto",
854 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
855 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
858 if (!still_ok_land(sectp, lp))
861 land_amt = lp->lnd_item[item];
862 sect_amt = sectp->sct_item[item];
863 move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
864 load_unload, atoi(p));
865 if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
867 sectp->sct_item[item] = sect_amt - move_amt;
868 lp->lnd_item[item] = land_amt + move_amt;
870 /* Did we put mils onto this unit? If so, reset the fortification */
871 if (item == I_MILIT && move_amt > 0)
875 pr("%d %s loaded onto %s at %s\n",
876 move_amt, ich->i_name,
877 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
878 if (lp->lnd_own != player->cnum) {
879 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
880 cname(player->cnum), move_amt, ich->i_name,
881 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
884 pr("%d %s unloaded from %s at %s\n",
885 -move_amt, ich->i_name,
886 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
887 if (sectp->sct_own != player->cnum) {
888 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
889 cname(player->cnum), -move_amt, ich->i_name,
890 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
898 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
899 int load_unload, int *nunitsp)
908 if (load_unload == LOAD
909 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
911 if (lchr[lp->lnd_type].l_nland)
912 pr("%s doesn't have room for any more land units!\n",
915 pr("%s cannot carry land units!\n", prland(lp));
919 sprintf(prompt, "Land unit(s) to %s %s? ",
920 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
921 p = getstarg(player->argp[3], prompt, buf);
924 if (!snxtitem(&ni, EF_LAND, p, NULL))
927 if (!still_ok_land(sectp, lp))
930 if (noisy && p && *p)
933 while (nxtitem(&ni, &land)) {
937 if (load_unload == LOAD) {
938 if (land.lnd_ship > -1) {
940 pr("%s is already on ship #%d!\n",
941 prland(&land), land.lnd_ship);
944 if (land.lnd_land > -1) {
946 pr("%s is already on land #%d!\n",
947 prland(&land), land.lnd_land);
950 if (lnd_first_on_land(&land) >= 0) {
952 pr("%s cannot be loaded since it is carrying units\n",
956 if (land.lnd_uid == lp->lnd_uid) {
958 pr("%s can't be loaded onto itself!\n", prland(&land));
961 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
963 pr("%s is too heavy to load.\n", prland(&land));
968 /* Unit sanity done */
969 /* Find the right ship */
970 if (load_unload == UNLOAD) {
971 if (land.lnd_land != lp->lnd_uid)
973 if (land.lnd_ship > -1)
975 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
978 /* Fit unit on ship */
979 if (load_unload == LOAD) {
980 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
982 if (lchr[lp->lnd_type].l_nland)
983 pr("%s doesn't have room for any more land units!\n",
986 pr("%s cannot carry land units!\n", prland(lp));
990 sprintf(buf, "loaded on your %s at %s",
991 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
992 gift(lp->lnd_own, player->cnum, &land, buf);
993 land.lnd_land = lp->lnd_uid;
995 putland(land.lnd_uid, &land);
997 /* FIXME same issue as in load_land_ship() */
998 if (!lnd_supply_all(&land))
999 pr("WARNING: %s is out of supply!\n", prland(&land));
1001 if (!lnd_in_supply(&land))
1002 pr("WARNING: %s is out of supply!\n", prland(&land));
1005 sprintf(buf, "unloaded in your %s at %s",
1006 dchr[sectp->sct_type].d_name,
1007 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1008 gift(sectp->sct_own, player->cnum, &land, buf);
1010 putland(land.lnd_uid, &land);
1012 pr("%s %s %s at %s.\n",
1014 (load_unload == UNLOAD) ?
1015 "unloaded from" : "loaded onto",
1016 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));