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(player->cnum), ship.shp_own) < 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)
252 if (player->cnum != land.lnd_own &&
253 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
256 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
259 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
262 if (ontradingblock(EF_LAND, &land)) {
263 pr("You cannot load/unload an item on the trading block!\n");
268 if (sect.sct_own != player->cnum &&
269 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
270 pr("Sector %s is not yours.\n",
271 xyas(land.lnd_x, land.lnd_y, player->cnum));
278 load_land_land(§, &land, noisy, load_unload,
285 load_plane_land(§, &land, noisy, load_unload,
292 load_comm_land(§, &land, ich, load_unload, &nunits)))
295 /* load/unload plague */
296 if (sect.sct_pstage == PLG_INFECT
297 && land.lnd_pstage == PLG_HEALTHY)
298 land.lnd_pstage = PLG_EXPOSED;
299 if (land.lnd_pstage == PLG_INFECT
300 && sect.sct_pstage == PLG_HEALTHY)
301 sect.sct_pstage = PLG_EXPOSED;
304 putland(land.lnd_uid, &land);
307 pr("No units affected\n");
309 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
310 load_unload == UNLOAD ? "un" : "");
315 gift(natid givee, natid giver, void *ptr, char *mesg)
318 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
319 unit_give_away(ptr, givee, 0);
323 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
325 if (!check_sect_ok(sectp))
327 if (!check_ship_ok(shipp))
333 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
335 if (!check_sect_ok(sectp))
337 if (!check_land_ok(landp))
343 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
344 int load_unload, int *nshipsp)
352 struct mchrstr *mcp = mchr + sp->shp_type;
354 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
356 pr("%s cannot carry planes\n", prship(sp));
359 if (load_unload == LOAD &&
360 shp_nplane(sp, NULL, NULL, NULL)
361 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
363 pr("%s doesn't have room for any more planes\n", prship(sp));
366 sprintf(prompt, "Plane(s) to %s %s? ",
367 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
368 p = getstarg(player->argp[3], prompt, buf);
371 if (!snxtitem(&ni, EF_PLANE, p, NULL))
374 if (!still_ok_ship(sectp, sp))
377 if (noisy && p && *p)
380 while (nxtitem(&ni, &pln)) {
381 if (pln.pln_own != player->cnum)
383 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
384 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
385 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
386 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
389 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
392 if (load_unload == LOAD && pln.pln_ship > -1) {
394 pr("%s is already on ship #%d!\n",
395 prplane(&pln), pln.pln_ship);
398 if (load_unload == LOAD && pln.pln_land > -1) {
400 pr("%s is already on land unit #%d!\n",
401 prplane(&pln), pln.pln_land);
404 if (pln.pln_harden != 0) {
406 pr("%s has been hardened and can't be loaded\n",
411 /* Plane sanity done */
412 /* Find the right ship */
413 if (load_unload == UNLOAD) {
414 if (pln.pln_ship != sp->shp_uid)
416 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
419 /* ship to (plane or missle) sanity */
420 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
421 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
422 strcpy(buf, "planes");
423 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
424 strcpy(buf, "choppers");
425 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
426 strcpy(buf, "missiles");
427 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
428 strcpy(buf, "extra light planes");
429 } /* else impossible */
431 pr("%s cannot carry %s.\n", prship(sp), buf);
434 /* Fit plane on ship */
435 if (load_unload == LOAD) {
436 if (!put_plane_on_ship(&pln, sp)) {
438 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
441 sprintf(buf, "loaded on your %s at %s",
442 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
443 gift(sp->shp_own, player->cnum, &pln, buf);
444 putplane(pln.pln_uid, &pln);
447 sprintf(buf, "unloaded in your %s at %s",
448 dchr[sectp->sct_type].d_name,
449 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
450 gift(sectp->sct_own, player->cnum, &pln, buf);
451 putplane(pln.pln_uid, &pln);
453 pr("%s %s %s at %s.\n",
455 (load_unload == UNLOAD) ?
456 "unloaded from" : "loaded onto",
457 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
465 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
466 int load_unload, int *nshipsp)
476 if (load_unload == LOAD) {
478 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
479 (mchr[(int)sp->shp_type].m_nland == 0)) {
480 if (shp_nland(sp) >= 2) {
481 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
484 /* Eh, let 'em load a spy only */
488 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
490 if (mchr[(int)sp->shp_type].m_nland)
491 pr("%s doesn't have room for any more land units!\n",
494 pr("%s cannot carry land units!\n", prship(sp));
499 sprintf(prompt, "Land unit(s) to %s %s? ",
500 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
501 p = getstarg(player->argp[3], prompt, buf);
504 if (!snxtitem(&ni, EF_LAND, p, NULL))
507 if (!still_ok_ship(sectp, sp))
510 if (noisy && p && *p)
513 while (nxtitem(&ni, &land)) {
514 if (land.lnd_own != player->cnum)
517 if (load_unload == LOAD) {
518 if (land.lnd_ship > -1) {
520 pr("%s is already on ship #%d!\n",
521 prland(&land), land.lnd_ship);
524 if (land.lnd_land > -1) {
526 pr("%s is already on land #%d!\n",
527 prland(&land), land.lnd_land);
530 if (lnd_first_on_land(&land) >= 0) {
532 pr("%s cannot be loaded since it is carrying units\n",
536 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
538 pr("%s is too heavy to load.\n", prland(&land));
541 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
543 pr("Subs can only carry spy units.\n");
548 /* Unit sanity done */
549 /* Find the right ship */
550 if (load_unload == UNLOAD) {
551 if (land.lnd_ship != sp->shp_uid)
553 if (land.lnd_land > -1)
555 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
558 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
559 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
560 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
562 pr("You can only load light units onto ships,\n");
563 pr("unless the ship is a non-sub supply ship\n");
564 pr("%s not loaded\n", prland(&land));
568 /* Fit unit on ship */
569 if (load_unload == LOAD) {
570 /* We have to check again, since it may have changed */
572 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
573 (mchr[(int)sp->shp_type].m_nland == 0)) {
574 if (shp_nland(sp) >= 2) {
575 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
578 /* Eh, let 'em load a spy only */
582 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
584 if (mchr[(int)sp->shp_type].m_nland)
585 pr("%s doesn't have room for any more land units!\n",
588 pr("%s cannot carry land units!\n", prship(sp));
592 sprintf(buf, "loaded on your %s at %s",
593 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
594 gift(sp->shp_own, player->cnum, &land, buf);
595 land.lnd_ship = sp->shp_uid;
599 * FIXME if this supplies from the sector, the putsect in
600 * load() / lload() duplicates those supplies, causing a
605 putland(land.lnd_uid, &land);
606 if (!has_supply(&land))
607 pr("WARNING: %s is out of supply!\n", prland(&land));
609 sprintf(buf, "unloaded in your %s at %s",
610 dchr[sectp->sct_type].d_name,
611 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
613 /* Spies are unloaded quietly, others aren't */
614 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
615 gift(sectp->sct_own, player->cnum, &land, buf);
617 putland(land.lnd_uid, &land);
619 pr("%s %s %s at %s.\n",
621 (load_unload == UNLOAD) ?
622 "unloaded from" : "loaded onto",
623 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
631 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
632 struct ichrstr *ich, int load_unload, int *nshipsp)
634 i_type item = ich->i_uid;
635 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
636 int ship_amt, ship_max, sect_amt, move_amt;
642 sprintf(prompt, "Number of %s to %s %s at %s? ",
644 (load_unload == UNLOAD) ?
645 "unload from" : "load onto",
646 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
647 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
650 if (!still_ok_ship(sectp, sp))
653 ship_amt = sp->shp_item[item];
654 ship_max = mcp->m_item[item];
655 sect_amt = sectp->sct_item[item];
658 move_amt = -amount - ship_amt;
660 move_amt = load_unload == LOAD ? amount : -amount;
661 if (move_amt > ship_max - ship_amt)
662 move_amt = ship_max - ship_amt;
663 if (move_amt < -ship_amt)
664 move_amt = -ship_amt;
665 if (move_amt > sect_amt)
667 if (move_amt < sect_amt - ITEM_MAX)
668 move_amt = sect_amt - ITEM_MAX;
671 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
672 pr("%s civilians refuse to %s at %s!\n",
673 move_amt < 0 ? "Your" : "Foreign",
674 move_amt < 0 ? "disembark" : "board",
675 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
679 if (!want_to_abandon(sectp, item, move_amt, 0))
681 if (!still_ok_ship(sectp, sp))
683 sectp->sct_item[item] = sect_amt - move_amt;
684 sp->shp_item[item] = ship_amt + move_amt;
686 pr("%d %s loaded onto %s at %s\n",
687 move_amt, ich->i_name,
688 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
689 if (sp->shp_own != player->cnum) {
690 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
691 cname(player->cnum), move_amt, ich->i_name,
692 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
695 pr("%d %s unloaded from %s at %s\n",
696 -move_amt, ich->i_name,
697 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
698 if (sectp->sct_own != player->cnum) {
699 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
700 cname(player->cnum), -move_amt, ich->i_name,
701 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
709 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
710 int load_unload, int *nunitsp)
718 struct lchrstr *lcp = lchr + lp->lnd_type;
720 if (!lcp->l_nxlight) {
722 pr("%s cannot carry extra-light planes.\n", prland(lp));
725 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
727 pr("%s doesn't have room for any more extra-light planes\n",
731 sprintf(prompt, "Plane(s) to %s %s? ",
732 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
733 p = getstarg(player->argp[3], prompt, buf);
736 if (!snxtitem(&ni, EF_PLANE, p, NULL))
739 if (!still_ok_land(sectp, lp))
742 if (noisy && p && *p)
745 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
746 pr("Sector %s is not yours.\n",
747 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
751 while (nxtitem(&ni, &pln)) {
752 if (pln.pln_own != player->cnum)
755 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
757 pr("You can only load xlight planes onto units.\n");
761 if (load_unload == LOAD && pln.pln_ship > -1) {
763 pr("%s is already on ship #%d!\n",
764 prplane(&pln), pln.pln_ship);
767 if (load_unload == LOAD && pln.pln_land > -1) {
769 pr("%s is already on unit #%d!\n",
770 prplane(&pln), pln.pln_land);
773 if (pln.pln_harden != 0) {
775 pr("%s has been hardened and can't be loaded\n",
780 /* Plane sanity done */
781 /* Find the right unit */
782 if (load_unload == UNLOAD) {
783 if (pln.pln_land != lp->lnd_uid)
785 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
788 /* Fit plane on unit */
789 if (load_unload == LOAD) {
790 if (!put_plane_on_land(&pln, lp)) {
792 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
795 sprintf(buf, "loaded on %s at %s",
796 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
797 gift(lp->lnd_own, player->cnum, &pln, buf);
798 putplane(pln.pln_uid, &pln);
801 sprintf(buf, "unloaded at your sector at %s",
802 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
803 gift(sectp->sct_own, player->cnum, &pln, buf);
804 putplane(pln.pln_uid, &pln);
806 pr("%s %s %s at %s.\n",
808 (load_unload == UNLOAD) ?
809 "unloaded from" : "loaded onto",
810 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
818 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
819 struct ichrstr *ich, int load_unload, int *nunitsp)
821 i_type item = ich->i_uid;
822 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
823 int land_amt, land_max, sect_amt, move_amt;
829 sprintf(prompt, "Number of %s to %s %s at %s? ",
831 (load_unload == UNLOAD) ?
832 "unload from" : "load onto",
833 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
834 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
837 if (!still_ok_land(sectp, lp))
840 land_amt = lp->lnd_item[item];
841 land_max = lcp->l_item[item];
842 sect_amt = sectp->sct_item[item];
845 move_amt = -amount - land_amt;
847 move_amt = load_unload == LOAD ? amount : -amount;
848 if (move_amt > land_max - land_amt)
849 move_amt = land_max - land_amt;
850 if (move_amt < -land_amt)
851 move_amt = -land_amt;
852 if (move_amt > sect_amt)
854 if (move_amt < sect_amt - ITEM_MAX)
855 move_amt = sect_amt - ITEM_MAX;
858 if (sectp->sct_own != player->cnum && move_amt > 0) {
859 pr("Sector %s is not yours.\n",
860 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
863 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
864 pr("%s civilians refuse to %s at %s!\n",
865 move_amt < 0 ? "Your" : "Foreign",
866 move_amt < 0 ? "disembark" : "board",
867 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
870 sectp->sct_item[item] = sect_amt - move_amt;
871 lp->lnd_item[item] = land_amt + move_amt;
873 /* Did we put mils onto this unit? If so, reset the fortification */
874 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)) {
937 if (land.lnd_own != player->cnum)
940 if (load_unload == LOAD) {
941 if (land.lnd_ship > -1) {
943 pr("%s is already on ship #%d!\n",
944 prland(&land), land.lnd_ship);
947 if (land.lnd_land > -1) {
949 pr("%s is already on land #%d!\n",
950 prland(&land), land.lnd_land);
953 if (lnd_first_on_land(&land) >= 0) {
955 pr("%s cannot be loaded since it is carrying units\n",
959 if (land.lnd_uid == lp->lnd_uid) {
961 pr("%s can't be loaded onto itself!\n", prland(&land));
964 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
966 pr("%s is too heavy to load.\n", prland(&land));
971 /* Unit sanity done */
972 /* Find the right ship */
973 if (load_unload == UNLOAD) {
974 if (land.lnd_land != lp->lnd_uid)
976 if (land.lnd_ship > -1)
978 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
981 /* Fit unit on ship */
982 if (load_unload == LOAD) {
983 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
985 if (lchr[lp->lnd_type].l_nland)
986 pr("%s doesn't have room for any more land units!\n",
989 pr("%s cannot carry land units!\n", prland(lp));
993 sprintf(buf, "loaded on your %s at %s",
994 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
995 gift(lp->lnd_own, player->cnum, &land, buf);
996 land.lnd_land = lp->lnd_uid;
999 /* FIXME same issue as in load_land_ship() */
1000 resupply_all(&land);
1002 putland(land.lnd_uid, &land);
1003 if (!has_supply(&land))
1004 pr("WARNING: %s is out of supply!\n", prland(&land));
1006 sprintf(buf, "unloaded in your %s at %s",
1007 dchr[sectp->sct_type].d_name,
1008 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1009 gift(sectp->sct_own, player->cnum, &land, buf);
1011 putland(land.lnd_uid, &land);
1013 pr("%s %s %s at %s.\n",
1015 (load_unload == UNLOAD) ?
1016 "unloaded from" : "loaded onto",
1017 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));