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
50 * The values 1 and -1 are important below, don't change them.
55 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
56 int noisy, int load_unload, int *nshipsp);
57 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
58 int noisy, int load_unload, int *nshipsp);
59 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
60 struct ichrstr *ich, int load_unload,
62 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
63 int noisy, int load_unload, int *nunitsp);
64 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
65 int noisy, int load_unload, int *nunitsp);
66 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
67 struct ichrstr *ich, int load_unload,
76 struct nstr_item nbst;
85 if (!(p = getstarg(player->argp[1],
86 "What commodity (or 'plane' or 'land')? ", buf))
90 if (!strncmp(p, "plane", 5))
92 else if (!strncmp(p, "land", 4))
94 else if (NULL != (ich = item_by_name(p)))
97 pr("Can't load '%s'\n", p);
101 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
106 if (!snxtitem(&nbst, EF_SHIP, p, NULL))
109 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
112 while (nxtitem(&nbst, &ship)) {
115 if (!player->owner && (load_unload == UNLOAD)) {
119 if (ontradingblock(EF_SHIP, &ship)) {
120 pr("You cannot load/unload an item on the trading block!\n");
125 if (ship.shp_own != player->cnum) {
128 if (getrel(getnatp(player->cnum), ship.shp_own) < FRIENDLY)
131 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
133 if ((sect.sct_own != player->cnum) &&
134 (ship.shp_own != player->cnum))
136 if (!player->owner &&
137 !sect_has_dock(§))
141 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
143 pr("You don't own %s \n",
144 xyas(ship.shp_x, ship.shp_y, player->cnum));
147 if (!sect_has_dock(§)) {
149 pr("Sector %s is not a harbor or canal.\n",
150 xyas(ship.shp_x, ship.shp_y, player->cnum));
153 if (sect.sct_own != player->cnum && load_unload == UNLOAD
154 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
156 pr("You can't unload into an unfriendly %s\n",
157 dchr[sect.sct_type].d_name);
160 if (sect.sct_effic < 2) {
162 pr("The %s at %s is not 2%% efficient yet.\n",
163 dchr[sect.sct_type].d_name,
164 xyas(ship.shp_x, ship.shp_y, player->cnum));
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)
251 if (player->cnum != land.lnd_own &&
252 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
255 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
258 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
261 if (ontradingblock(EF_LAND, &land)) {
262 pr("You cannot load/unload an item on the trading block!\n");
267 if (sect.sct_own != player->cnum &&
268 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
269 pr("Sector %s is not yours.\n",
270 xyas(land.lnd_x, land.lnd_y, player->cnum));
277 load_land_land(§, &land, noisy, load_unload,
284 load_plane_land(§, &land, noisy, load_unload,
291 load_comm_land(§, &land, ich, load_unload, &nunits)))
294 /* load/unload plague */
295 if (sect.sct_pstage == PLG_INFECT
296 && land.lnd_pstage == PLG_HEALTHY)
297 land.lnd_pstage = PLG_EXPOSED;
298 if (land.lnd_pstage == PLG_INFECT
299 && sect.sct_pstage == PLG_HEALTHY)
300 sect.sct_pstage = PLG_EXPOSED;
303 putland(land.lnd_uid, &land);
306 pr("No units affected\n");
308 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
309 load_unload == UNLOAD ? "un" : "");
314 gift(natid givee, natid giver, void *ptr, char *mesg)
317 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
318 unit_give_away(ptr, givee, 0);
322 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
324 if (!check_sect_ok(sectp))
326 if (!check_ship_ok(shipp))
332 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
334 if (!check_sect_ok(sectp))
336 if (!check_land_ok(landp))
342 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
343 int load_unload, int *nshipsp)
351 struct mchrstr *mcp = mchr + sp->shp_type;
353 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
355 pr("%s cannot carry planes\n", prship(sp));
358 if (load_unload == LOAD &&
359 shp_nplane(sp, NULL, NULL, NULL)
360 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
362 pr("%s doesn't have room for any more planes\n", prship(sp));
365 sprintf(prompt, "Plane(s) to %s %s? ",
366 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
367 p = getstarg(player->argp[3], prompt, buf);
370 if (!snxtitem(&ni, EF_PLANE, p, NULL))
373 if (!still_ok_ship(sectp, sp))
376 if (noisy && p && *p)
379 while (nxtitem(&ni, &pln)) {
380 if (pln.pln_own != player->cnum)
382 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
383 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
384 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
385 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
388 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
391 if (load_unload == LOAD && pln.pln_ship > -1) {
393 pr("%s is already on ship #%d!\n",
394 prplane(&pln), pln.pln_ship);
397 if (load_unload == LOAD && pln.pln_land > -1) {
399 pr("%s is already on land unit #%d!\n",
400 prplane(&pln), pln.pln_land);
403 if (pln.pln_harden != 0) {
405 pr("%s has been hardened and can't be loaded\n",
410 /* Plane sanity done */
411 /* Find the right ship */
412 if (load_unload == UNLOAD) {
413 if (pln.pln_ship != sp->shp_uid)
415 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
418 /* ship to (plane or missle) sanity */
419 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
420 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
421 strcpy(buf, "planes");
422 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
423 strcpy(buf, "choppers");
424 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
425 strcpy(buf, "missiles");
426 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
427 strcpy(buf, "extra light planes");
428 } /* else impossible */
430 pr("%s cannot carry %s.\n", prship(sp), buf);
433 /* Fit plane on ship */
434 if (load_unload == LOAD) {
435 if (!put_plane_on_ship(&pln, sp)) {
437 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
440 sprintf(buf, "loaded on your %s at %s",
441 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
442 gift(sp->shp_own, player->cnum, &pln, buf);
443 putplane(pln.pln_uid, &pln);
446 sprintf(buf, "unloaded in your %s at %s",
447 dchr[sectp->sct_type].d_name,
448 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
449 gift(sectp->sct_own, player->cnum, &pln, buf);
450 putplane(pln.pln_uid, &pln);
452 pr("%s %s %s at %s.\n",
454 (load_unload == UNLOAD) ?
455 "unloaded from" : "loaded onto",
456 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
464 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
465 int load_unload, int *nshipsp)
475 if (load_unload == LOAD) {
477 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
478 (mchr[(int)sp->shp_type].m_nland == 0)) {
479 if (shp_nland(sp) >= 2) {
480 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
483 /* Eh, let 'em load a spy only */
487 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
489 if (mchr[(int)sp->shp_type].m_nland)
490 pr("%s doesn't have room for any more land units!\n",
493 pr("%s cannot carry land units!\n", prship(sp));
498 sprintf(prompt, "Land unit(s) to %s %s? ",
499 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
500 p = getstarg(player->argp[3], prompt, buf);
503 if (!snxtitem(&ni, EF_LAND, p, NULL))
506 if (!still_ok_ship(sectp, sp))
509 if (noisy && p && *p)
512 while (nxtitem(&ni, &land)) {
513 if (land.lnd_own != player->cnum)
516 if (load_unload == LOAD) {
517 if (land.lnd_ship > -1) {
519 pr("%s is already on ship #%d!\n",
520 prland(&land), land.lnd_ship);
523 if (land.lnd_land > -1) {
525 pr("%s is already on land #%d!\n",
526 prland(&land), land.lnd_land);
529 if (lnd_first_on_land(&land) >= 0) {
531 pr("%s cannot be loaded since it is carrying units\n",
535 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
537 pr("%s is too heavy to load.\n", prland(&land));
540 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
542 pr("Subs can only carry spy units.\n");
547 /* Unit sanity done */
548 /* Find the right ship */
549 if (load_unload == UNLOAD) {
550 if (land.lnd_ship != sp->shp_uid)
552 if (land.lnd_land > -1)
554 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
557 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
558 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
559 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
561 pr("You can only load light units onto ships,\n");
562 pr("unless the ship is a non-sub supply ship\n");
563 pr("%s not loaded\n", prland(&land));
567 /* Fit unit on ship */
568 if (load_unload == LOAD) {
569 /* We have to check again, since it may have changed */
571 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
572 (mchr[(int)sp->shp_type].m_nland == 0)) {
573 if (shp_nland(sp) >= 2) {
574 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
577 /* Eh, let 'em load a spy only */
581 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
583 if (mchr[(int)sp->shp_type].m_nland)
584 pr("%s doesn't have room for any more land units!\n",
587 pr("%s cannot carry land units!\n", prship(sp));
591 sprintf(buf, "loaded on your %s at %s",
592 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
593 gift(sp->shp_own, player->cnum, &land, buf);
594 land.lnd_ship = sp->shp_uid;
597 putland(land.lnd_uid, &land);
598 if (!has_supply(&land))
599 pr("WARNING: %s is out of supply!\n", prland(&land));
601 sprintf(buf, "unloaded in your %s at %s",
602 dchr[sectp->sct_type].d_name,
603 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
605 /* Spies are unloaded quietly, others aren't */
606 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
607 gift(sectp->sct_own, player->cnum, &land, buf);
609 putland(land.lnd_uid, &land);
611 pr("%s %s %s at %s.\n",
613 (load_unload == UNLOAD) ?
614 "unloaded from" : "loaded onto",
615 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
623 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
624 struct ichrstr *ich, int load_unload, int *nshipsp)
626 i_type item = ich->i_uid;
627 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
628 int ship_amt, ship_max, sect_amt, move_amt;
634 sprintf(prompt, "Number of %s to %s %s at %s? ",
636 (load_unload == UNLOAD) ?
637 "unload from" : "load onto",
638 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
639 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
642 if (!still_ok_ship(sectp, sp))
645 ship_amt = sp->shp_item[item];
646 ship_max = mcp->m_item[item];
647 sect_amt = sectp->sct_item[item];
650 move_amt = -amount - ship_amt;
652 move_amt = load_unload == LOAD ? amount : -amount;
653 if (move_amt > ship_max - ship_amt)
654 move_amt = ship_max - ship_amt;
655 if (move_amt < -ship_amt)
656 move_amt = -ship_amt;
657 if (move_amt > sect_amt)
659 if (move_amt < sect_amt - ITEM_MAX)
660 move_amt = sect_amt - ITEM_MAX;
663 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
664 pr("%s civilians refuse to %s at %s!\n",
665 move_amt < 0 ? "Your" : "Foreign",
666 move_amt < 0 ? "disembark" : "board",
667 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
671 if (!want_to_abandon(sectp, item, move_amt, 0))
673 if (!still_ok_ship(sectp, sp))
675 sectp->sct_item[item] = sect_amt - move_amt;
676 sp->shp_item[item] = ship_amt + move_amt;
678 pr("%d %s loaded onto %s at %s\n",
679 move_amt, ich->i_name,
680 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
681 if (sp->shp_own != player->cnum) {
682 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
683 cname(player->cnum), move_amt, ich->i_name,
684 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
687 pr("%d %s unloaded from %s at %s\n",
688 -move_amt, ich->i_name,
689 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
690 if (sectp->sct_own != player->cnum) {
691 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
692 cname(player->cnum), -move_amt, ich->i_name,
693 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
701 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
702 int load_unload, int *nunitsp)
710 struct lchrstr *lcp = lchr + lp->lnd_type;
712 if (!lcp->l_nxlight) {
714 pr("%s cannot carry extra-light planes.\n", prland(lp));
717 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
719 pr("%s doesn't have room for any more extra-light planes\n",
723 sprintf(prompt, "Plane(s) to %s %s? ",
724 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
725 p = getstarg(player->argp[3], prompt, buf);
728 if (!snxtitem(&ni, EF_PLANE, p, NULL))
731 if (!still_ok_land(sectp, lp))
734 if (noisy && p && *p)
737 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
738 pr("Sector %s is not yours.\n",
739 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
743 while (nxtitem(&ni, &pln)) {
744 if (pln.pln_own != player->cnum)
747 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
749 pr("You can only load xlight planes onto units.\n");
753 if (load_unload == LOAD && pln.pln_ship > -1) {
755 pr("%s is already on ship #%d!\n",
756 prplane(&pln), pln.pln_ship);
759 if (load_unload == LOAD && pln.pln_land > -1) {
761 pr("%s is already on unit #%d!\n",
762 prplane(&pln), pln.pln_land);
765 if (pln.pln_harden != 0) {
767 pr("%s has been hardened and can't be loaded\n",
772 /* Plane sanity done */
773 /* Find the right unit */
774 if (load_unload == UNLOAD) {
775 if (pln.pln_land != lp->lnd_uid)
777 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
780 /* Fit plane on unit */
781 if (load_unload == LOAD) {
782 if (!put_plane_on_land(&pln, lp)) {
784 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
787 sprintf(buf, "loaded on %s at %s",
788 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
789 gift(lp->lnd_own, player->cnum, &pln, buf);
790 putplane(pln.pln_uid, &pln);
793 sprintf(buf, "unloaded at your sector at %s",
794 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
795 gift(sectp->sct_own, player->cnum, &pln, buf);
796 putplane(pln.pln_uid, &pln);
798 pr("%s %s %s at %s.\n",
800 (load_unload == UNLOAD) ?
801 "unloaded from" : "loaded onto",
802 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
810 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
811 struct ichrstr *ich, int load_unload, int *nunitsp)
813 i_type item = ich->i_uid;
814 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
815 int land_amt, land_max, sect_amt, move_amt;
821 sprintf(prompt, "Number of %s to %s %s at %s? ",
823 (load_unload == UNLOAD) ?
824 "unload from" : "load onto",
825 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
826 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
829 if (!still_ok_land(sectp, lp))
832 land_amt = lp->lnd_item[item];
833 land_max = lcp->l_item[item];
834 sect_amt = sectp->sct_item[item];
837 move_amt = -amount - land_amt;
839 move_amt = load_unload == LOAD ? amount : -amount;
840 if (move_amt > land_max - land_amt)
841 move_amt = land_max - land_amt;
842 if (move_amt < -land_amt)
843 move_amt = -land_amt;
844 if (move_amt > sect_amt)
846 if (move_amt < sect_amt - ITEM_MAX)
847 move_amt = sect_amt - ITEM_MAX;
850 if (sectp->sct_own != player->cnum && move_amt > 0) {
851 pr("Sector %s is not yours.\n",
852 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
855 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
856 pr("%s civilians refuse to %s at %s!\n",
857 move_amt < 0 ? "Your" : "Foreign",
858 move_amt < 0 ? "disembark" : "board",
859 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
862 sectp->sct_item[item] = sect_amt - move_amt;
863 lp->lnd_item[item] = land_amt + move_amt;
865 /* Did we put mils onto this unit? If so, reset the fortification */
866 if (item == I_MILIT && move_amt > 0)
869 pr("%d %s loaded onto %s at %s\n",
870 move_amt, ich->i_name,
871 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
872 if (lp->lnd_own != player->cnum) {
873 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
874 cname(player->cnum), move_amt, ich->i_name,
875 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
878 pr("%d %s unloaded from %s at %s\n",
879 -move_amt, ich->i_name,
880 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
881 if (sectp->sct_own != player->cnum) {
882 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
883 cname(player->cnum), -move_amt, ich->i_name,
884 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
892 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
893 int load_unload, int *nunitsp)
902 if (load_unload == LOAD
903 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
905 if (lchr[lp->lnd_type].l_nland)
906 pr("%s doesn't have room for any more land units!\n",
909 pr("%s cannot carry land units!\n", prland(lp));
913 sprintf(prompt, "Land unit(s) to %s %s? ",
914 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
915 p = getstarg(player->argp[3], prompt, buf);
918 if (!snxtitem(&ni, EF_LAND, p, NULL))
921 if (!still_ok_land(sectp, lp))
924 if (noisy && p && *p)
927 while (nxtitem(&ni, &land)) {
929 if (land.lnd_own != player->cnum)
932 if (load_unload == LOAD) {
933 if (land.lnd_ship > -1) {
935 pr("%s is already on ship #%d!\n",
936 prland(&land), land.lnd_ship);
939 if (land.lnd_land > -1) {
941 pr("%s is already on land #%d!\n",
942 prland(&land), land.lnd_land);
945 if (lnd_first_on_land(&land) >= 0) {
947 pr("%s cannot be loaded since it is carrying units\n",
951 if (land.lnd_uid == lp->lnd_uid) {
953 pr("%s can't be loaded onto itself!\n", prland(&land));
956 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
958 pr("%s is too heavy to load.\n", prland(&land));
963 /* Unit sanity done */
964 /* Find the right ship */
965 if (load_unload == UNLOAD) {
966 if (land.lnd_land != lp->lnd_uid)
968 if (land.lnd_ship > -1)
970 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
973 /* Fit unit on ship */
974 if (load_unload == LOAD) {
975 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
977 if (lchr[lp->lnd_type].l_nland)
978 pr("%s doesn't have room for any more land units!\n",
981 pr("%s cannot carry land units!\n", prland(lp));
985 sprintf(buf, "loaded on your %s at %s",
986 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
987 gift(lp->lnd_own, player->cnum, &land, buf);
988 land.lnd_land = lp->lnd_uid;
991 putland(land.lnd_uid, &land);
992 if (!has_supply(&land))
993 pr("WARNING: %s is out of supply!\n", prland(&land));
995 sprintf(buf, "unloaded in your %s at %s",
996 dchr[sectp->sct_type].d_name,
997 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
998 gift(sectp->sct_own, player->cnum, &land, buf);
1000 putland(land.lnd_uid, &land);
1002 pr("%s %s %s at %s.\n",
1004 (load_unload == UNLOAD) ?
1005 "unloaded from" : "loaded onto",
1006 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));