2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, 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-2009
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 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 p = getstarg(player->argp[2], "Ship(s): ", buf);
108 if (!snxtitem(&nbst, EF_SHIP, p, NULL))
111 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
114 while (nxtitem(&nbst, &ship)) {
117 if (!player->owner) {
118 if (load_unload == UNLOAD || !noisy)
120 if (relations_with(ship.shp_own, player->cnum) < FRIENDLY)
124 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
128 if (!player->owner) {
129 if (ship.shp_own != player->cnum)
131 if (!sect_has_dock(§))
133 if (load_unload == LOAD) {
135 pr("You don't own %s \n",
136 xyas(sect.sct_x, sect.sct_y, player->cnum));
140 if (!sect_has_dock(§)) {
142 pr("Sector %s is not a harbor or canal.\n",
143 xyas(sect.sct_x, sect.sct_y, player->cnum));
146 if (load_unload == UNLOAD
148 && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
150 pr("You can't unload into an unfriendly %s\n",
151 dchr[sect.sct_type].d_name);
154 if (sect.sct_effic < 2) {
156 pr("The %s at %s is not 2%% efficient yet.\n",
157 dchr[sect.sct_type].d_name,
158 xyas(sect.sct_x, sect.sct_y, player->cnum));
163 if (ontradingblock(EF_SHIP, &ship)) {
164 pr("You cannot load/unload an item on the trading block!\n");
171 retval = load_plane_ship(§, &ship, noisy, load_unload,
177 retval = load_land_ship(§, &ship, noisy, load_unload,
183 retval = load_comm_ship(§, &ship, ich, load_unload,
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 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 p = getstarg(player->argp[2], "Unit(s): ", buf);
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) {
252 if (load_unload == UNLOAD || !noisy)
254 if (relations_with(land.lnd_own, player->cnum) != ALLIED)
258 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
260 if (!player->owner) {
261 if (land.lnd_own != player->cnum)
263 if (load_unload == LOAD) {
265 pr("Sector %s is not yours.\n",
266 xyas(sect.sct_x, sect.sct_y, player->cnum));
269 if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
270 pr("Sector %s is not yours.\n",
271 xyas(sect.sct_x, sect.sct_y, player->cnum));
277 if (ontradingblock(EF_LAND, &land)) {
278 pr("You cannot load/unload an item on the trading block!\n");
285 retval = load_land_land(§, &land, noisy, load_unload,
291 retval = load_plane_land(§, &land, noisy, load_unload,
297 retval = load_comm_land(§, &land, ich, load_unload,
302 /* load/unload plague */
303 if (sect.sct_pstage == PLG_INFECT
304 && land.lnd_pstage == PLG_HEALTHY)
305 land.lnd_pstage = PLG_EXPOSED;
306 if (land.lnd_pstage == PLG_INFECT
307 && sect.sct_pstage == PLG_HEALTHY)
308 sect.sct_pstage = PLG_EXPOSED;
311 putland(land.lnd_uid, &land);
314 pr("No units affected\n");
316 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
317 load_unload == UNLOAD ? "un" : "");
322 move_amount(int sect_amt, int unit_amt, int unit_max,
323 int load_unload, int amount)
328 move_amt = -amount - unit_amt;
330 move_amt = load_unload == LOAD ? amount : -amount;
331 if (move_amt > unit_max - unit_amt)
332 move_amt = unit_max - unit_amt;
333 if (move_amt < -unit_amt)
334 move_amt = -unit_amt;
335 if (move_amt > sect_amt)
337 if (move_amt < sect_amt - ITEM_MAX)
338 move_amt = sect_amt - ITEM_MAX;
343 load_comm_ok(struct sctstr *sectp, natid unit_own,
344 i_type item, int move_amt)
348 if (move_amt < 0 && !player->god && unit_own != player->cnum)
350 if (move_amt > 0 && !player->god && sectp->sct_own != player->cnum)
352 if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
353 pr("%s civilians refuse to %s at %s!\n",
354 (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
355 ? "Your" : "Foreign",
356 move_amt < 0 ? "disembark" : "board",
357 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
364 gift(natid givee, natid giver, void *ptr, char *mesg)
367 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
368 unit_give_away(ptr, givee, 0);
372 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
374 if (!check_sect_ok(sectp))
376 if (!check_ship_ok(shipp))
382 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
384 if (!check_sect_ok(sectp))
386 if (!check_land_ok(landp))
392 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
393 int load_unload, int *nshipsp)
401 struct mchrstr *mcp = mchr + sp->shp_type;
403 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
405 pr("%s cannot carry planes\n", prship(sp));
408 if (load_unload == LOAD &&
409 shp_nplane(sp, NULL, NULL, NULL)
410 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
412 pr("%s doesn't have room for any more planes\n", prship(sp));
415 sprintf(prompt, "Plane(s) to %s %s? ",
416 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
417 p = getstarg(player->argp[3], prompt, buf);
420 if (!snxtitem(&ni, EF_PLANE, p, NULL))
423 if (!still_ok_ship(sectp, sp))
426 if (noisy && p && *p)
429 while (nxtitem(&ni, &pln)) {
432 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
433 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
434 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
435 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
438 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
441 if (load_unload == LOAD && pln.pln_ship > -1) {
443 pr("%s is already on ship #%d!\n",
444 prplane(&pln), pln.pln_ship);
447 if (load_unload == LOAD && pln.pln_land > -1) {
449 pr("%s is already on land unit #%d!\n",
450 prplane(&pln), pln.pln_land);
453 if (pln.pln_harden != 0) {
455 pr("%s has been hardened and can't be loaded\n",
460 if (load_unload == UNLOAD) {
461 if (pln.pln_ship != sp->shp_uid)
463 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
466 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
468 if (plchr[(int)pln.pln_type].pl_flags & P_K)
470 else if (plchr[(int)pln.pln_type].pl_flags & P_E)
471 p = "extra light planes";
472 else if (plchr[(int)pln.pln_type].pl_flags & P_M)
476 pr("%s cannot carry %s.\n", prship(sp), p);
480 /* Fit plane on ship */
481 if (load_unload == LOAD) {
482 if (!put_plane_on_ship(&pln, sp)) {
484 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
487 sprintf(buf, "loaded on your %s at %s",
488 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
489 gift(sp->shp_own, player->cnum, &pln, buf);
490 putplane(pln.pln_uid, &pln);
493 sprintf(buf, "unloaded in your %s at %s",
494 dchr[sectp->sct_type].d_name,
495 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
496 gift(sectp->sct_own, player->cnum, &pln, buf);
497 putplane(pln.pln_uid, &pln);
499 pr("%s %s %s at %s.\n",
501 (load_unload == UNLOAD) ?
502 "unloaded from" : "loaded onto",
503 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
511 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
512 int load_unload, int *nshipsp)
522 if (load_unload == LOAD) {
524 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
525 (mchr[(int)sp->shp_type].m_nland == 0)) {
526 if (shp_nland(sp) >= 2) {
527 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
530 /* Eh, let 'em load a spy only */
534 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
536 if (mchr[(int)sp->shp_type].m_nland)
537 pr("%s doesn't have room for any more land units!\n",
540 pr("%s cannot carry land units!\n", prship(sp));
545 sprintf(prompt, "Land unit(s) to %s %s? ",
546 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
547 p = getstarg(player->argp[3], prompt, buf);
550 if (!snxtitem(&ni, EF_LAND, p, NULL))
553 if (!still_ok_ship(sectp, sp))
556 if (noisy && p && *p)
559 while (nxtitem(&ni, &land)) {
563 if (load_unload == LOAD) {
564 if (land.lnd_ship > -1) {
566 pr("%s is already on ship #%d!\n",
567 prland(&land), land.lnd_ship);
570 if (land.lnd_land > -1) {
572 pr("%s is already on land #%d!\n",
573 prland(&land), land.lnd_land);
576 if (lnd_first_on_land(&land) >= 0) {
578 pr("%s cannot be loaded since it is carrying units\n",
582 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
584 pr("%s is too heavy to load.\n", prland(&land));
587 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
589 pr("Subs can only carry spy units.\n");
594 /* Unit sanity done */
595 /* Find the right ship */
596 if (load_unload == UNLOAD) {
597 if (land.lnd_ship != sp->shp_uid)
599 if (land.lnd_land > -1)
601 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
604 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
605 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
606 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
608 pr("You can only load light units onto ships,\n");
609 pr("unless the ship is a non-sub supply ship\n");
610 pr("%s not loaded\n", prland(&land));
614 /* Fit unit on ship */
615 if (load_unload == LOAD) {
616 /* We have to check again, since it may have changed */
618 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
619 (mchr[(int)sp->shp_type].m_nland == 0)) {
620 if (shp_nland(sp) >= 2) {
621 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
624 /* Eh, let 'em load a spy only */
628 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
630 if (mchr[(int)sp->shp_type].m_nland)
631 pr("%s doesn't have room for any more land units!\n",
634 pr("%s cannot carry land units!\n", prship(sp));
638 sprintf(buf, "loaded on your %s at %s",
639 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
640 gift(sp->shp_own, player->cnum, &land, buf);
641 land.lnd_ship = sp->shp_uid;
643 putland(land.lnd_uid, &land);
646 * FIXME if this supplies from the sector, the putsect in
647 * load() / lload() duplicates those supplies, causing a
650 if (!lnd_supply_all(&land))
651 pr("WARNING: %s is out of supply!\n", prland(&land));
653 if (!lnd_in_supply(&land))
654 pr("WARNING: %s is out of supply!\n", prland(&land));
657 sprintf(buf, "unloaded in your %s at %s",
658 dchr[sectp->sct_type].d_name,
659 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
661 /* Spies are unloaded quietly, others aren't */
662 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
663 gift(sectp->sct_own, player->cnum, &land, buf);
665 putland(land.lnd_uid, &land);
667 pr("%s %s %s at %s.\n",
669 (load_unload == UNLOAD) ?
670 "unloaded from" : "loaded onto",
671 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
679 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
680 struct ichrstr *ich, int load_unload, int *nshipsp)
682 i_type item = ich->i_uid;
683 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
684 int ship_amt, sect_amt, move_amt;
689 sprintf(prompt, "Number of %s to %s %s at %s? ",
691 (load_unload == UNLOAD) ?
692 "unload from" : "load onto",
693 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
694 p = getstarg(player->argp[3], prompt, buf);
698 if (!still_ok_ship(sectp, sp))
701 ship_amt = sp->shp_item[item];
702 sect_amt = sectp->sct_item[item];
703 move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
704 load_unload, atoi(p));
705 if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
707 if (!want_to_abandon(sectp, item, move_amt, NULL))
709 if (!still_ok_ship(sectp, sp))
711 sectp->sct_item[item] = sect_amt - move_amt;
712 sp->shp_item[item] = ship_amt + move_amt;
715 pr("%d %s loaded onto %s at %s\n",
716 move_amt, ich->i_name,
717 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
718 if (sp->shp_own != player->cnum) {
719 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
720 cname(player->cnum), move_amt, ich->i_name,
721 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
724 pr("%d %s unloaded from %s at %s\n",
725 -move_amt, ich->i_name,
726 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
727 if (sectp->sct_own != player->cnum) {
728 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
729 cname(player->cnum), -move_amt, ich->i_name,
730 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
738 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
739 int load_unload, int *nunitsp)
747 struct lchrstr *lcp = lchr + lp->lnd_type;
749 if (!lcp->l_nxlight) {
751 pr("%s cannot carry extra-light planes.\n", prland(lp));
754 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
756 pr("%s doesn't have room for any more extra-light planes\n",
760 sprintf(prompt, "Plane(s) to %s %s? ",
761 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
762 p = getstarg(player->argp[3], prompt, buf);
765 if (!snxtitem(&ni, EF_PLANE, p, NULL))
768 if (!still_ok_land(sectp, lp))
771 if (noisy && p && *p)
774 while (nxtitem(&ni, &pln)) {
778 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
780 pr("You can only load xlight planes onto units.\n");
784 if (load_unload == LOAD && pln.pln_ship > -1) {
786 pr("%s is already on ship #%d!\n",
787 prplane(&pln), pln.pln_ship);
790 if (load_unload == LOAD && pln.pln_land > -1) {
792 pr("%s is already on unit #%d!\n",
793 prplane(&pln), pln.pln_land);
796 if (pln.pln_harden != 0) {
798 pr("%s has been hardened and can't be loaded\n",
803 /* Plane sanity done */
804 /* Find the right unit */
805 if (load_unload == UNLOAD) {
806 if (pln.pln_land != lp->lnd_uid)
808 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
811 /* Fit plane on unit */
812 if (load_unload == LOAD) {
813 if (!put_plane_on_land(&pln, lp)) {
815 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
818 sprintf(buf, "loaded on %s at %s",
819 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
820 gift(lp->lnd_own, player->cnum, &pln, buf);
821 putplane(pln.pln_uid, &pln);
824 sprintf(buf, "unloaded at your sector at %s",
825 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
826 gift(sectp->sct_own, player->cnum, &pln, buf);
827 putplane(pln.pln_uid, &pln);
829 pr("%s %s %s at %s.\n",
831 (load_unload == UNLOAD) ?
832 "unloaded from" : "loaded onto",
833 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
841 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
842 struct ichrstr *ich, int load_unload, int *nunitsp)
844 i_type item = ich->i_uid;
845 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
846 int land_amt, sect_amt, move_amt;
851 sprintf(prompt, "Number of %s to %s %s at %s? ",
853 (load_unload == UNLOAD) ?
854 "unload from" : "load onto",
855 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
856 p = getstarg(player->argp[3], prompt, buf);
860 if (!still_ok_land(sectp, lp))
863 land_amt = lp->lnd_item[item];
864 sect_amt = sectp->sct_item[item];
865 move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
866 load_unload, atoi(p));
867 if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
869 sectp->sct_item[item] = sect_amt - move_amt;
870 lp->lnd_item[item] = land_amt + move_amt;
872 /* Did we put mils onto this unit? If so, reset the fortification */
873 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)) {
939 if (load_unload == LOAD) {
940 if (land.lnd_ship > -1) {
942 pr("%s is already on ship #%d!\n",
943 prland(&land), land.lnd_ship);
946 if (land.lnd_land > -1) {
948 pr("%s is already on land #%d!\n",
949 prland(&land), land.lnd_land);
952 if (lnd_first_on_land(&land) >= 0) {
954 pr("%s cannot be loaded since it is carrying units\n",
958 if (land.lnd_uid == lp->lnd_uid) {
960 pr("%s can't be loaded onto itself!\n", prland(&land));
963 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
965 pr("%s is too heavy to load.\n", prland(&land));
970 /* Unit sanity done */
971 /* Find the right ship */
972 if (load_unload == UNLOAD) {
973 if (land.lnd_land != lp->lnd_uid)
975 if (land.lnd_ship > -1)
977 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
980 /* Fit unit on ship */
981 if (load_unload == LOAD) {
982 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
984 if (lchr[lp->lnd_type].l_nland)
985 pr("%s doesn't have room for any more land units!\n",
988 pr("%s cannot carry land units!\n", prland(lp));
992 sprintf(buf, "loaded on your %s at %s",
993 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
994 gift(lp->lnd_own, player->cnum, &land, buf);
995 land.lnd_land = lp->lnd_uid;
997 putland(land.lnd_uid, &land);
999 /* FIXME same issue as in load_land_ship() */
1000 if (!lnd_supply_all(&land))
1001 pr("WARNING: %s is out of supply!\n", prland(&land));
1003 if (!lnd_in_supply(&land))
1004 pr("WARNING: %s is out of supply!\n", prland(&land));
1007 sprintf(buf, "unloaded in your %s at %s",
1008 dchr[sectp->sct_type].d_name,
1009 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1010 gift(sectp->sct_own, player->cnum, &land, buf);
1012 putland(land.lnd_uid, &land);
1014 pr("%s %s %s at %s.\n",
1016 (load_unload == UNLOAD) ?
1017 "unloaded from" : "loaded onto",
1018 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));