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 move_amount(int sect_amt, int unit_amt, int unit_max,
326 int load_unload, int amount)
331 move_amt = -amount - unit_amt;
333 move_amt = load_unload == LOAD ? amount : -amount;
334 if (move_amt > unit_max - unit_amt)
335 move_amt = unit_max - unit_amt;
336 if (move_amt < -unit_amt)
337 move_amt = -unit_amt;
338 if (move_amt > sect_amt)
340 if (move_amt < sect_amt - ITEM_MAX)
341 move_amt = sect_amt - ITEM_MAX;
346 load_comm_ok(struct sctstr *sectp, natid unit_own,
347 i_type item, int move_amt)
351 if (move_amt < 0 && !player->god && unit_own != player->cnum)
353 if (move_amt > 0 && !player->god && sectp->sct_own != player->cnum)
355 if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
356 pr("%s civilians refuse to %s at %s!\n",
357 (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
358 ? "Your" : "Foreign",
359 move_amt < 0 ? "disembark" : "board",
360 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
367 gift(natid givee, natid giver, void *ptr, char *mesg)
370 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
371 unit_give_away(ptr, givee, 0);
375 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
377 if (!check_sect_ok(sectp))
379 if (!check_ship_ok(shipp))
385 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
387 if (!check_sect_ok(sectp))
389 if (!check_land_ok(landp))
395 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
396 int load_unload, int *nshipsp)
404 struct mchrstr *mcp = mchr + sp->shp_type;
406 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
408 pr("%s cannot carry planes\n", prship(sp));
411 if (load_unload == LOAD &&
412 shp_nplane(sp, NULL, NULL, NULL)
413 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
415 pr("%s doesn't have room for any more planes\n", prship(sp));
418 sprintf(prompt, "Plane(s) to %s %s? ",
419 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
420 p = getstarg(player->argp[3], prompt, buf);
423 if (!snxtitem(&ni, EF_PLANE, p, NULL))
426 if (!still_ok_ship(sectp, sp))
429 if (noisy && p && *p)
432 while (nxtitem(&ni, &pln)) {
433 if (pln.pln_own != player->cnum)
435 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
436 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
437 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
438 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
441 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
444 if (load_unload == LOAD && pln.pln_ship > -1) {
446 pr("%s is already on ship #%d!\n",
447 prplane(&pln), pln.pln_ship);
450 if (load_unload == LOAD && pln.pln_land > -1) {
452 pr("%s is already on land unit #%d!\n",
453 prplane(&pln), pln.pln_land);
456 if (pln.pln_harden != 0) {
458 pr("%s has been hardened and can't be loaded\n",
463 /* Plane sanity done */
464 /* Find the right ship */
465 if (load_unload == UNLOAD) {
466 if (pln.pln_ship != sp->shp_uid)
468 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
471 /* ship to (plane or missle) sanity */
472 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
473 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
474 strcpy(buf, "planes");
475 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
476 strcpy(buf, "choppers");
477 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
478 strcpy(buf, "missiles");
479 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
480 strcpy(buf, "extra light planes");
481 } /* else impossible */
483 pr("%s cannot carry %s.\n", prship(sp), buf);
486 /* Fit plane on ship */
487 if (load_unload == LOAD) {
488 if (!put_plane_on_ship(&pln, sp)) {
490 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
493 sprintf(buf, "loaded on your %s at %s",
494 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
495 gift(sp->shp_own, player->cnum, &pln, buf);
496 putplane(pln.pln_uid, &pln);
499 sprintf(buf, "unloaded in your %s at %s",
500 dchr[sectp->sct_type].d_name,
501 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
502 gift(sectp->sct_own, player->cnum, &pln, buf);
503 putplane(pln.pln_uid, &pln);
505 pr("%s %s %s at %s.\n",
507 (load_unload == UNLOAD) ?
508 "unloaded from" : "loaded onto",
509 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
517 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
518 int load_unload, int *nshipsp)
528 if (load_unload == LOAD) {
530 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
531 (mchr[(int)sp->shp_type].m_nland == 0)) {
532 if (shp_nland(sp) >= 2) {
533 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
536 /* Eh, let 'em load a spy only */
540 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
542 if (mchr[(int)sp->shp_type].m_nland)
543 pr("%s doesn't have room for any more land units!\n",
546 pr("%s cannot carry land units!\n", prship(sp));
551 sprintf(prompt, "Land unit(s) to %s %s? ",
552 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
553 p = getstarg(player->argp[3], prompt, buf);
556 if (!snxtitem(&ni, EF_LAND, p, NULL))
559 if (!still_ok_ship(sectp, sp))
562 if (noisy && p && *p)
565 while (nxtitem(&ni, &land)) {
566 if (land.lnd_own != player->cnum)
569 if (load_unload == LOAD) {
570 if (land.lnd_ship > -1) {
572 pr("%s is already on ship #%d!\n",
573 prland(&land), land.lnd_ship);
576 if (land.lnd_land > -1) {
578 pr("%s is already on land #%d!\n",
579 prland(&land), land.lnd_land);
582 if (lnd_first_on_land(&land) >= 0) {
584 pr("%s cannot be loaded since it is carrying units\n",
588 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
590 pr("%s is too heavy to load.\n", prland(&land));
593 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
595 pr("Subs can only carry spy units.\n");
600 /* Unit sanity done */
601 /* Find the right ship */
602 if (load_unload == UNLOAD) {
603 if (land.lnd_ship != sp->shp_uid)
605 if (land.lnd_land > -1)
607 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
610 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
611 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
612 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
614 pr("You can only load light units onto ships,\n");
615 pr("unless the ship is a non-sub supply ship\n");
616 pr("%s not loaded\n", prland(&land));
620 /* Fit unit on ship */
621 if (load_unload == LOAD) {
622 /* We have to check again, since it may have changed */
624 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
625 (mchr[(int)sp->shp_type].m_nland == 0)) {
626 if (shp_nland(sp) >= 2) {
627 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
630 /* Eh, let 'em load a spy only */
634 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
636 if (mchr[(int)sp->shp_type].m_nland)
637 pr("%s doesn't have room for any more land units!\n",
640 pr("%s cannot carry land units!\n", prship(sp));
644 sprintf(buf, "loaded on your %s at %s",
645 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
646 gift(sp->shp_own, player->cnum, &land, buf);
647 land.lnd_ship = sp->shp_uid;
651 * FIXME if this supplies from the sector, the putsect in
652 * load() / lload() duplicates those supplies, causing a
657 putland(land.lnd_uid, &land);
658 if (!has_supply(&land))
659 pr("WARNING: %s is out of supply!\n", prland(&land));
661 sprintf(buf, "unloaded in your %s at %s",
662 dchr[sectp->sct_type].d_name,
663 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
665 /* Spies are unloaded quietly, others aren't */
666 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
667 gift(sectp->sct_own, player->cnum, &land, buf);
669 putland(land.lnd_uid, &land);
671 pr("%s %s %s at %s.\n",
673 (load_unload == UNLOAD) ?
674 "unloaded from" : "loaded onto",
675 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
683 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
684 struct ichrstr *ich, int load_unload, int *nshipsp)
686 i_type item = ich->i_uid;
687 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
688 int ship_amt, sect_amt, move_amt;
693 sprintf(prompt, "Number of %s to %s %s at %s? ",
695 (load_unload == UNLOAD) ?
696 "unload from" : "load onto",
697 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
698 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
701 if (!still_ok_ship(sectp, sp))
704 ship_amt = sp->shp_item[item];
705 sect_amt = sectp->sct_item[item];
706 move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
707 load_unload, atoi(p));
708 if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
710 if (!want_to_abandon(sectp, item, move_amt, 0))
712 if (!still_ok_ship(sectp, sp))
714 sectp->sct_item[item] = sect_amt - move_amt;
715 sp->shp_item[item] = ship_amt + move_amt;
718 pr("%d %s loaded onto %s at %s\n",
719 move_amt, ich->i_name,
720 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
721 if (sp->shp_own != player->cnum) {
722 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
723 cname(player->cnum), move_amt, ich->i_name,
724 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
727 pr("%d %s unloaded from %s at %s\n",
728 -move_amt, ich->i_name,
729 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
730 if (sectp->sct_own != player->cnum) {
731 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
732 cname(player->cnum), -move_amt, ich->i_name,
733 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
741 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
742 int load_unload, int *nunitsp)
750 struct lchrstr *lcp = lchr + lp->lnd_type;
752 if (!lcp->l_nxlight) {
754 pr("%s cannot carry extra-light planes.\n", prland(lp));
757 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
759 pr("%s doesn't have room for any more extra-light planes\n",
763 sprintf(prompt, "Plane(s) to %s %s? ",
764 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
765 p = getstarg(player->argp[3], prompt, buf);
768 if (!snxtitem(&ni, EF_PLANE, p, NULL))
771 if (!still_ok_land(sectp, lp))
774 if (noisy && p && *p)
777 while (nxtitem(&ni, &pln)) {
778 if (pln.pln_own != player->cnum)
781 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
783 pr("You can only load xlight planes onto units.\n");
787 if (load_unload == LOAD && pln.pln_ship > -1) {
789 pr("%s is already on ship #%d!\n",
790 prplane(&pln), pln.pln_ship);
793 if (load_unload == LOAD && pln.pln_land > -1) {
795 pr("%s is already on unit #%d!\n",
796 prplane(&pln), pln.pln_land);
799 if (pln.pln_harden != 0) {
801 pr("%s has been hardened and can't be loaded\n",
806 /* Plane sanity done */
807 /* Find the right unit */
808 if (load_unload == UNLOAD) {
809 if (pln.pln_land != lp->lnd_uid)
811 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
814 /* Fit plane on unit */
815 if (load_unload == LOAD) {
816 if (!put_plane_on_land(&pln, lp)) {
818 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
821 sprintf(buf, "loaded on %s at %s",
822 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
823 gift(lp->lnd_own, player->cnum, &pln, buf);
824 putplane(pln.pln_uid, &pln);
827 sprintf(buf, "unloaded at your sector at %s",
828 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
829 gift(sectp->sct_own, player->cnum, &pln, buf);
830 putplane(pln.pln_uid, &pln);
832 pr("%s %s %s at %s.\n",
834 (load_unload == UNLOAD) ?
835 "unloaded from" : "loaded onto",
836 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
844 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
845 struct ichrstr *ich, int load_unload, int *nunitsp)
847 i_type item = ich->i_uid;
848 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
849 int land_amt, sect_amt, move_amt;
854 sprintf(prompt, "Number of %s to %s %s at %s? ",
856 (load_unload == UNLOAD) ?
857 "unload from" : "load onto",
858 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
859 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
862 if (!still_ok_land(sectp, lp))
865 land_amt = lp->lnd_item[item];
866 sect_amt = sectp->sct_item[item];
867 move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
868 load_unload, atoi(p));
869 if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
871 sectp->sct_item[item] = sect_amt - move_amt;
872 lp->lnd_item[item] = land_amt + move_amt;
874 /* Did we put mils onto this unit? If so, reset the fortification */
875 if (item == I_MILIT && move_amt > 0)
879 pr("%d %s loaded onto %s at %s\n",
880 move_amt, ich->i_name,
881 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
882 if (lp->lnd_own != player->cnum) {
883 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
884 cname(player->cnum), move_amt, ich->i_name,
885 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
888 pr("%d %s unloaded from %s at %s\n",
889 -move_amt, ich->i_name,
890 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
891 if (sectp->sct_own != player->cnum) {
892 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
893 cname(player->cnum), -move_amt, ich->i_name,
894 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
902 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
903 int load_unload, int *nunitsp)
912 if (load_unload == LOAD
913 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
915 if (lchr[lp->lnd_type].l_nland)
916 pr("%s doesn't have room for any more land units!\n",
919 pr("%s cannot carry land units!\n", prland(lp));
923 sprintf(prompt, "Land unit(s) to %s %s? ",
924 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
925 p = getstarg(player->argp[3], prompt, buf);
928 if (!snxtitem(&ni, EF_LAND, p, NULL))
931 if (!still_ok_land(sectp, lp))
934 if (noisy && p && *p)
937 while (nxtitem(&ni, &land)) {
939 if (land.lnd_own != player->cnum)
942 if (load_unload == LOAD) {
943 if (land.lnd_ship > -1) {
945 pr("%s is already on ship #%d!\n",
946 prland(&land), land.lnd_ship);
949 if (land.lnd_land > -1) {
951 pr("%s is already on land #%d!\n",
952 prland(&land), land.lnd_land);
955 if (lnd_first_on_land(&land) >= 0) {
957 pr("%s cannot be loaded since it is carrying units\n",
961 if (land.lnd_uid == lp->lnd_uid) {
963 pr("%s can't be loaded onto itself!\n", prland(&land));
966 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
968 pr("%s is too heavy to load.\n", prland(&land));
973 /* Unit sanity done */
974 /* Find the right ship */
975 if (load_unload == UNLOAD) {
976 if (land.lnd_land != lp->lnd_uid)
978 if (land.lnd_ship > -1)
980 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
983 /* Fit unit on ship */
984 if (load_unload == LOAD) {
985 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
987 if (lchr[lp->lnd_type].l_nland)
988 pr("%s doesn't have room for any more land units!\n",
991 pr("%s cannot carry land units!\n", prland(lp));
995 sprintf(buf, "loaded on your %s at %s",
996 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
997 gift(lp->lnd_own, player->cnum, &land, buf);
998 land.lnd_land = lp->lnd_uid;
1001 /* FIXME same issue as in load_land_ship() */
1002 resupply_all(&land);
1004 putland(land.lnd_uid, &land);
1005 if (!has_supply(&land))
1006 pr("WARNING: %s is out of supply!\n", prland(&land));
1008 sprintf(buf, "unloaded in your %s at %s",
1009 dchr[sectp->sct_type].d_name,
1010 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1011 gift(sectp->sct_own, player->cnum, &land, buf);
1013 putland(land.lnd_uid, &land);
1015 pr("%s %s %s at %s.\n",
1017 (load_unload == UNLOAD) ?
1018 "unloaded from" : "loaded onto",
1019 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));