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;
598 putland(land.lnd_uid, &land);
599 if (!has_supply(&land))
600 pr("WARNING: %s is out of supply!\n", prland(&land));
602 sprintf(buf, "unloaded in your %s at %s",
603 dchr[sectp->sct_type].d_name,
604 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
606 /* Spies are unloaded quietly, others aren't */
607 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
608 gift(sectp->sct_own, player->cnum, &land, buf);
610 putland(land.lnd_uid, &land);
612 pr("%s %s %s at %s.\n",
614 (load_unload == UNLOAD) ?
615 "unloaded from" : "loaded onto",
616 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
624 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
625 struct ichrstr *ich, int load_unload, int *nshipsp)
627 i_type item = ich->i_uid;
628 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
629 int ship_amt, ship_max, sect_amt, move_amt;
635 sprintf(prompt, "Number of %s to %s %s at %s? ",
637 (load_unload == UNLOAD) ?
638 "unload from" : "load onto",
639 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
640 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
643 if (!still_ok_ship(sectp, sp))
646 ship_amt = sp->shp_item[item];
647 ship_max = mcp->m_item[item];
648 sect_amt = sectp->sct_item[item];
651 move_amt = -amount - ship_amt;
653 move_amt = load_unload == LOAD ? amount : -amount;
654 if (move_amt > ship_max - ship_amt)
655 move_amt = ship_max - ship_amt;
656 if (move_amt < -ship_amt)
657 move_amt = -ship_amt;
658 if (move_amt > sect_amt)
660 if (move_amt < sect_amt - ITEM_MAX)
661 move_amt = sect_amt - ITEM_MAX;
664 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
665 pr("%s civilians refuse to %s at %s!\n",
666 move_amt < 0 ? "Your" : "Foreign",
667 move_amt < 0 ? "disembark" : "board",
668 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
672 if (!want_to_abandon(sectp, item, move_amt, 0))
674 if (!still_ok_ship(sectp, sp))
676 sectp->sct_item[item] = sect_amt - move_amt;
677 sp->shp_item[item] = ship_amt + move_amt;
679 pr("%d %s loaded onto %s at %s\n",
680 move_amt, ich->i_name,
681 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
682 if (sp->shp_own != player->cnum) {
683 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
684 cname(player->cnum), move_amt, ich->i_name,
685 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
688 pr("%d %s unloaded from %s at %s\n",
689 -move_amt, ich->i_name,
690 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
691 if (sectp->sct_own != player->cnum) {
692 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
693 cname(player->cnum), -move_amt, ich->i_name,
694 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
702 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
703 int load_unload, int *nunitsp)
711 struct lchrstr *lcp = lchr + lp->lnd_type;
713 if (!lcp->l_nxlight) {
715 pr("%s cannot carry extra-light planes.\n", prland(lp));
718 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
720 pr("%s doesn't have room for any more extra-light planes\n",
724 sprintf(prompt, "Plane(s) to %s %s? ",
725 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
726 p = getstarg(player->argp[3], prompt, buf);
729 if (!snxtitem(&ni, EF_PLANE, p, NULL))
732 if (!still_ok_land(sectp, lp))
735 if (noisy && p && *p)
738 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
739 pr("Sector %s is not yours.\n",
740 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
744 while (nxtitem(&ni, &pln)) {
745 if (pln.pln_own != player->cnum)
748 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
750 pr("You can only load xlight planes onto units.\n");
754 if (load_unload == LOAD && pln.pln_ship > -1) {
756 pr("%s is already on ship #%d!\n",
757 prplane(&pln), pln.pln_ship);
760 if (load_unload == LOAD && pln.pln_land > -1) {
762 pr("%s is already on unit #%d!\n",
763 prplane(&pln), pln.pln_land);
766 if (pln.pln_harden != 0) {
768 pr("%s has been hardened and can't be loaded\n",
773 /* Plane sanity done */
774 /* Find the right unit */
775 if (load_unload == UNLOAD) {
776 if (pln.pln_land != lp->lnd_uid)
778 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
781 /* Fit plane on unit */
782 if (load_unload == LOAD) {
783 if (!put_plane_on_land(&pln, lp)) {
785 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
788 sprintf(buf, "loaded on %s at %s",
789 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
790 gift(lp->lnd_own, player->cnum, &pln, buf);
791 putplane(pln.pln_uid, &pln);
794 sprintf(buf, "unloaded at your sector at %s",
795 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
796 gift(sectp->sct_own, player->cnum, &pln, buf);
797 putplane(pln.pln_uid, &pln);
799 pr("%s %s %s at %s.\n",
801 (load_unload == UNLOAD) ?
802 "unloaded from" : "loaded onto",
803 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
811 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
812 struct ichrstr *ich, int load_unload, int *nunitsp)
814 i_type item = ich->i_uid;
815 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
816 int land_amt, land_max, sect_amt, move_amt;
822 sprintf(prompt, "Number of %s to %s %s at %s? ",
824 (load_unload == UNLOAD) ?
825 "unload from" : "load onto",
826 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
827 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
830 if (!still_ok_land(sectp, lp))
833 land_amt = lp->lnd_item[item];
834 land_max = lcp->l_item[item];
835 sect_amt = sectp->sct_item[item];
838 move_amt = -amount - land_amt;
840 move_amt = load_unload == LOAD ? amount : -amount;
841 if (move_amt > land_max - land_amt)
842 move_amt = land_max - land_amt;
843 if (move_amt < -land_amt)
844 move_amt = -land_amt;
845 if (move_amt > sect_amt)
847 if (move_amt < sect_amt - ITEM_MAX)
848 move_amt = sect_amt - ITEM_MAX;
851 if (sectp->sct_own != player->cnum && move_amt > 0) {
852 pr("Sector %s is not yours.\n",
853 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
856 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
857 pr("%s civilians refuse to %s at %s!\n",
858 move_amt < 0 ? "Your" : "Foreign",
859 move_amt < 0 ? "disembark" : "board",
860 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
863 sectp->sct_item[item] = sect_amt - move_amt;
864 lp->lnd_item[item] = land_amt + move_amt;
866 /* Did we put mils onto this unit? If so, reset the fortification */
867 if (item == I_MILIT && move_amt > 0)
870 pr("%d %s loaded onto %s at %s\n",
871 move_amt, ich->i_name,
872 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
873 if (lp->lnd_own != player->cnum) {
874 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
875 cname(player->cnum), move_amt, ich->i_name,
876 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
879 pr("%d %s unloaded from %s at %s\n",
880 -move_amt, ich->i_name,
881 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
882 if (sectp->sct_own != player->cnum) {
883 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
884 cname(player->cnum), -move_amt, ich->i_name,
885 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
893 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
894 int load_unload, int *nunitsp)
903 if (load_unload == LOAD
904 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
906 if (lchr[lp->lnd_type].l_nland)
907 pr("%s doesn't have room for any more land units!\n",
910 pr("%s cannot carry land units!\n", prland(lp));
914 sprintf(prompt, "Land unit(s) to %s %s? ",
915 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
916 p = getstarg(player->argp[3], prompt, buf);
919 if (!snxtitem(&ni, EF_LAND, p, NULL))
922 if (!still_ok_land(sectp, lp))
925 if (noisy && p && *p)
928 while (nxtitem(&ni, &land)) {
930 if (land.lnd_own != player->cnum)
933 if (load_unload == LOAD) {
934 if (land.lnd_ship > -1) {
936 pr("%s is already on ship #%d!\n",
937 prland(&land), land.lnd_ship);
940 if (land.lnd_land > -1) {
942 pr("%s is already on land #%d!\n",
943 prland(&land), land.lnd_land);
946 if (lnd_first_on_land(&land) >= 0) {
948 pr("%s cannot be loaded since it is carrying units\n",
952 if (land.lnd_uid == lp->lnd_uid) {
954 pr("%s can't be loaded onto itself!\n", prland(&land));
957 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
959 pr("%s is too heavy to load.\n", prland(&land));
964 /* Unit sanity done */
965 /* Find the right ship */
966 if (load_unload == UNLOAD) {
967 if (land.lnd_land != lp->lnd_uid)
969 if (land.lnd_ship > -1)
971 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
974 /* Fit unit on ship */
975 if (load_unload == LOAD) {
976 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
978 if (lchr[lp->lnd_type].l_nland)
979 pr("%s doesn't have room for any more land units!\n",
982 pr("%s cannot carry land units!\n", prland(lp));
986 sprintf(buf, "loaded on your %s at %s",
987 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
988 gift(lp->lnd_own, player->cnum, &land, buf);
989 land.lnd_land = lp->lnd_uid;
992 putland(land.lnd_uid, &land);
993 if (!has_supply(&land))
994 pr("WARNING: %s is out of supply!\n", prland(&land));
996 sprintf(buf, "unloaded in your %s at %s",
997 dchr[sectp->sct_type].d_name,
998 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
999 gift(sectp->sct_own, player->cnum, &land, buf);
1001 putland(land.lnd_uid, &land);
1003 pr("%s %s %s at %s.\n",
1005 (load_unload == UNLOAD) ?
1006 "unloaded from" : "loaded onto",
1007 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));