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-2008
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");
171 load_plane_ship(§, &ship, noisy, load_unload,
178 load_land_ship(§, &ship, noisy, load_unload,
185 load_comm_ship(§, &ship, ich, load_unload, &nships)))
188 /* load/unload plague */
189 if (sect.sct_pstage == PLG_INFECT
190 && ship.shp_pstage == PLG_HEALTHY)
191 ship.shp_pstage = PLG_EXPOSED;
192 if (ship.shp_pstage == PLG_INFECT
193 && sect.sct_pstage == PLG_HEALTHY)
194 sect.sct_pstage = PLG_EXPOSED;
196 putship(ship.shp_uid, &ship);
199 pr("No ships affected\n");
201 pr("%d ship%s %sloaded\n", nships, splur(nships),
202 load_unload == UNLOAD ? "un" : "");
212 struct nstr_item nbst;
221 if (!(p = getstarg(player->argp[1],
222 "What commodity (or 'plane' or 'land')? ", buf))
225 if (!strncmp(p, "plane", 5))
227 else if (!strncmp(p, "land", 4))
229 else if (NULL != (ich = item_by_name(p)))
232 pr("Can't load '%s'\n", p);
236 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
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");
286 load_land_land(§, &land, noisy, load_unload,
293 load_plane_land(§, &land, noisy, load_unload,
300 load_comm_land(§, &land, ich, load_unload, &nunits)))
303 /* load/unload plague */
304 if (sect.sct_pstage == PLG_INFECT
305 && land.lnd_pstage == PLG_HEALTHY)
306 land.lnd_pstage = PLG_EXPOSED;
307 if (land.lnd_pstage == PLG_INFECT
308 && sect.sct_pstage == PLG_HEALTHY)
309 sect.sct_pstage = PLG_EXPOSED;
312 putland(land.lnd_uid, &land);
315 pr("No units affected\n");
317 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
318 load_unload == UNLOAD ? "un" : "");
323 move_amount(int sect_amt, int unit_amt, int unit_max,
324 int load_unload, int amount)
329 move_amt = -amount - unit_amt;
331 move_amt = load_unload == LOAD ? amount : -amount;
332 if (move_amt > unit_max - unit_amt)
333 move_amt = unit_max - unit_amt;
334 if (move_amt < -unit_amt)
335 move_amt = -unit_amt;
336 if (move_amt > sect_amt)
338 if (move_amt < sect_amt - ITEM_MAX)
339 move_amt = sect_amt - ITEM_MAX;
344 load_comm_ok(struct sctstr *sectp, natid unit_own,
345 i_type item, int move_amt)
349 if (move_amt < 0 && !player->god && unit_own != player->cnum)
351 if (move_amt > 0 && !player->god && sectp->sct_own != player->cnum)
353 if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
354 pr("%s civilians refuse to %s at %s!\n",
355 (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
356 ? "Your" : "Foreign",
357 move_amt < 0 ? "disembark" : "board",
358 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
365 gift(natid givee, natid giver, void *ptr, char *mesg)
368 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
369 unit_give_away(ptr, givee, 0);
373 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
375 if (!check_sect_ok(sectp))
377 if (!check_ship_ok(shipp))
383 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
385 if (!check_sect_ok(sectp))
387 if (!check_land_ok(landp))
393 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
394 int load_unload, int *nshipsp)
402 struct mchrstr *mcp = mchr + sp->shp_type;
404 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
406 pr("%s cannot carry planes\n", prship(sp));
409 if (load_unload == LOAD &&
410 shp_nplane(sp, NULL, NULL, NULL)
411 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
413 pr("%s doesn't have room for any more planes\n", prship(sp));
416 sprintf(prompt, "Plane(s) to %s %s? ",
417 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
418 p = getstarg(player->argp[3], prompt, buf);
421 if (!snxtitem(&ni, EF_PLANE, p, NULL))
424 if (!still_ok_ship(sectp, sp))
427 if (noisy && p && *p)
430 while (nxtitem(&ni, &pln)) {
433 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
434 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
435 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
436 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
439 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
442 if (load_unload == LOAD && pln.pln_ship > -1) {
444 pr("%s is already on ship #%d!\n",
445 prplane(&pln), pln.pln_ship);
448 if (load_unload == LOAD && pln.pln_land > -1) {
450 pr("%s is already on land unit #%d!\n",
451 prplane(&pln), pln.pln_land);
454 if (pln.pln_harden != 0) {
456 pr("%s has been hardened and can't be loaded\n",
461 /* Plane sanity done */
462 /* Find the right ship */
463 if (load_unload == UNLOAD) {
464 if (pln.pln_ship != sp->shp_uid)
466 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
469 /* ship to (plane or missle) sanity */
470 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
471 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
472 strcpy(buf, "planes");
473 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
474 strcpy(buf, "choppers");
475 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
476 strcpy(buf, "missiles");
477 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
478 strcpy(buf, "extra light planes");
479 } /* else impossible */
481 pr("%s cannot carry %s.\n", prship(sp), buf);
484 /* Fit plane on ship */
485 if (load_unload == LOAD) {
486 if (!put_plane_on_ship(&pln, sp)) {
488 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
491 sprintf(buf, "loaded on your %s at %s",
492 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
493 gift(sp->shp_own, player->cnum, &pln, buf);
494 putplane(pln.pln_uid, &pln);
497 sprintf(buf, "unloaded in your %s at %s",
498 dchr[sectp->sct_type].d_name,
499 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
500 gift(sectp->sct_own, player->cnum, &pln, buf);
501 putplane(pln.pln_uid, &pln);
503 pr("%s %s %s at %s.\n",
505 (load_unload == UNLOAD) ?
506 "unloaded from" : "loaded onto",
507 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
515 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
516 int load_unload, int *nshipsp)
526 if (load_unload == LOAD) {
528 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
529 (mchr[(int)sp->shp_type].m_nland == 0)) {
530 if (shp_nland(sp) >= 2) {
531 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
534 /* Eh, let 'em load a spy only */
538 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
540 if (mchr[(int)sp->shp_type].m_nland)
541 pr("%s doesn't have room for any more land units!\n",
544 pr("%s cannot carry land units!\n", prship(sp));
549 sprintf(prompt, "Land unit(s) to %s %s? ",
550 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
551 p = getstarg(player->argp[3], prompt, buf);
554 if (!snxtitem(&ni, EF_LAND, p, NULL))
557 if (!still_ok_ship(sectp, sp))
560 if (noisy && p && *p)
563 while (nxtitem(&ni, &land)) {
567 if (load_unload == LOAD) {
568 if (land.lnd_ship > -1) {
570 pr("%s is already on ship #%d!\n",
571 prland(&land), land.lnd_ship);
574 if (land.lnd_land > -1) {
576 pr("%s is already on land #%d!\n",
577 prland(&land), land.lnd_land);
580 if (lnd_first_on_land(&land) >= 0) {
582 pr("%s cannot be loaded since it is carrying units\n",
586 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
588 pr("%s is too heavy to load.\n", prland(&land));
591 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
593 pr("Subs can only carry spy units.\n");
598 /* Unit sanity done */
599 /* Find the right ship */
600 if (load_unload == UNLOAD) {
601 if (land.lnd_ship != sp->shp_uid)
603 if (land.lnd_land > -1)
605 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
608 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
609 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
610 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
612 pr("You can only load light units onto ships,\n");
613 pr("unless the ship is a non-sub supply ship\n");
614 pr("%s not loaded\n", prland(&land));
618 /* Fit unit on ship */
619 if (load_unload == LOAD) {
620 /* We have to check again, since it may have changed */
622 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
623 (mchr[(int)sp->shp_type].m_nland == 0)) {
624 if (shp_nland(sp) >= 2) {
625 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
628 /* Eh, let 'em load a spy only */
632 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
634 if (mchr[(int)sp->shp_type].m_nland)
635 pr("%s doesn't have room for any more land units!\n",
638 pr("%s cannot carry land units!\n", prship(sp));
642 sprintf(buf, "loaded on your %s at %s",
643 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
644 gift(sp->shp_own, player->cnum, &land, buf);
645 land.lnd_ship = sp->shp_uid;
649 * FIXME if this supplies from the sector, the putsect in
650 * load() / lload() duplicates those supplies, causing a
655 putland(land.lnd_uid, &land);
656 if (!has_supply(&land))
657 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 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
699 if (!still_ok_ship(sectp, sp))
702 ship_amt = sp->shp_item[item];
703 sect_amt = sectp->sct_item[item];
704 move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
705 load_unload, atoi(p));
706 if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
708 if (!want_to_abandon(sectp, item, move_amt, 0))
710 if (!still_ok_ship(sectp, sp))
712 sectp->sct_item[item] = sect_amt - move_amt;
713 sp->shp_item[item] = ship_amt + move_amt;
716 pr("%d %s loaded onto %s at %s\n",
717 move_amt, ich->i_name,
718 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
719 if (sp->shp_own != player->cnum) {
720 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
721 cname(player->cnum), move_amt, ich->i_name,
722 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
725 pr("%d %s unloaded from %s at %s\n",
726 -move_amt, ich->i_name,
727 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
728 if (sectp->sct_own != player->cnum) {
729 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
730 cname(player->cnum), -move_amt, ich->i_name,
731 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
739 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
740 int load_unload, int *nunitsp)
748 struct lchrstr *lcp = lchr + lp->lnd_type;
750 if (!lcp->l_nxlight) {
752 pr("%s cannot carry extra-light planes.\n", prland(lp));
755 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
757 pr("%s doesn't have room for any more extra-light planes\n",
761 sprintf(prompt, "Plane(s) to %s %s? ",
762 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
763 p = getstarg(player->argp[3], prompt, buf);
766 if (!snxtitem(&ni, EF_PLANE, p, NULL))
769 if (!still_ok_land(sectp, lp))
772 if (noisy && p && *p)
775 while (nxtitem(&ni, &pln)) {
779 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
781 pr("You can only load xlight planes onto units.\n");
785 if (load_unload == LOAD && pln.pln_ship > -1) {
787 pr("%s is already on ship #%d!\n",
788 prplane(&pln), pln.pln_ship);
791 if (load_unload == LOAD && pln.pln_land > -1) {
793 pr("%s is already on unit #%d!\n",
794 prplane(&pln), pln.pln_land);
797 if (pln.pln_harden != 0) {
799 pr("%s has been hardened and can't be loaded\n",
804 /* Plane sanity done */
805 /* Find the right unit */
806 if (load_unload == UNLOAD) {
807 if (pln.pln_land != lp->lnd_uid)
809 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
812 /* Fit plane on unit */
813 if (load_unload == LOAD) {
814 if (!put_plane_on_land(&pln, lp)) {
816 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
819 sprintf(buf, "loaded on %s at %s",
820 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
821 gift(lp->lnd_own, player->cnum, &pln, buf);
822 putplane(pln.pln_uid, &pln);
825 sprintf(buf, "unloaded at your sector at %s",
826 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
827 gift(sectp->sct_own, player->cnum, &pln, buf);
828 putplane(pln.pln_uid, &pln);
830 pr("%s %s %s at %s.\n",
832 (load_unload == UNLOAD) ?
833 "unloaded from" : "loaded onto",
834 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
842 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
843 struct ichrstr *ich, int load_unload, int *nunitsp)
845 i_type item = ich->i_uid;
846 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
847 int land_amt, sect_amt, move_amt;
852 sprintf(prompt, "Number of %s to %s %s at %s? ",
854 (load_unload == UNLOAD) ?
855 "unload from" : "load onto",
856 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
857 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
860 if (!still_ok_land(sectp, lp))
863 land_amt = lp->lnd_item[item];
864 sect_amt = sectp->sct_item[item];
865 move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
866 load_unload, atoi(p));
867 if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
869 sectp->sct_item[item] = sect_amt - move_amt;
870 lp->lnd_item[item] = land_amt + move_amt;
872 /* Did we put mils onto this unit? If so, reset the fortification */
873 if (item == I_MILIT && move_amt > 0)
877 pr("%d %s loaded onto %s at %s\n",
878 move_amt, ich->i_name,
879 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
880 if (lp->lnd_own != player->cnum) {
881 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
882 cname(player->cnum), move_amt, ich->i_name,
883 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
886 pr("%d %s unloaded from %s at %s\n",
887 -move_amt, ich->i_name,
888 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
889 if (sectp->sct_own != player->cnum) {
890 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
891 cname(player->cnum), -move_amt, ich->i_name,
892 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
900 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
901 int load_unload, int *nunitsp)
910 if (load_unload == LOAD
911 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
913 if (lchr[lp->lnd_type].l_nland)
914 pr("%s doesn't have room for any more land units!\n",
917 pr("%s cannot carry land units!\n", prland(lp));
921 sprintf(prompt, "Land unit(s) to %s %s? ",
922 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
923 p = getstarg(player->argp[3], prompt, buf);
926 if (!snxtitem(&ni, EF_LAND, p, NULL))
929 if (!still_ok_land(sectp, lp))
932 if (noisy && p && *p)
935 while (nxtitem(&ni, &land)) {
939 if (load_unload == LOAD) {
940 if (land.lnd_ship > -1) {
942 pr("%s is already on ship #%d!\n",
943 prland(&land), land.lnd_ship);
946 if (land.lnd_land > -1) {
948 pr("%s is already on land #%d!\n",
949 prland(&land), land.lnd_land);
952 if (lnd_first_on_land(&land) >= 0) {
954 pr("%s cannot be loaded since it is carrying units\n",
958 if (land.lnd_uid == lp->lnd_uid) {
960 pr("%s can't be loaded onto itself!\n", prland(&land));
963 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
965 pr("%s is too heavy to load.\n", prland(&land));
970 /* Unit sanity done */
971 /* Find the right ship */
972 if (load_unload == UNLOAD) {
973 if (land.lnd_land != lp->lnd_uid)
975 if (land.lnd_ship > -1)
977 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
980 /* Fit unit on ship */
981 if (load_unload == LOAD) {
982 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
984 if (lchr[lp->lnd_type].l_nland)
985 pr("%s doesn't have room for any more land units!\n",
988 pr("%s cannot carry land units!\n", prland(lp));
992 sprintf(buf, "loaded on your %s at %s",
993 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
994 gift(lp->lnd_own, player->cnum, &land, buf);
995 land.lnd_land = lp->lnd_uid;
998 /* FIXME same issue as in load_land_ship() */
1001 putland(land.lnd_uid, &land);
1002 if (!has_supply(&land))
1003 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));