2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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 && (load_unload == UNLOAD)) {
120 if (ontradingblock(EF_SHIP, &ship)) {
121 pr("You cannot load/unload an item on the trading block!\n");
126 if (ship.shp_own != player->cnum) {
129 if (getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY)
132 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
134 if ((sect.sct_own != player->cnum) &&
135 (ship.shp_own != player->cnum))
137 if (!player->owner &&
138 !sect_has_dock(§))
142 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
144 pr("You don't own %s \n",
145 xyas(ship.shp_x, ship.shp_y, player->cnum));
148 if (!sect_has_dock(§)) {
150 pr("Sector %s is not a harbor or canal.\n",
151 xyas(ship.shp_x, ship.shp_y, player->cnum));
154 if (sect.sct_own != player->cnum && load_unload == UNLOAD
155 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
157 pr("You can't unload into an unfriendly %s\n",
158 dchr[sect.sct_type].d_name);
161 if (sect.sct_effic < 2) {
163 pr("The %s at %s is not 2%% efficient yet.\n",
164 dchr[sect.sct_type].d_name,
165 xyas(ship.shp_x, ship.shp_y, player->cnum));
172 load_plane_ship(§, &ship, noisy, load_unload,
179 load_land_ship(§, &ship, noisy, load_unload,
186 load_comm_ship(§, &ship, ich, load_unload, &nships)))
189 /* load/unload plague */
190 if (sect.sct_pstage == PLG_INFECT
191 && ship.shp_pstage == PLG_HEALTHY)
192 ship.shp_pstage = PLG_EXPOSED;
193 if (ship.shp_pstage == PLG_INFECT
194 && sect.sct_pstage == PLG_HEALTHY)
195 sect.sct_pstage = PLG_EXPOSED;
197 putship(ship.shp_uid, &ship);
200 pr("No ships affected\n");
202 pr("%d ship%s %sloaded\n", nships, splur(nships),
203 load_unload == UNLOAD ? "un" : "");
213 struct nstr_item nbst;
222 if (!(p = getstarg(player->argp[1],
223 "What commodity (or 'plane' or 'land')? ", buf))
226 if (!strncmp(p, "plane", 5))
228 else if (!strncmp(p, "land", 4))
230 else if (NULL != (ich = item_by_name(p)))
233 pr("Can't load '%s'\n", p);
237 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
242 if (!snxtitem(&nbst, EF_LAND, p, NULL))
245 load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
248 while (nxtitem(&nbst, &land)) {
249 if (land.lnd_own == 0)
251 if (!player->owner && load_unload == UNLOAD)
253 if (player->cnum != land.lnd_own) {
256 if (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)
260 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
263 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
266 if (ontradingblock(EF_LAND, &land)) {
267 pr("You cannot load/unload an item on the trading block!\n");
272 if (sect.sct_own != player->cnum && load_unload == LOAD) {
274 pr("Sector %s is not yours.\n",
275 xyas(sect.sct_x, sect.sct_y, player->cnum));
278 if (sect.sct_own != player->cnum &&
279 getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
280 pr("Sector %s is not yours.\n",
281 xyas(land.lnd_x, land.lnd_y, player->cnum));
288 load_land_land(§, &land, noisy, load_unload,
295 load_plane_land(§, &land, noisy, load_unload,
302 load_comm_land(§, &land, ich, load_unload, &nunits)))
305 /* load/unload plague */
306 if (sect.sct_pstage == PLG_INFECT
307 && land.lnd_pstage == PLG_HEALTHY)
308 land.lnd_pstage = PLG_EXPOSED;
309 if (land.lnd_pstage == PLG_INFECT
310 && sect.sct_pstage == PLG_HEALTHY)
311 sect.sct_pstage = PLG_EXPOSED;
314 putland(land.lnd_uid, &land);
317 pr("No units affected\n");
319 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
320 load_unload == UNLOAD ? "un" : "");
325 load_comm_ok(struct sctstr *sectp, i_type item, int move_amt)
329 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
330 pr("%s civilians refuse to %s at %s!\n",
331 move_amt < 0 ? "Your" : "Foreign",
332 move_amt < 0 ? "disembark" : "board",
333 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
340 gift(natid givee, natid giver, void *ptr, char *mesg)
343 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
344 unit_give_away(ptr, givee, 0);
348 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
350 if (!check_sect_ok(sectp))
352 if (!check_ship_ok(shipp))
358 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
360 if (!check_sect_ok(sectp))
362 if (!check_land_ok(landp))
368 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
369 int load_unload, int *nshipsp)
377 struct mchrstr *mcp = mchr + sp->shp_type;
379 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
381 pr("%s cannot carry planes\n", prship(sp));
384 if (load_unload == LOAD &&
385 shp_nplane(sp, NULL, NULL, NULL)
386 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
388 pr("%s doesn't have room for any more planes\n", prship(sp));
391 sprintf(prompt, "Plane(s) to %s %s? ",
392 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
393 p = getstarg(player->argp[3], prompt, buf);
396 if (!snxtitem(&ni, EF_PLANE, p, NULL))
399 if (!still_ok_ship(sectp, sp))
402 if (noisy && p && *p)
405 while (nxtitem(&ni, &pln)) {
406 if (pln.pln_own != player->cnum)
408 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
409 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
410 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
411 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
414 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
417 if (load_unload == LOAD && pln.pln_ship > -1) {
419 pr("%s is already on ship #%d!\n",
420 prplane(&pln), pln.pln_ship);
423 if (load_unload == LOAD && pln.pln_land > -1) {
425 pr("%s is already on land unit #%d!\n",
426 prplane(&pln), pln.pln_land);
429 if (pln.pln_harden != 0) {
431 pr("%s has been hardened and can't be loaded\n",
436 /* Plane sanity done */
437 /* Find the right ship */
438 if (load_unload == UNLOAD) {
439 if (pln.pln_ship != sp->shp_uid)
441 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
444 /* ship to (plane or missle) sanity */
445 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
446 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
447 strcpy(buf, "planes");
448 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
449 strcpy(buf, "choppers");
450 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
451 strcpy(buf, "missiles");
452 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
453 strcpy(buf, "extra light planes");
454 } /* else impossible */
456 pr("%s cannot carry %s.\n", prship(sp), buf);
459 /* Fit plane on ship */
460 if (load_unload == LOAD) {
461 if (!put_plane_on_ship(&pln, sp)) {
463 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
466 sprintf(buf, "loaded on your %s at %s",
467 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
468 gift(sp->shp_own, player->cnum, &pln, buf);
469 putplane(pln.pln_uid, &pln);
472 sprintf(buf, "unloaded in your %s at %s",
473 dchr[sectp->sct_type].d_name,
474 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
475 gift(sectp->sct_own, player->cnum, &pln, buf);
476 putplane(pln.pln_uid, &pln);
478 pr("%s %s %s at %s.\n",
480 (load_unload == UNLOAD) ?
481 "unloaded from" : "loaded onto",
482 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
490 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
491 int load_unload, int *nshipsp)
501 if (load_unload == LOAD) {
503 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
504 (mchr[(int)sp->shp_type].m_nland == 0)) {
505 if (shp_nland(sp) >= 2) {
506 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
509 /* Eh, let 'em load a spy only */
513 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
515 if (mchr[(int)sp->shp_type].m_nland)
516 pr("%s doesn't have room for any more land units!\n",
519 pr("%s cannot carry land units!\n", prship(sp));
524 sprintf(prompt, "Land unit(s) to %s %s? ",
525 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
526 p = getstarg(player->argp[3], prompt, buf);
529 if (!snxtitem(&ni, EF_LAND, p, NULL))
532 if (!still_ok_ship(sectp, sp))
535 if (noisy && p && *p)
538 while (nxtitem(&ni, &land)) {
539 if (land.lnd_own != player->cnum)
542 if (load_unload == LOAD) {
543 if (land.lnd_ship > -1) {
545 pr("%s is already on ship #%d!\n",
546 prland(&land), land.lnd_ship);
549 if (land.lnd_land > -1) {
551 pr("%s is already on land #%d!\n",
552 prland(&land), land.lnd_land);
555 if (lnd_first_on_land(&land) >= 0) {
557 pr("%s cannot be loaded since it is carrying units\n",
561 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
563 pr("%s is too heavy to load.\n", prland(&land));
566 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
568 pr("Subs can only carry spy units.\n");
573 /* Unit sanity done */
574 /* Find the right ship */
575 if (load_unload == UNLOAD) {
576 if (land.lnd_ship != sp->shp_uid)
578 if (land.lnd_land > -1)
580 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
583 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
584 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
585 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
587 pr("You can only load light units onto ships,\n");
588 pr("unless the ship is a non-sub supply ship\n");
589 pr("%s not loaded\n", prland(&land));
593 /* Fit unit on ship */
594 if (load_unload == LOAD) {
595 /* We have to check again, since it may have changed */
597 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
598 (mchr[(int)sp->shp_type].m_nland == 0)) {
599 if (shp_nland(sp) >= 2) {
600 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
603 /* Eh, let 'em load a spy only */
607 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
609 if (mchr[(int)sp->shp_type].m_nland)
610 pr("%s doesn't have room for any more land units!\n",
613 pr("%s cannot carry land units!\n", prship(sp));
617 sprintf(buf, "loaded on your %s at %s",
618 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
619 gift(sp->shp_own, player->cnum, &land, buf);
620 land.lnd_ship = sp->shp_uid;
624 * FIXME if this supplies from the sector, the putsect in
625 * load() / lload() duplicates those supplies, causing a
630 putland(land.lnd_uid, &land);
631 if (!has_supply(&land))
632 pr("WARNING: %s is out of supply!\n", prland(&land));
634 sprintf(buf, "unloaded in your %s at %s",
635 dchr[sectp->sct_type].d_name,
636 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
638 /* Spies are unloaded quietly, others aren't */
639 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
640 gift(sectp->sct_own, player->cnum, &land, buf);
642 putland(land.lnd_uid, &land);
644 pr("%s %s %s at %s.\n",
646 (load_unload == UNLOAD) ?
647 "unloaded from" : "loaded onto",
648 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
656 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
657 struct ichrstr *ich, int load_unload, int *nshipsp)
659 i_type item = ich->i_uid;
660 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
661 int ship_amt, ship_max, sect_amt, move_amt;
667 sprintf(prompt, "Number of %s to %s %s at %s? ",
669 (load_unload == UNLOAD) ?
670 "unload from" : "load onto",
671 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
672 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
675 if (!still_ok_ship(sectp, sp))
678 ship_amt = sp->shp_item[item];
679 ship_max = mcp->m_item[item];
680 sect_amt = sectp->sct_item[item];
683 move_amt = -amount - ship_amt;
685 move_amt = load_unload == LOAD ? amount : -amount;
686 if (move_amt > ship_max - ship_amt)
687 move_amt = ship_max - ship_amt;
688 if (move_amt < -ship_amt)
689 move_amt = -ship_amt;
690 if (move_amt > sect_amt)
692 if (move_amt < sect_amt - ITEM_MAX)
693 move_amt = sect_amt - ITEM_MAX;
694 if (!load_comm_ok(sectp, item, move_amt))
696 if (!want_to_abandon(sectp, item, move_amt, 0))
698 if (!still_ok_ship(sectp, sp))
700 sectp->sct_item[item] = sect_amt - move_amt;
701 sp->shp_item[item] = ship_amt + move_amt;
703 pr("%d %s loaded onto %s at %s\n",
704 move_amt, ich->i_name,
705 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
706 if (sp->shp_own != player->cnum) {
707 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
708 cname(player->cnum), move_amt, ich->i_name,
709 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
712 pr("%d %s unloaded from %s at %s\n",
713 -move_amt, ich->i_name,
714 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
715 if (sectp->sct_own != player->cnum) {
716 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
717 cname(player->cnum), -move_amt, ich->i_name,
718 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
726 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
727 int load_unload, int *nunitsp)
735 struct lchrstr *lcp = lchr + lp->lnd_type;
737 if (!lcp->l_nxlight) {
739 pr("%s cannot carry extra-light planes.\n", prland(lp));
742 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
744 pr("%s doesn't have room for any more extra-light planes\n",
748 sprintf(prompt, "Plane(s) to %s %s? ",
749 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
750 p = getstarg(player->argp[3], prompt, buf);
753 if (!snxtitem(&ni, EF_PLANE, p, NULL))
756 if (!still_ok_land(sectp, lp))
759 if (noisy && p && *p)
762 while (nxtitem(&ni, &pln)) {
763 if (pln.pln_own != player->cnum)
766 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
768 pr("You can only load xlight planes onto units.\n");
772 if (load_unload == LOAD && pln.pln_ship > -1) {
774 pr("%s is already on ship #%d!\n",
775 prplane(&pln), pln.pln_ship);
778 if (load_unload == LOAD && pln.pln_land > -1) {
780 pr("%s is already on unit #%d!\n",
781 prplane(&pln), pln.pln_land);
784 if (pln.pln_harden != 0) {
786 pr("%s has been hardened and can't be loaded\n",
791 /* Plane sanity done */
792 /* Find the right unit */
793 if (load_unload == UNLOAD) {
794 if (pln.pln_land != lp->lnd_uid)
796 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
799 /* Fit plane on unit */
800 if (load_unload == LOAD) {
801 if (!put_plane_on_land(&pln, lp)) {
803 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
806 sprintf(buf, "loaded on %s at %s",
807 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
808 gift(lp->lnd_own, player->cnum, &pln, buf);
809 putplane(pln.pln_uid, &pln);
812 sprintf(buf, "unloaded at your sector at %s",
813 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
814 gift(sectp->sct_own, player->cnum, &pln, buf);
815 putplane(pln.pln_uid, &pln);
817 pr("%s %s %s at %s.\n",
819 (load_unload == UNLOAD) ?
820 "unloaded from" : "loaded onto",
821 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
829 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
830 struct ichrstr *ich, int load_unload, int *nunitsp)
832 i_type item = ich->i_uid;
833 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
834 int land_amt, land_max, sect_amt, move_amt;
840 sprintf(prompt, "Number of %s to %s %s at %s? ",
842 (load_unload == UNLOAD) ?
843 "unload from" : "load onto",
844 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
845 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
848 if (!still_ok_land(sectp, lp))
851 land_amt = lp->lnd_item[item];
852 land_max = lcp->l_item[item];
853 sect_amt = sectp->sct_item[item];
856 move_amt = -amount - land_amt;
858 move_amt = load_unload == LOAD ? amount : -amount;
859 if (move_amt > land_max - land_amt)
860 move_amt = land_max - land_amt;
861 if (move_amt < -land_amt)
862 move_amt = -land_amt;
863 if (move_amt > sect_amt)
865 if (move_amt < sect_amt - ITEM_MAX)
866 move_amt = sect_amt - ITEM_MAX;
867 if (!load_comm_ok(sectp, item, move_amt))
869 if (sectp->sct_own != player->cnum && move_amt > 0) {
870 pr("Sector %s is not yours.\n",
871 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
874 sectp->sct_item[item] = sect_amt - move_amt;
875 lp->lnd_item[item] = land_amt + move_amt;
877 /* Did we put mils onto this unit? If so, reset the fortification */
878 if (item == I_MILIT && move_amt > 0)
881 pr("%d %s loaded onto %s at %s\n",
882 move_amt, ich->i_name,
883 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
884 if (lp->lnd_own != player->cnum) {
885 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
886 cname(player->cnum), move_amt, ich->i_name,
887 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
890 pr("%d %s unloaded from %s at %s\n",
891 -move_amt, ich->i_name,
892 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
893 if (sectp->sct_own != player->cnum) {
894 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
895 cname(player->cnum), -move_amt, ich->i_name,
896 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
904 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
905 int load_unload, int *nunitsp)
914 if (load_unload == LOAD
915 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
917 if (lchr[lp->lnd_type].l_nland)
918 pr("%s doesn't have room for any more land units!\n",
921 pr("%s cannot carry land units!\n", prland(lp));
925 sprintf(prompt, "Land unit(s) to %s %s? ",
926 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
927 p = getstarg(player->argp[3], prompt, buf);
930 if (!snxtitem(&ni, EF_LAND, p, NULL))
933 if (!still_ok_land(sectp, lp))
936 if (noisy && p && *p)
939 while (nxtitem(&ni, &land)) {
941 if (land.lnd_own != player->cnum)
944 if (load_unload == LOAD) {
945 if (land.lnd_ship > -1) {
947 pr("%s is already on ship #%d!\n",
948 prland(&land), land.lnd_ship);
951 if (land.lnd_land > -1) {
953 pr("%s is already on land #%d!\n",
954 prland(&land), land.lnd_land);
957 if (lnd_first_on_land(&land) >= 0) {
959 pr("%s cannot be loaded since it is carrying units\n",
963 if (land.lnd_uid == lp->lnd_uid) {
965 pr("%s can't be loaded onto itself!\n", prland(&land));
968 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
970 pr("%s is too heavy to load.\n", prland(&land));
975 /* Unit sanity done */
976 /* Find the right ship */
977 if (load_unload == UNLOAD) {
978 if (land.lnd_land != lp->lnd_uid)
980 if (land.lnd_ship > -1)
982 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
985 /* Fit unit on ship */
986 if (load_unload == LOAD) {
987 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
989 if (lchr[lp->lnd_type].l_nland)
990 pr("%s doesn't have room for any more land units!\n",
993 pr("%s cannot carry land units!\n", prland(lp));
997 sprintf(buf, "loaded on your %s at %s",
998 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
999 gift(lp->lnd_own, player->cnum, &land, buf);
1000 land.lnd_land = lp->lnd_uid;
1001 land.lnd_harden = 0;
1003 /* FIXME same issue as in load_land_ship() */
1004 resupply_all(&land);
1006 putland(land.lnd_uid, &land);
1007 if (!has_supply(&land))
1008 pr("WARNING: %s is out of supply!\n", prland(&land));
1010 sprintf(buf, "unloaded in your %s at %s",
1011 dchr[sectp->sct_type].d_name,
1012 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1013 gift(sectp->sct_own, player->cnum, &land, buf);
1015 putland(land.lnd_uid, &land);
1017 pr("%s %s %s at %s.\n",
1019 (load_unload == UNLOAD) ?
1020 "unloaded from" : "loaded onto",
1021 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));