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)) {
119 if (!player->owner) {
122 if (getrel(getnatp(ship.shp_own), player->cnum) < FRIENDLY)
125 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
127 if (!player->owner && ship.shp_own != player->cnum)
129 if (!player->owner && !sect_has_dock(§))
133 if (!player->owner && load_unload == LOAD) {
135 pr("You don't own %s \n",
136 xyas(ship.shp_x, ship.shp_y, player->cnum));
139 if (!sect_has_dock(§)) {
141 pr("Sector %s is not a harbor or canal.\n",
142 xyas(ship.shp_x, ship.shp_y, player->cnum));
145 if (!player->owner && load_unload == UNLOAD
146 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
148 pr("You can't unload into an unfriendly %s\n",
149 dchr[sect.sct_type].d_name);
152 if (sect.sct_effic < 2) {
154 pr("The %s at %s is not 2%% efficient yet.\n",
155 dchr[sect.sct_type].d_name,
156 xyas(ship.shp_x, ship.shp_y, player->cnum));
161 if (ontradingblock(EF_SHIP, &ship)) {
162 pr("You cannot load/unload an item on the trading block!\n");
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)
250 if (!player->owner && load_unload == UNLOAD)
252 if (!player->owner) {
255 if (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)
259 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
261 if (!player->owner && land.lnd_own != player->cnum)
263 if (!player->owner && load_unload == LOAD) {
265 pr("Sector %s is not yours.\n",
266 xyas(sect.sct_x, sect.sct_y, player->cnum));
269 if (!player->owner &&
270 getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
271 pr("Sector %s is not yours.\n",
272 xyas(land.lnd_x, land.lnd_y, player->cnum));
277 if (ontradingblock(EF_LAND, &land)) {
278 pr("You cannot load/unload an item on the trading block!\n");
287 load_land_land(§, &land, noisy, load_unload,
294 load_plane_land(§, &land, noisy, load_unload,
301 load_comm_land(§, &land, ich, load_unload, &nunits)))
304 /* load/unload plague */
305 if (sect.sct_pstage == PLG_INFECT
306 && land.lnd_pstage == PLG_HEALTHY)
307 land.lnd_pstage = PLG_EXPOSED;
308 if (land.lnd_pstage == PLG_INFECT
309 && sect.sct_pstage == PLG_HEALTHY)
310 sect.sct_pstage = PLG_EXPOSED;
313 putland(land.lnd_uid, &land);
316 pr("No units affected\n");
318 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
319 load_unload == UNLOAD ? "un" : "");
324 move_amount(int sect_amt, int unit_amt, int unit_max,
325 int load_unload, int amount)
330 move_amt = -amount - unit_amt;
332 move_amt = load_unload == LOAD ? amount : -amount;
333 if (move_amt > unit_max - unit_amt)
334 move_amt = unit_max - unit_amt;
335 if (move_amt < -unit_amt)
336 move_amt = -unit_amt;
337 if (move_amt > sect_amt)
339 if (move_amt < sect_amt - ITEM_MAX)
340 move_amt = sect_amt - ITEM_MAX;
345 load_comm_ok(struct sctstr *sectp, natid unit_own,
346 i_type item, int move_amt)
350 if (move_amt < 0 && !player->god && unit_own != player->cnum)
352 if (move_amt > 0 && !player->god && sectp->sct_own != player->cnum)
354 if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
355 pr("%s civilians refuse to %s at %s!\n",
356 (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
357 ? "Your" : "Foreign",
358 move_amt < 0 ? "disembark" : "board",
359 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
366 gift(natid givee, natid giver, void *ptr, char *mesg)
369 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
370 unit_give_away(ptr, givee, 0);
374 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
376 if (!check_sect_ok(sectp))
378 if (!check_ship_ok(shipp))
384 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
386 if (!check_sect_ok(sectp))
388 if (!check_land_ok(landp))
394 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
395 int load_unload, int *nshipsp)
403 struct mchrstr *mcp = mchr + sp->shp_type;
405 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
407 pr("%s cannot carry planes\n", prship(sp));
410 if (load_unload == LOAD &&
411 shp_nplane(sp, NULL, NULL, NULL)
412 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
414 pr("%s doesn't have room for any more planes\n", prship(sp));
417 sprintf(prompt, "Plane(s) to %s %s? ",
418 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
419 p = getstarg(player->argp[3], prompt, buf);
422 if (!snxtitem(&ni, EF_PLANE, p, NULL))
425 if (!still_ok_ship(sectp, sp))
428 if (noisy && p && *p)
431 while (nxtitem(&ni, &pln)) {
434 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
435 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
436 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
437 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
440 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
443 if (load_unload == LOAD && pln.pln_ship > -1) {
445 pr("%s is already on ship #%d!\n",
446 prplane(&pln), pln.pln_ship);
449 if (load_unload == LOAD && pln.pln_land > -1) {
451 pr("%s is already on land unit #%d!\n",
452 prplane(&pln), pln.pln_land);
455 if (pln.pln_harden != 0) {
457 pr("%s has been hardened and can't be loaded\n",
462 /* Plane sanity done */
463 /* Find the right ship */
464 if (load_unload == UNLOAD) {
465 if (pln.pln_ship != sp->shp_uid)
467 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
470 /* ship to (plane or missle) sanity */
471 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
472 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
473 strcpy(buf, "planes");
474 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
475 strcpy(buf, "choppers");
476 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
477 strcpy(buf, "missiles");
478 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
479 strcpy(buf, "extra light planes");
480 } /* else impossible */
482 pr("%s cannot carry %s.\n", prship(sp), buf);
485 /* Fit plane on ship */
486 if (load_unload == LOAD) {
487 if (!put_plane_on_ship(&pln, sp)) {
489 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
492 sprintf(buf, "loaded on your %s at %s",
493 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
494 gift(sp->shp_own, player->cnum, &pln, buf);
495 putplane(pln.pln_uid, &pln);
498 sprintf(buf, "unloaded in your %s at %s",
499 dchr[sectp->sct_type].d_name,
500 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
501 gift(sectp->sct_own, player->cnum, &pln, buf);
502 putplane(pln.pln_uid, &pln);
504 pr("%s %s %s at %s.\n",
506 (load_unload == UNLOAD) ?
507 "unloaded from" : "loaded onto",
508 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
516 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
517 int load_unload, int *nshipsp)
527 if (load_unload == LOAD) {
529 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
530 (mchr[(int)sp->shp_type].m_nland == 0)) {
531 if (shp_nland(sp) >= 2) {
532 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
535 /* Eh, let 'em load a spy only */
539 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
541 if (mchr[(int)sp->shp_type].m_nland)
542 pr("%s doesn't have room for any more land units!\n",
545 pr("%s cannot carry land units!\n", prship(sp));
550 sprintf(prompt, "Land unit(s) to %s %s? ",
551 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
552 p = getstarg(player->argp[3], prompt, buf);
555 if (!snxtitem(&ni, EF_LAND, p, NULL))
558 if (!still_ok_ship(sectp, sp))
561 if (noisy && p && *p)
564 while (nxtitem(&ni, &land)) {
568 if (load_unload == LOAD) {
569 if (land.lnd_ship > -1) {
571 pr("%s is already on ship #%d!\n",
572 prland(&land), land.lnd_ship);
575 if (land.lnd_land > -1) {
577 pr("%s is already on land #%d!\n",
578 prland(&land), land.lnd_land);
581 if (lnd_first_on_land(&land) >= 0) {
583 pr("%s cannot be loaded since it is carrying units\n",
587 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
589 pr("%s is too heavy to load.\n", prland(&land));
592 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
594 pr("Subs can only carry spy units.\n");
599 /* Unit sanity done */
600 /* Find the right ship */
601 if (load_unload == UNLOAD) {
602 if (land.lnd_ship != sp->shp_uid)
604 if (land.lnd_land > -1)
606 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
609 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
610 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
611 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
613 pr("You can only load light units onto ships,\n");
614 pr("unless the ship is a non-sub supply ship\n");
615 pr("%s not loaded\n", prland(&land));
619 /* Fit unit on ship */
620 if (load_unload == LOAD) {
621 /* We have to check again, since it may have changed */
623 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
624 (mchr[(int)sp->shp_type].m_nland == 0)) {
625 if (shp_nland(sp) >= 2) {
626 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
629 /* Eh, let 'em load a spy only */
633 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
635 if (mchr[(int)sp->shp_type].m_nland)
636 pr("%s doesn't have room for any more land units!\n",
639 pr("%s cannot carry land units!\n", prship(sp));
643 sprintf(buf, "loaded on your %s at %s",
644 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
645 gift(sp->shp_own, player->cnum, &land, buf);
646 land.lnd_ship = sp->shp_uid;
650 * FIXME if this supplies from the sector, the putsect in
651 * load() / lload() duplicates those supplies, causing a
656 putland(land.lnd_uid, &land);
657 if (!has_supply(&land))
658 pr("WARNING: %s is out of supply!\n", prland(&land));
660 sprintf(buf, "unloaded in your %s at %s",
661 dchr[sectp->sct_type].d_name,
662 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
664 /* Spies are unloaded quietly, others aren't */
665 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
666 gift(sectp->sct_own, player->cnum, &land, buf);
668 putland(land.lnd_uid, &land);
670 pr("%s %s %s at %s.\n",
672 (load_unload == UNLOAD) ?
673 "unloaded from" : "loaded onto",
674 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
682 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
683 struct ichrstr *ich, int load_unload, int *nshipsp)
685 i_type item = ich->i_uid;
686 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
687 int ship_amt, sect_amt, move_amt;
692 sprintf(prompt, "Number of %s to %s %s at %s? ",
694 (load_unload == UNLOAD) ?
695 "unload from" : "load onto",
696 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
697 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
700 if (!still_ok_ship(sectp, sp))
703 ship_amt = sp->shp_item[item];
704 sect_amt = sectp->sct_item[item];
705 move_amt = move_amount(sect_amt, ship_amt, mcp->m_item[item],
706 load_unload, atoi(p));
707 if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
709 if (!want_to_abandon(sectp, item, move_amt, 0))
711 if (!still_ok_ship(sectp, sp))
713 sectp->sct_item[item] = sect_amt - move_amt;
714 sp->shp_item[item] = ship_amt + move_amt;
717 pr("%d %s loaded onto %s at %s\n",
718 move_amt, ich->i_name,
719 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
720 if (sp->shp_own != player->cnum) {
721 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
722 cname(player->cnum), move_amt, ich->i_name,
723 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
726 pr("%d %s unloaded from %s at %s\n",
727 -move_amt, ich->i_name,
728 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
729 if (sectp->sct_own != player->cnum) {
730 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
731 cname(player->cnum), -move_amt, ich->i_name,
732 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
740 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
741 int load_unload, int *nunitsp)
749 struct lchrstr *lcp = lchr + lp->lnd_type;
751 if (!lcp->l_nxlight) {
753 pr("%s cannot carry extra-light planes.\n", prland(lp));
756 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
758 pr("%s doesn't have room for any more extra-light planes\n",
762 sprintf(prompt, "Plane(s) to %s %s? ",
763 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
764 p = getstarg(player->argp[3], prompt, buf);
767 if (!snxtitem(&ni, EF_PLANE, p, NULL))
770 if (!still_ok_land(sectp, lp))
773 if (noisy && p && *p)
776 while (nxtitem(&ni, &pln)) {
780 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
782 pr("You can only load xlight planes onto units.\n");
786 if (load_unload == LOAD && pln.pln_ship > -1) {
788 pr("%s is already on ship #%d!\n",
789 prplane(&pln), pln.pln_ship);
792 if (load_unload == LOAD && pln.pln_land > -1) {
794 pr("%s is already on unit #%d!\n",
795 prplane(&pln), pln.pln_land);
798 if (pln.pln_harden != 0) {
800 pr("%s has been hardened and can't be loaded\n",
805 /* Plane sanity done */
806 /* Find the right unit */
807 if (load_unload == UNLOAD) {
808 if (pln.pln_land != lp->lnd_uid)
810 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
813 /* Fit plane on unit */
814 if (load_unload == LOAD) {
815 if (!put_plane_on_land(&pln, lp)) {
817 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
820 sprintf(buf, "loaded on %s at %s",
821 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
822 gift(lp->lnd_own, player->cnum, &pln, buf);
823 putplane(pln.pln_uid, &pln);
826 sprintf(buf, "unloaded at your sector at %s",
827 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
828 gift(sectp->sct_own, player->cnum, &pln, buf);
829 putplane(pln.pln_uid, &pln);
831 pr("%s %s %s at %s.\n",
833 (load_unload == UNLOAD) ?
834 "unloaded from" : "loaded onto",
835 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
843 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
844 struct ichrstr *ich, int load_unload, int *nunitsp)
846 i_type item = ich->i_uid;
847 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
848 int land_amt, sect_amt, move_amt;
853 sprintf(prompt, "Number of %s to %s %s at %s? ",
855 (load_unload == UNLOAD) ?
856 "unload from" : "load onto",
857 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
858 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
861 if (!still_ok_land(sectp, lp))
864 land_amt = lp->lnd_item[item];
865 sect_amt = sectp->sct_item[item];
866 move_amt = move_amount(sect_amt, land_amt, lcp->l_item[item],
867 load_unload, atoi(p));
868 if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
870 sectp->sct_item[item] = sect_amt - move_amt;
871 lp->lnd_item[item] = land_amt + move_amt;
873 /* Did we put mils onto this unit? If so, reset the fortification */
874 if (item == I_MILIT && move_amt > 0)
878 pr("%d %s loaded onto %s at %s\n",
879 move_amt, ich->i_name,
880 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
881 if (lp->lnd_own != player->cnum) {
882 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
883 cname(player->cnum), move_amt, ich->i_name,
884 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
887 pr("%d %s unloaded from %s at %s\n",
888 -move_amt, ich->i_name,
889 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
890 if (sectp->sct_own != player->cnum) {
891 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
892 cname(player->cnum), -move_amt, ich->i_name,
893 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
901 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
902 int load_unload, int *nunitsp)
911 if (load_unload == LOAD
912 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
914 if (lchr[lp->lnd_type].l_nland)
915 pr("%s doesn't have room for any more land units!\n",
918 pr("%s cannot carry land units!\n", prland(lp));
922 sprintf(prompt, "Land unit(s) to %s %s? ",
923 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
924 p = getstarg(player->argp[3], prompt, buf);
927 if (!snxtitem(&ni, EF_LAND, p, NULL))
930 if (!still_ok_land(sectp, lp))
933 if (noisy && p && *p)
936 while (nxtitem(&ni, &land)) {
940 if (load_unload == LOAD) {
941 if (land.lnd_ship > -1) {
943 pr("%s is already on ship #%d!\n",
944 prland(&land), land.lnd_ship);
947 if (land.lnd_land > -1) {
949 pr("%s is already on land #%d!\n",
950 prland(&land), land.lnd_land);
953 if (lnd_first_on_land(&land) >= 0) {
955 pr("%s cannot be loaded since it is carrying units\n",
959 if (land.lnd_uid == lp->lnd_uid) {
961 pr("%s can't be loaded onto itself!\n", prland(&land));
964 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
966 pr("%s is too heavy to load.\n", prland(&land));
971 /* Unit sanity done */
972 /* Find the right ship */
973 if (load_unload == UNLOAD) {
974 if (land.lnd_land != lp->lnd_uid)
976 if (land.lnd_ship > -1)
978 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
981 /* Fit unit on ship */
982 if (load_unload == LOAD) {
983 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
985 if (lchr[lp->lnd_type].l_nland)
986 pr("%s doesn't have room for any more land units!\n",
989 pr("%s cannot carry land units!\n", prland(lp));
993 sprintf(buf, "loaded on your %s at %s",
994 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
995 gift(lp->lnd_own, player->cnum, &land, buf);
996 land.lnd_land = lp->lnd_uid;
999 /* FIXME same issue as in load_land_ship() */
1000 resupply_all(&land);
1002 putland(land.lnd_uid, &land);
1003 if (!has_supply(&land))
1004 pr("WARNING: %s is out of supply!\n", prland(&land));
1006 sprintf(buf, "unloaded in your %s at %s",
1007 dchr[sectp->sct_type].d_name,
1008 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1009 gift(sectp->sct_own, player->cnum, &land, buf);
1011 putland(land.lnd_uid, &land);
1013 pr("%s %s %s at %s.\n",
1015 (load_unload == UNLOAD) ?
1016 "unloaded from" : "loaded onto",
1017 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));