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 gift(natid givee, natid giver, void *ptr, char *mesg)
328 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
329 unit_give_away(ptr, givee, 0);
333 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
335 if (!check_sect_ok(sectp))
337 if (!check_ship_ok(shipp))
343 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
345 if (!check_sect_ok(sectp))
347 if (!check_land_ok(landp))
353 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
354 int load_unload, int *nshipsp)
362 struct mchrstr *mcp = mchr + sp->shp_type;
364 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
366 pr("%s cannot carry planes\n", prship(sp));
369 if (load_unload == LOAD &&
370 shp_nplane(sp, NULL, NULL, NULL)
371 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
373 pr("%s doesn't have room for any more planes\n", prship(sp));
376 sprintf(prompt, "Plane(s) to %s %s? ",
377 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
378 p = getstarg(player->argp[3], prompt, buf);
381 if (!snxtitem(&ni, EF_PLANE, p, NULL))
384 if (!still_ok_ship(sectp, sp))
387 if (noisy && p && *p)
390 while (nxtitem(&ni, &pln)) {
391 if (pln.pln_own != player->cnum)
393 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
394 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
395 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
396 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
399 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
402 if (load_unload == LOAD && pln.pln_ship > -1) {
404 pr("%s is already on ship #%d!\n",
405 prplane(&pln), pln.pln_ship);
408 if (load_unload == LOAD && pln.pln_land > -1) {
410 pr("%s is already on land unit #%d!\n",
411 prplane(&pln), pln.pln_land);
414 if (pln.pln_harden != 0) {
416 pr("%s has been hardened and can't be loaded\n",
421 /* Plane sanity done */
422 /* Find the right ship */
423 if (load_unload == UNLOAD) {
424 if (pln.pln_ship != sp->shp_uid)
426 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
429 /* ship to (plane or missle) sanity */
430 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
431 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
432 strcpy(buf, "planes");
433 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
434 strcpy(buf, "choppers");
435 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
436 strcpy(buf, "missiles");
437 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
438 strcpy(buf, "extra light planes");
439 } /* else impossible */
441 pr("%s cannot carry %s.\n", prship(sp), buf);
444 /* Fit plane on ship */
445 if (load_unload == LOAD) {
446 if (!put_plane_on_ship(&pln, sp)) {
448 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
451 sprintf(buf, "loaded on your %s at %s",
452 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
453 gift(sp->shp_own, player->cnum, &pln, buf);
454 putplane(pln.pln_uid, &pln);
457 sprintf(buf, "unloaded in your %s at %s",
458 dchr[sectp->sct_type].d_name,
459 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
460 gift(sectp->sct_own, player->cnum, &pln, buf);
461 putplane(pln.pln_uid, &pln);
463 pr("%s %s %s at %s.\n",
465 (load_unload == UNLOAD) ?
466 "unloaded from" : "loaded onto",
467 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
475 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
476 int load_unload, int *nshipsp)
486 if (load_unload == LOAD) {
488 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
489 (mchr[(int)sp->shp_type].m_nland == 0)) {
490 if (shp_nland(sp) >= 2) {
491 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
494 /* Eh, let 'em load a spy only */
498 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
500 if (mchr[(int)sp->shp_type].m_nland)
501 pr("%s doesn't have room for any more land units!\n",
504 pr("%s cannot carry land units!\n", prship(sp));
509 sprintf(prompt, "Land unit(s) to %s %s? ",
510 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
511 p = getstarg(player->argp[3], prompt, buf);
514 if (!snxtitem(&ni, EF_LAND, p, NULL))
517 if (!still_ok_ship(sectp, sp))
520 if (noisy && p && *p)
523 while (nxtitem(&ni, &land)) {
524 if (land.lnd_own != player->cnum)
527 if (load_unload == LOAD) {
528 if (land.lnd_ship > -1) {
530 pr("%s is already on ship #%d!\n",
531 prland(&land), land.lnd_ship);
534 if (land.lnd_land > -1) {
536 pr("%s is already on land #%d!\n",
537 prland(&land), land.lnd_land);
540 if (lnd_first_on_land(&land) >= 0) {
542 pr("%s cannot be loaded since it is carrying units\n",
546 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
548 pr("%s is too heavy to load.\n", prland(&land));
551 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
553 pr("Subs can only carry spy units.\n");
558 /* Unit sanity done */
559 /* Find the right ship */
560 if (load_unload == UNLOAD) {
561 if (land.lnd_ship != sp->shp_uid)
563 if (land.lnd_land > -1)
565 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
568 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
569 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
570 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
572 pr("You can only load light units onto ships,\n");
573 pr("unless the ship is a non-sub supply ship\n");
574 pr("%s not loaded\n", prland(&land));
578 /* Fit unit on ship */
579 if (load_unload == LOAD) {
580 /* We have to check again, since it may have changed */
582 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
583 (mchr[(int)sp->shp_type].m_nland == 0)) {
584 if (shp_nland(sp) >= 2) {
585 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
588 /* Eh, let 'em load a spy only */
592 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
594 if (mchr[(int)sp->shp_type].m_nland)
595 pr("%s doesn't have room for any more land units!\n",
598 pr("%s cannot carry land units!\n", prship(sp));
602 sprintf(buf, "loaded on your %s at %s",
603 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
604 gift(sp->shp_own, player->cnum, &land, buf);
605 land.lnd_ship = sp->shp_uid;
609 * FIXME if this supplies from the sector, the putsect in
610 * load() / lload() duplicates those supplies, causing a
615 putland(land.lnd_uid, &land);
616 if (!has_supply(&land))
617 pr("WARNING: %s is out of supply!\n", prland(&land));
619 sprintf(buf, "unloaded in your %s at %s",
620 dchr[sectp->sct_type].d_name,
621 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
623 /* Spies are unloaded quietly, others aren't */
624 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
625 gift(sectp->sct_own, player->cnum, &land, buf);
627 putland(land.lnd_uid, &land);
629 pr("%s %s %s at %s.\n",
631 (load_unload == UNLOAD) ?
632 "unloaded from" : "loaded onto",
633 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
641 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
642 struct ichrstr *ich, int load_unload, int *nshipsp)
644 i_type item = ich->i_uid;
645 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
646 int ship_amt, ship_max, sect_amt, move_amt;
652 sprintf(prompt, "Number of %s to %s %s at %s? ",
654 (load_unload == UNLOAD) ?
655 "unload from" : "load onto",
656 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
657 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
660 if (!still_ok_ship(sectp, sp))
663 ship_amt = sp->shp_item[item];
664 ship_max = mcp->m_item[item];
665 sect_amt = sectp->sct_item[item];
668 move_amt = -amount - ship_amt;
670 move_amt = load_unload == LOAD ? amount : -amount;
671 if (move_amt > ship_max - ship_amt)
672 move_amt = ship_max - ship_amt;
673 if (move_amt < -ship_amt)
674 move_amt = -ship_amt;
675 if (move_amt > sect_amt)
677 if (move_amt < sect_amt - ITEM_MAX)
678 move_amt = sect_amt - ITEM_MAX;
681 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
682 pr("%s civilians refuse to %s at %s!\n",
683 move_amt < 0 ? "Your" : "Foreign",
684 move_amt < 0 ? "disembark" : "board",
685 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
689 if (!want_to_abandon(sectp, item, move_amt, 0))
691 if (!still_ok_ship(sectp, sp))
693 sectp->sct_item[item] = sect_amt - move_amt;
694 sp->shp_item[item] = ship_amt + move_amt;
696 pr("%d %s loaded onto %s at %s\n",
697 move_amt, ich->i_name,
698 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
699 if (sp->shp_own != player->cnum) {
700 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
701 cname(player->cnum), move_amt, ich->i_name,
702 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
705 pr("%d %s unloaded from %s at %s\n",
706 -move_amt, ich->i_name,
707 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
708 if (sectp->sct_own != player->cnum) {
709 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
710 cname(player->cnum), -move_amt, ich->i_name,
711 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
719 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
720 int load_unload, int *nunitsp)
728 struct lchrstr *lcp = lchr + lp->lnd_type;
730 if (!lcp->l_nxlight) {
732 pr("%s cannot carry extra-light planes.\n", prland(lp));
735 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
737 pr("%s doesn't have room for any more extra-light planes\n",
741 sprintf(prompt, "Plane(s) to %s %s? ",
742 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
743 p = getstarg(player->argp[3], prompt, buf);
746 if (!snxtitem(&ni, EF_PLANE, p, NULL))
749 if (!still_ok_land(sectp, lp))
752 if (noisy && p && *p)
755 while (nxtitem(&ni, &pln)) {
756 if (pln.pln_own != player->cnum)
759 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
761 pr("You can only load xlight planes onto units.\n");
765 if (load_unload == LOAD && pln.pln_ship > -1) {
767 pr("%s is already on ship #%d!\n",
768 prplane(&pln), pln.pln_ship);
771 if (load_unload == LOAD && pln.pln_land > -1) {
773 pr("%s is already on unit #%d!\n",
774 prplane(&pln), pln.pln_land);
777 if (pln.pln_harden != 0) {
779 pr("%s has been hardened and can't be loaded\n",
784 /* Plane sanity done */
785 /* Find the right unit */
786 if (load_unload == UNLOAD) {
787 if (pln.pln_land != lp->lnd_uid)
789 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
792 /* Fit plane on unit */
793 if (load_unload == LOAD) {
794 if (!put_plane_on_land(&pln, lp)) {
796 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
799 sprintf(buf, "loaded on %s at %s",
800 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
801 gift(lp->lnd_own, player->cnum, &pln, buf);
802 putplane(pln.pln_uid, &pln);
805 sprintf(buf, "unloaded at your sector at %s",
806 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
807 gift(sectp->sct_own, player->cnum, &pln, buf);
808 putplane(pln.pln_uid, &pln);
810 pr("%s %s %s at %s.\n",
812 (load_unload == UNLOAD) ?
813 "unloaded from" : "loaded onto",
814 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
822 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
823 struct ichrstr *ich, int load_unload, int *nunitsp)
825 i_type item = ich->i_uid;
826 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
827 int land_amt, land_max, sect_amt, move_amt;
833 sprintf(prompt, "Number of %s to %s %s at %s? ",
835 (load_unload == UNLOAD) ?
836 "unload from" : "load onto",
837 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
838 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
841 if (!still_ok_land(sectp, lp))
844 land_amt = lp->lnd_item[item];
845 land_max = lcp->l_item[item];
846 sect_amt = sectp->sct_item[item];
849 move_amt = -amount - land_amt;
851 move_amt = load_unload == LOAD ? amount : -amount;
852 if (move_amt > land_max - land_amt)
853 move_amt = land_max - land_amt;
854 if (move_amt < -land_amt)
855 move_amt = -land_amt;
856 if (move_amt > sect_amt)
858 if (move_amt < sect_amt - ITEM_MAX)
859 move_amt = sect_amt - ITEM_MAX;
862 if (sectp->sct_own != player->cnum && move_amt > 0) {
863 pr("Sector %s is not yours.\n",
864 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
867 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
868 pr("%s civilians refuse to %s at %s!\n",
869 move_amt < 0 ? "Your" : "Foreign",
870 move_amt < 0 ? "disembark" : "board",
871 xyas(sectp->sct_x, sectp->sct_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));