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 load_comm_ok(struct sctstr *sectp, natid unit_own,
326 i_type item, int move_amt)
330 if (sectp->sct_oldown != unit_own && item == I_CIVIL) {
331 pr("%s civilians refuse to %s at %s!\n",
332 (move_amt < 0 ? unit_own : sectp->sct_oldown) == player->cnum
333 ? "Your" : "Foreign",
334 move_amt < 0 ? "disembark" : "board",
335 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
342 gift(natid givee, natid giver, void *ptr, char *mesg)
345 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(ptr), mesg);
346 unit_give_away(ptr, givee, 0);
350 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
352 if (!check_sect_ok(sectp))
354 if (!check_ship_ok(shipp))
360 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
362 if (!check_sect_ok(sectp))
364 if (!check_land_ok(landp))
370 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
371 int load_unload, int *nshipsp)
379 struct mchrstr *mcp = mchr + sp->shp_type;
381 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
383 pr("%s cannot carry planes\n", prship(sp));
386 if (load_unload == LOAD &&
387 shp_nplane(sp, NULL, NULL, NULL)
388 >= mcp->m_nchoppers + mcp->m_nxlight + mcp->m_nplanes) {
390 pr("%s doesn't have room for any more planes\n", prship(sp));
393 sprintf(prompt, "Plane(s) to %s %s? ",
394 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
395 p = getstarg(player->argp[3], prompt, buf);
398 if (!snxtitem(&ni, EF_PLANE, p, NULL))
401 if (!still_ok_ship(sectp, sp))
404 if (noisy && p && *p)
407 while (nxtitem(&ni, &pln)) {
408 if (pln.pln_own != player->cnum)
410 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
411 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
412 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
413 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
416 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
419 if (load_unload == LOAD && pln.pln_ship > -1) {
421 pr("%s is already on ship #%d!\n",
422 prplane(&pln), pln.pln_ship);
425 if (load_unload == LOAD && pln.pln_land > -1) {
427 pr("%s is already on land unit #%d!\n",
428 prplane(&pln), pln.pln_land);
431 if (pln.pln_harden != 0) {
433 pr("%s has been hardened and can't be loaded\n",
438 /* Plane sanity done */
439 /* Find the right ship */
440 if (load_unload == UNLOAD) {
441 if (pln.pln_ship != sp->shp_uid)
443 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
446 /* ship to (plane or missle) sanity */
447 if (!could_be_on_ship(&pln, sp, 0, 0, 0, 0)) {
448 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
449 strcpy(buf, "planes");
450 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
451 strcpy(buf, "choppers");
452 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
453 strcpy(buf, "missiles");
454 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
455 strcpy(buf, "extra light planes");
456 } /* else impossible */
458 pr("%s cannot carry %s.\n", prship(sp), buf);
461 /* Fit plane on ship */
462 if (load_unload == LOAD) {
463 if (!put_plane_on_ship(&pln, sp)) {
465 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
468 sprintf(buf, "loaded on your %s at %s",
469 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
470 gift(sp->shp_own, player->cnum, &pln, buf);
471 putplane(pln.pln_uid, &pln);
474 sprintf(buf, "unloaded in your %s at %s",
475 dchr[sectp->sct_type].d_name,
476 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
477 gift(sectp->sct_own, player->cnum, &pln, buf);
478 putplane(pln.pln_uid, &pln);
480 pr("%s %s %s at %s.\n",
482 (load_unload == UNLOAD) ?
483 "unloaded from" : "loaded onto",
484 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
492 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
493 int load_unload, int *nshipsp)
503 if (load_unload == LOAD) {
505 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
506 (mchr[(int)sp->shp_type].m_nland == 0)) {
507 if (shp_nland(sp) >= 2) {
508 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
511 /* Eh, let 'em load a spy only */
515 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
517 if (mchr[(int)sp->shp_type].m_nland)
518 pr("%s doesn't have room for any more land units!\n",
521 pr("%s cannot carry land units!\n", prship(sp));
526 sprintf(prompt, "Land unit(s) to %s %s? ",
527 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
528 p = getstarg(player->argp[3], prompt, buf);
531 if (!snxtitem(&ni, EF_LAND, p, NULL))
534 if (!still_ok_ship(sectp, sp))
537 if (noisy && p && *p)
540 while (nxtitem(&ni, &land)) {
541 if (land.lnd_own != player->cnum)
544 if (load_unload == LOAD) {
545 if (land.lnd_ship > -1) {
547 pr("%s is already on ship #%d!\n",
548 prland(&land), land.lnd_ship);
551 if (land.lnd_land > -1) {
553 pr("%s is already on land #%d!\n",
554 prland(&land), land.lnd_land);
557 if (lnd_first_on_land(&land) >= 0) {
559 pr("%s cannot be loaded since it is carrying units\n",
563 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
565 pr("%s is too heavy to load.\n", prland(&land));
568 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
570 pr("Subs can only carry spy units.\n");
575 /* Unit sanity done */
576 /* Find the right ship */
577 if (load_unload == UNLOAD) {
578 if (land.lnd_ship != sp->shp_uid)
580 if (land.lnd_land > -1)
582 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
585 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
586 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
587 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
589 pr("You can only load light units onto ships,\n");
590 pr("unless the ship is a non-sub supply ship\n");
591 pr("%s not loaded\n", prland(&land));
595 /* Fit unit on ship */
596 if (load_unload == LOAD) {
597 /* We have to check again, since it may have changed */
599 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
600 (mchr[(int)sp->shp_type].m_nland == 0)) {
601 if (shp_nland(sp) >= 2) {
602 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
605 /* Eh, let 'em load a spy only */
609 if (!load_spy && shp_nland(sp) >= mchr[sp->shp_type].m_nland) {
611 if (mchr[(int)sp->shp_type].m_nland)
612 pr("%s doesn't have room for any more land units!\n",
615 pr("%s cannot carry land units!\n", prship(sp));
619 sprintf(buf, "loaded on your %s at %s",
620 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
621 gift(sp->shp_own, player->cnum, &land, buf);
622 land.lnd_ship = sp->shp_uid;
626 * FIXME if this supplies from the sector, the putsect in
627 * load() / lload() duplicates those supplies, causing a
632 putland(land.lnd_uid, &land);
633 if (!has_supply(&land))
634 pr("WARNING: %s is out of supply!\n", prland(&land));
636 sprintf(buf, "unloaded in your %s at %s",
637 dchr[sectp->sct_type].d_name,
638 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
640 /* Spies are unloaded quietly, others aren't */
641 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
642 gift(sectp->sct_own, player->cnum, &land, buf);
644 putland(land.lnd_uid, &land);
646 pr("%s %s %s at %s.\n",
648 (load_unload == UNLOAD) ?
649 "unloaded from" : "loaded onto",
650 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
658 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
659 struct ichrstr *ich, int load_unload, int *nshipsp)
661 i_type item = ich->i_uid;
662 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
663 int ship_amt, ship_max, sect_amt, move_amt;
669 sprintf(prompt, "Number of %s to %s %s at %s? ",
671 (load_unload == UNLOAD) ?
672 "unload from" : "load onto",
673 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
674 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
677 if (!still_ok_ship(sectp, sp))
680 ship_amt = sp->shp_item[item];
681 ship_max = mcp->m_item[item];
682 sect_amt = sectp->sct_item[item];
685 move_amt = -amount - ship_amt;
687 move_amt = load_unload == LOAD ? amount : -amount;
688 if (move_amt > ship_max - ship_amt)
689 move_amt = ship_max - ship_amt;
690 if (move_amt < -ship_amt)
691 move_amt = -ship_amt;
692 if (move_amt > sect_amt)
694 if (move_amt < sect_amt - ITEM_MAX)
695 move_amt = sect_amt - ITEM_MAX;
696 if (!load_comm_ok(sectp, sp->shp_own, item, move_amt))
698 if (!want_to_abandon(sectp, item, move_amt, 0))
700 if (!still_ok_ship(sectp, sp))
702 sectp->sct_item[item] = sect_amt - move_amt;
703 sp->shp_item[item] = ship_amt + move_amt;
705 pr("%d %s loaded onto %s at %s\n",
706 move_amt, ich->i_name,
707 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
708 if (sp->shp_own != player->cnum) {
709 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
710 cname(player->cnum), move_amt, ich->i_name,
711 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
714 pr("%d %s unloaded from %s at %s\n",
715 -move_amt, ich->i_name,
716 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
717 if (sectp->sct_own != player->cnum) {
718 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
719 cname(player->cnum), -move_amt, ich->i_name,
720 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
728 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
729 int load_unload, int *nunitsp)
737 struct lchrstr *lcp = lchr + lp->lnd_type;
739 if (!lcp->l_nxlight) {
741 pr("%s cannot carry extra-light planes.\n", prland(lp));
744 if (load_unload == LOAD && lnd_nxlight(lp) >= lcp->l_nxlight) {
746 pr("%s doesn't have room for any more extra-light planes\n",
750 sprintf(prompt, "Plane(s) to %s %s? ",
751 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
752 p = getstarg(player->argp[3], prompt, buf);
755 if (!snxtitem(&ni, EF_PLANE, p, NULL))
758 if (!still_ok_land(sectp, lp))
761 if (noisy && p && *p)
764 while (nxtitem(&ni, &pln)) {
765 if (pln.pln_own != player->cnum)
768 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
770 pr("You can only load xlight planes onto units.\n");
774 if (load_unload == LOAD && pln.pln_ship > -1) {
776 pr("%s is already on ship #%d!\n",
777 prplane(&pln), pln.pln_ship);
780 if (load_unload == LOAD && pln.pln_land > -1) {
782 pr("%s is already on unit #%d!\n",
783 prplane(&pln), pln.pln_land);
786 if (pln.pln_harden != 0) {
788 pr("%s has been hardened and can't be loaded\n",
793 /* Plane sanity done */
794 /* Find the right unit */
795 if (load_unload == UNLOAD) {
796 if (pln.pln_land != lp->lnd_uid)
798 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
801 /* Fit plane on unit */
802 if (load_unload == LOAD) {
803 if (!put_plane_on_land(&pln, lp)) {
805 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
808 sprintf(buf, "loaded on %s at %s",
809 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
810 gift(lp->lnd_own, player->cnum, &pln, buf);
811 putplane(pln.pln_uid, &pln);
814 sprintf(buf, "unloaded at your sector at %s",
815 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
816 gift(sectp->sct_own, player->cnum, &pln, buf);
817 putplane(pln.pln_uid, &pln);
819 pr("%s %s %s at %s.\n",
821 (load_unload == UNLOAD) ?
822 "unloaded from" : "loaded onto",
823 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
831 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
832 struct ichrstr *ich, int load_unload, int *nunitsp)
834 i_type item = ich->i_uid;
835 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
836 int land_amt, land_max, sect_amt, move_amt;
842 sprintf(prompt, "Number of %s to %s %s at %s? ",
844 (load_unload == UNLOAD) ?
845 "unload from" : "load onto",
846 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
847 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
850 if (!still_ok_land(sectp, lp))
853 land_amt = lp->lnd_item[item];
854 land_max = lcp->l_item[item];
855 sect_amt = sectp->sct_item[item];
858 move_amt = -amount - land_amt;
860 move_amt = load_unload == LOAD ? amount : -amount;
861 if (move_amt > land_max - land_amt)
862 move_amt = land_max - land_amt;
863 if (move_amt < -land_amt)
864 move_amt = -land_amt;
865 if (move_amt > sect_amt)
867 if (move_amt < sect_amt - ITEM_MAX)
868 move_amt = sect_amt - ITEM_MAX;
869 if (!load_comm_ok(sectp, lp->lnd_own, item, move_amt))
871 if (sectp->sct_own != player->cnum && move_amt > 0) {
872 pr("Sector %s is not yours.\n",
873 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
876 sectp->sct_item[item] = sect_amt - move_amt;
877 lp->lnd_item[item] = land_amt + move_amt;
879 /* Did we put mils onto this unit? If so, reset the fortification */
880 if (item == I_MILIT && move_amt > 0)
883 pr("%d %s loaded onto %s at %s\n",
884 move_amt, ich->i_name,
885 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
886 if (lp->lnd_own != player->cnum) {
887 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
888 cname(player->cnum), move_amt, ich->i_name,
889 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
892 pr("%d %s unloaded from %s at %s\n",
893 -move_amt, ich->i_name,
894 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
895 if (sectp->sct_own != player->cnum) {
896 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
897 cname(player->cnum), -move_amt, ich->i_name,
898 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
906 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
907 int load_unload, int *nunitsp)
916 if (load_unload == LOAD
917 && lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
919 if (lchr[lp->lnd_type].l_nland)
920 pr("%s doesn't have room for any more land units!\n",
923 pr("%s cannot carry land units!\n", prland(lp));
927 sprintf(prompt, "Land unit(s) to %s %s? ",
928 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
929 p = getstarg(player->argp[3], prompt, buf);
932 if (!snxtitem(&ni, EF_LAND, p, NULL))
935 if (!still_ok_land(sectp, lp))
938 if (noisy && p && *p)
941 while (nxtitem(&ni, &land)) {
943 if (land.lnd_own != player->cnum)
946 if (load_unload == LOAD) {
947 if (land.lnd_ship > -1) {
949 pr("%s is already on ship #%d!\n",
950 prland(&land), land.lnd_ship);
953 if (land.lnd_land > -1) {
955 pr("%s is already on land #%d!\n",
956 prland(&land), land.lnd_land);
959 if (lnd_first_on_land(&land) >= 0) {
961 pr("%s cannot be loaded since it is carrying units\n",
965 if (land.lnd_uid == lp->lnd_uid) {
967 pr("%s can't be loaded onto itself!\n", prland(&land));
970 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
972 pr("%s is too heavy to load.\n", prland(&land));
977 /* Unit sanity done */
978 /* Find the right ship */
979 if (load_unload == UNLOAD) {
980 if (land.lnd_land != lp->lnd_uid)
982 if (land.lnd_ship > -1)
984 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
987 /* Fit unit on ship */
988 if (load_unload == LOAD) {
989 if (lnd_nland(lp) >= lchr[lp->lnd_type].l_nland) {
991 if (lchr[lp->lnd_type].l_nland)
992 pr("%s doesn't have room for any more land units!\n",
995 pr("%s cannot carry land units!\n", prland(lp));
999 sprintf(buf, "loaded on your %s at %s",
1000 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1001 gift(lp->lnd_own, player->cnum, &land, buf);
1002 land.lnd_land = lp->lnd_uid;
1003 land.lnd_harden = 0;
1005 /* FIXME same issue as in load_land_ship() */
1006 resupply_all(&land);
1008 putland(land.lnd_uid, &land);
1009 if (!has_supply(&land))
1010 pr("WARNING: %s is out of supply!\n", prland(&land));
1012 sprintf(buf, "unloaded in your %s at %s",
1013 dchr[sectp->sct_type].d_name,
1014 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1015 gift(sectp->sct_own, player->cnum, &land, buf);
1017 putland(land.lnd_uid, &land);
1019 pr("%s %s %s at %s.\n",
1021 (load_unload == UNLOAD) ?
1022 "unloaded from" : "loaded onto",
1023 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));