2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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
49 * The values 1 and -1 are important below, don't change them.
54 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
55 int noisy, int load_unload, int *nshipsp);
56 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
57 int noisy, int load_unload, int *nshipsp);
58 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
59 struct ichrstr *ich, int load_unload,
61 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
62 int noisy, int load_unload, int *nunitsp);
63 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
64 int noisy, int load_unload, int *nunitsp);
65 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
66 struct ichrstr *ich, int load_unload,
75 struct nstr_item nbst;
84 if (!(p = getstarg(player->argp[1],
85 "What commodity (or 'plane' or 'land')? ", buf))
89 if (!strncmp(p, "plane", 5))
91 else if (!strncmp(p, "land", 4))
93 else if (NULL != (ich = item_by_name(p)))
96 pr("Can't load '%s'\n", p);
100 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
105 if (!snxtitem(&nbst, EF_SHIP, p))
108 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
111 while (nxtitem(&nbst, &ship)) {
114 if (!player->owner && (load_unload == UNLOAD)) {
118 if (ontradingblock(EF_SHIP, &ship)) {
119 pr("You cannot load/unload an item on the trading block!\n");
124 if (ship.shp_own != player->cnum) {
127 if (getrel(getnatp(player->cnum), ship.shp_own) < FRIENDLY)
130 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
132 if ((sect.sct_own != player->cnum) &&
133 (ship.shp_own != player->cnum))
135 if (!player->owner &&
136 !sect_has_dock(§))
140 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
142 pr("You don't own %s \n",
143 xyas(ship.shp_x, ship.shp_y, player->cnum));
146 if (!sect_has_dock(§)) {
148 pr("Sector %s is not a harbor%s%s.\n",
149 xyas(ship.shp_x, ship.shp_y, player->cnum),
150 dchr[SCT_CAPIT].d_nav == NAV_CANAL ? " or a " : "",
151 dchr[SCT_CAPIT].d_nav == NAV_CANAL ?
152 dchr[SCT_CAPIT].d_name : "");
155 if (sect.sct_own != player->cnum && load_unload == UNLOAD
156 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
158 pr("You can't unload into an unfriendly %s\n",
159 dchr[sect.sct_type].d_name);
162 if (sect.sct_effic < 2) {
164 pr("The %s at %s is not 2%% efficient yet.\n",
165 dchr[sect.sct_type].d_name,
166 xyas(ship.shp_x, ship.shp_y, player->cnum));
173 load_plane_ship(§, &ship, noisy, load_unload,
180 load_land_ship(§, &ship, noisy, load_unload,
187 load_comm_ship(§, &ship, ich, load_unload, &nships)))
190 /* load/unload plague */
191 if (sect.sct_pstage == PLG_INFECT
192 && ship.shp_pstage == PLG_HEALTHY)
193 ship.shp_pstage = PLG_EXPOSED;
194 if (ship.shp_pstage == PLG_INFECT
195 && sect.sct_pstage == PLG_HEALTHY)
196 sect.sct_pstage = PLG_EXPOSED;
198 putship(ship.shp_uid, &ship);
201 pr("No ships affected\n");
203 pr("%d ship%s %sloaded\n", nships, splur(nships),
204 load_unload == UNLOAD ? "un" : "");
214 struct nstr_item nbst;
223 if (!(p = getstarg(player->argp[1],
224 "What commodity (or 'plane' or 'land')? ", buf))
227 if (!strncmp(p, "plane", 5))
229 else if (!strncmp(p, "land", 4))
231 else if (NULL != (ich = item_by_name(p)))
234 pr("Can't load '%s'\n", p);
238 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
243 if (!snxtitem(&nbst, EF_LAND, p))
246 load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
249 while (nxtitem(&nbst, &land)) {
250 if (land.lnd_own == 0)
253 if (player->cnum != land.lnd_own &&
254 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
257 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
260 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
263 if (ontradingblock(EF_LAND, &land)) {
264 pr("You cannot load/unload an item on the trading block!\n");
269 if (sect.sct_own != player->cnum &&
270 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
271 pr("Sector %s is not yours.\n",
272 xyas(land.lnd_x, land.lnd_y, player->cnum));
279 load_land_land(§, &land, noisy, load_unload,
286 load_plane_land(§, &land, noisy, load_unload,
293 load_comm_land(§, &land, ich, load_unload, &nunits)))
296 /* load/unload plague */
297 if (sect.sct_pstage == PLG_INFECT
298 && land.lnd_pstage == PLG_HEALTHY)
299 land.lnd_pstage = PLG_EXPOSED;
300 if (land.lnd_pstage == PLG_INFECT
301 && sect.sct_pstage == PLG_HEALTHY)
302 sect.sct_pstage = PLG_EXPOSED;
305 putland(land.lnd_uid, &land);
308 pr("No units affected\n");
310 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
311 load_unload == UNLOAD ? "un" : "");
316 gift(natid givee, natid giver, void *ptr, char *mesg)
318 struct empobj *gen = ptr;
321 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(gen), mesg);
323 makelost(gen->ef_type, gen->own, gen->uid, gen->x, gen->y);
325 makenotlost(gen->ef_type, gen->own, gen->uid, gen->x, gen->y);
329 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
331 if (!check_sect_ok(sectp))
333 if (!check_ship_ok(shipp))
339 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
341 if (!check_sect_ok(sectp))
343 if (!check_land_ok(landp))
349 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
350 int load_unload, int *nshipsp)
358 struct mchrstr *mcp = mchr + sp->shp_type;
360 if (!(mcp->m_flags & (M_CHOPPER | M_XLIGHT | M_FLY | M_MSL))) {
362 pr("%s cannot carry planes\n", prship(sp));
366 if (load_unload == LOAD &&
367 sp->shp_nchoppers >= mcp->m_nchoppers &&
368 sp->shp_nxlight >= mcp->m_nxlight &&
369 sp->shp_nplane >= mcp->m_nplanes) {
371 pr("%s doesn't have room for any more planes\n", prship(sp));
374 sprintf(prompt, "Plane(s) to %s %s? ",
375 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
376 if (!snxtitem(&ni, EF_PLANE,
377 p = getstarg(player->argp[3], prompt, buf)))
380 if (!still_ok_ship(sectp, sp))
384 noisy &= isdigit(*p);
386 while (nxtitem(&ni, &pln)) {
387 if (pln.pln_own != player->cnum)
389 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
390 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
391 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
392 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
395 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
398 if (load_unload == LOAD && pln.pln_ship > -1) {
400 pr("%s is already on ship #%d!\n",
401 prplane(&pln), pln.pln_ship);
404 if (load_unload == LOAD && pln.pln_land > -1) {
406 pr("%s is already on land unit #%d!\n",
407 prplane(&pln), pln.pln_land);
411 /* Plane sanity done */
412 /* Find the right ship */
413 if (load_unload == UNLOAD) {
414 if (pln.pln_ship != sp->shp_uid)
416 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
419 /* ship to (plane or missle) sanity */
420 if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) {
421 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
422 strcpy(buf, "planes");
423 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
424 strcpy(buf, "choppers");
425 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
426 strcpy(buf, "missiles");
427 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
428 strcpy(buf, "extra light planes");
429 } /* else impossible */
431 pr("%s cannot carry %s.\n", prship(sp), buf);
434 /* Fit plane on ship */
435 if (load_unload == LOAD) {
436 if (!put_plane_on_ship(&pln, sp)) {
438 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
441 sprintf(buf, "loaded on your %s at %s",
442 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
443 gift(sp->shp_own, player->cnum, &pln, buf);
445 putplane(pln.pln_uid, &pln);
447 if (!take_plane_off_ship(&pln, sp)) {
448 pr("Unable to take plane off ship!\n");
449 logerror("load: plane %d could not be taken off ship %d\n",
450 pln.pln_uid, sp->shp_uid);
453 sprintf(buf, "unloaded in your %s at %s",
454 dchr[sectp->sct_type].d_name,
455 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
456 gift(sectp->sct_own, player->cnum, &pln, buf);
457 putplane(pln.pln_uid, &pln);
459 pr("%s %s %s at %s.\n",
461 (load_unload == UNLOAD) ?
462 "unloaded from" : "loaded onto",
463 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
471 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
472 int load_unload, int *nshipsp)
474 struct nstr_item pni, ni;
484 if (load_unload == LOAD) {
486 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
487 (mchr[(int)sp->shp_type].m_nland == 0)) {
488 if (sp->shp_nland >= 2) {
489 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
492 /* Eh, let 'em load a spy only */
497 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
499 if (mchr[(int)sp->shp_type].m_nland)
500 pr("%s doesn't have room for any more land units!\n",
503 pr("%s cannot carry land units!\n", prship(sp));
508 sprintf(prompt, "Land unit(s) to %s %s? ",
509 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
510 if (!snxtitem(&ni, EF_LAND,
511 p = getstarg(player->argp[3], prompt, buf)))
514 if (!still_ok_ship(sectp, sp))
518 noisy &= isdigit(*p);
520 while (nxtitem(&ni, &land)) {
521 if (land.lnd_own != player->cnum)
524 if (load_unload == LOAD) {
525 if (land.lnd_ship > -1) {
527 pr("%s is already on ship #%d!\n",
528 prland(&land), land.lnd_ship);
531 if (land.lnd_land > -1) {
533 pr("%s is already on land #%d!\n",
534 prland(&land), land.lnd_land);
537 lnd_count_units(&land);
538 if (land.lnd_nland > 0) {
540 pr("%s cannot be loaded since it is carrying units\n",
544 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
546 pr("%s is too heavy to load.\n", prland(&land));
549 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
551 pr("Subs can only carry spy units.\n");
556 /* Unit sanity done */
557 /* Find the right ship */
558 if (load_unload == UNLOAD) {
559 if (land.lnd_ship != sp->shp_uid)
561 if (land.lnd_land > -1)
563 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
566 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
567 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
568 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
570 pr("You can only load light units onto ships,\n");
571 pr("unless the ship is a non-sub supply ship\n");
572 pr("%s not loaded\n", prland(&land));
576 /* Fit unit on ship */
577 if (load_unload == LOAD) {
579 /* We have to check again, since it may have changed */
581 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
582 (mchr[(int)sp->shp_type].m_nland == 0)) {
583 if (sp->shp_nland >= 2) {
584 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
587 /* Eh, let 'em load a spy only */
592 (sp->shp_nland >= mchr[(int)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;
607 land.lnd_mission = 0;
610 putland(land.lnd_uid, &land);
611 if (!has_supply(&land))
612 pr("WARNING: %s is out of supply!\n", prland(&land));
613 putship(sp->shp_uid, sp);
614 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
615 while (nxtitem(&pni, &plane)) {
616 if (plane.pln_flags & PLN_LAUNCHED)
618 if (plane.pln_land != land.lnd_uid)
620 sprintf(buf, "loaded on %s", prship(sp));
621 gift(sp->shp_own, player->cnum, &plane, buf);
622 plane.pln_mission = 0;
623 putplane(plane.pln_uid, &plane);
626 sprintf(buf, "unloaded in your %s at %s",
627 dchr[sectp->sct_type].d_name,
628 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
630 /* Spies are unloaded quietly, others aren't */
631 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
632 gift(sectp->sct_own, player->cnum, &land, buf);
635 putland(land.lnd_uid, &land);
636 putship(sp->shp_uid, sp);
638 /* Spies are unloaded quietly, others aren't, and
639 in the off chance they can carry a plane (missile?)
640 they are quietly unloaded too. */
641 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
642 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
643 while (nxtitem(&pni, &plane)) {
644 if (plane.pln_flags & PLN_LAUNCHED)
646 if (plane.pln_land != land.lnd_uid)
648 sprintf(buf, "unloaded at %s",
649 xyas(plane.pln_x, plane.pln_y,
651 gift(sectp->sct_own, player->cnum, &plane, buf);
652 plane.pln_mission = 0;
653 putplane(plane.pln_uid, &plane);
657 pr("%s %s %s at %s.\n",
659 (load_unload == UNLOAD) ?
660 "unloaded from" : "loaded onto",
661 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
669 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
670 struct ichrstr *ich, int load_unload, int *nshipsp)
672 i_type item = ich->i_uid;
673 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
674 int ship_amt, ship_max, sect_amt, move_amt;
680 sprintf(prompt, "Number of %s to %s %s at %s? ",
682 (load_unload == UNLOAD) ?
683 "unload from" : "load onto",
684 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
685 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
688 if (!still_ok_ship(sectp, sp))
691 ship_amt = sp->shp_item[item];
692 ship_max = mcp->m_item[item];
693 sect_amt = sectp->sct_item[item];
696 move_amt = -amount - ship_amt;
698 move_amt = load_unload == LOAD ? amount : -amount;
699 if (move_amt > ship_max - ship_amt)
700 move_amt = ship_max - ship_amt;
701 if (move_amt < -ship_amt)
702 move_amt = -ship_amt;
703 if (move_amt > sect_amt)
705 if (move_amt < sect_amt - ITEM_MAX)
706 move_amt = sect_amt - ITEM_MAX;
709 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
710 pr("%s civilians refuse to %s at %s!\n",
711 move_amt < 0 ? "Your" : "Foreign",
712 move_amt < 0 ? "disembark" : "board",
713 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
717 if (!want_to_abandon(sectp, item, move_amt, 0))
719 if (!still_ok_ship(sectp, sp))
721 sectp->sct_item[item] = sect_amt - move_amt;
722 sp->shp_item[item] = ship_amt + move_amt;
724 pr("%d %s loaded onto %s at %s\n",
725 move_amt, ich->i_name,
726 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
727 if (sp->shp_own != player->cnum) {
728 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
729 cname(player->cnum), move_amt, ich->i_name,
730 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
733 pr("%d %s unloaded from %s at %s\n",
734 -move_amt, ich->i_name,
735 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
736 if (sectp->sct_own != player->cnum) {
737 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
738 cname(player->cnum), -move_amt, ich->i_name,
739 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
747 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
748 int load_unload, int *nunitsp)
757 if (!lp->lnd_maxlight) {
759 pr("%s cannot carry extra-light planes.\n", prland(lp));
762 count_land_planes(lp);
763 if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) {
765 pr("%s doesn't have room for any more extra-light planes\n",
769 sprintf(prompt, "Plane(s) to %s %s? ",
770 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
771 if (!snxtitem(&ni, EF_PLANE,
772 p = getstarg(player->argp[3], prompt, buf)))
775 if (!still_ok_land(sectp, lp))
779 noisy &= isdigit(*p);
781 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
782 pr("Sector %s is not yours.\n",
783 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
787 while (nxtitem(&ni, &pln)) {
788 if (pln.pln_own != player->cnum)
791 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
793 pr("You can only load xlight planes onto units.\n");
797 if (load_unload == LOAD && pln.pln_ship > -1) {
799 pr("%s is already on ship #%d!\n",
800 prplane(&pln), pln.pln_ship);
803 if (load_unload == LOAD && pln.pln_land > -1) {
805 pr("%s is already on unit #%d!\n",
806 prplane(&pln), pln.pln_land);
809 /* Plane sanity done */
810 /* Find the right unit */
811 if (load_unload == UNLOAD) {
812 if (pln.pln_land != lp->lnd_uid)
814 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
817 /* Fit plane on unit */
818 if (load_unload == LOAD) {
819 if (!put_plane_on_land(&pln, lp)) {
821 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
824 sprintf(buf, "loaded on %s at %s",
825 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
826 gift(lp->lnd_own, player->cnum, &pln, buf);
827 putplane(pln.pln_uid, &pln);
829 if (!take_plane_off_land(&pln, lp)) {
830 pr("Unable to take plane off unit!\n");
831 logerror("load: plane %d could not be taken off unit %d\n",
832 pln.pln_uid, lp->lnd_uid);
835 sprintf(buf, "unloaded at your sector at %s",
836 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
837 gift(sectp->sct_own, player->cnum, &pln, buf);
838 putplane(pln.pln_uid, &pln);
840 pr("%s %s %s at %s.\n",
842 (load_unload == UNLOAD) ?
843 "unloaded from" : "loaded onto",
844 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
852 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
853 struct ichrstr *ich, int load_unload, int *nunitsp)
855 i_type item = ich->i_uid;
856 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
857 int land_amt, land_max, sect_amt, move_amt;
863 sprintf(prompt, "Number of %s to %s %s at %s? ",
865 (load_unload == UNLOAD) ?
866 "unload from" : "load onto",
867 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
868 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
871 if (!still_ok_land(sectp, lp))
874 land_amt = lp->lnd_item[item];
875 land_max = lcp->l_item[item];
876 sect_amt = sectp->sct_item[item];
879 move_amt = -amount - land_amt;
881 move_amt = load_unload == LOAD ? amount : -amount;
882 if (move_amt > land_max - land_amt)
883 move_amt = land_max - land_amt;
884 if (move_amt < -land_amt)
885 move_amt = -land_amt;
886 if (move_amt > sect_amt)
888 if (move_amt < sect_amt - ITEM_MAX)
889 move_amt = sect_amt - ITEM_MAX;
892 if (sectp->sct_own != player->cnum && move_amt > 0) {
893 pr("Sector %s is not yours.\n",
894 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
897 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
898 pr("%s civilians refuse to %s at %s!\n",
899 move_amt < 0 ? "Your" : "Foreign",
900 move_amt < 0 ? "disembark" : "board",
901 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
904 sectp->sct_item[item] = sect_amt - move_amt;
905 lp->lnd_item[item] = land_amt + move_amt;
907 /* Did we put mils onto this unit? If so, reset the fortification */
908 if (item == I_MILIT && move_amt > 0)
911 pr("%d %s loaded onto %s at %s\n",
912 move_amt, ich->i_name,
913 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
914 if (lp->lnd_own != player->cnum) {
915 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
916 cname(player->cnum), move_amt, ich->i_name,
917 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
920 pr("%d %s unloaded from %s at %s\n",
921 -move_amt, ich->i_name,
922 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
923 if (sectp->sct_own != player->cnum) {
924 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
925 cname(player->cnum), -move_amt, ich->i_name,
926 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
934 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
935 int load_unload, int *nunitsp)
937 struct nstr_item pni, ni;
947 if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) {
950 pr("%s doesn't have room for any more land units!\n",
953 pr("%s cannot carry land units!\n", prland(lp));
957 sprintf(prompt, "Land unit(s) to %s %s? ",
958 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
959 if (!snxtitem(&ni, EF_LAND,
960 p = getstarg(player->argp[3], prompt, buf)))
963 if (!still_ok_land(sectp, lp))
967 noisy &= isdigit(*p);
969 while (nxtitem(&ni, &land)) {
971 if (land.lnd_own != player->cnum)
974 if (load_unload == LOAD) {
975 if (land.lnd_ship > -1) {
977 pr("%s is already on ship #%d!\n",
978 prland(&land), land.lnd_ship);
981 if (land.lnd_land > -1) {
983 pr("%s is already on land #%d!\n",
984 prland(&land), land.lnd_land);
987 lnd_count_units(&land);
988 if (land.lnd_nland > 0) {
990 pr("%s cannot be loaded since it is carrying units\n",
994 if (land.lnd_uid == lp->lnd_uid) {
996 pr("%s can't be loaded onto itself!\n", prland(&land));
999 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
1001 pr("%s is too heavy to load.\n", prland(&land));
1006 /* Unit sanity done */
1007 /* Find the right ship */
1008 if (load_unload == UNLOAD) {
1009 if (land.lnd_land != lp->lnd_uid)
1011 if (land.lnd_ship > -1)
1013 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
1016 /* Fit unit on ship */
1017 if (load_unload == LOAD) {
1018 lnd_count_units(lp);
1019 if (lp->lnd_nland >= lp->lnd_maxland) {
1022 pr("%s doesn't have room for any more land units!\n",
1025 pr("%s cannot carry land units!\n", prland(lp));
1029 sprintf(buf, "loaded on your %s at %s",
1030 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1031 gift(lp->lnd_own, player->cnum, &land, buf);
1032 land.lnd_land = lp->lnd_uid;
1033 land.lnd_harden = 0;
1034 land.lnd_mission = 0;
1035 resupply_all(&land);
1037 putland(land.lnd_uid, &land);
1038 if (!has_supply(&land))
1039 pr("WARNING: %s is out of supply!\n", prland(&land));
1040 putland(lp->lnd_uid, lp);
1041 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1042 while (nxtitem(&pni, &plane)) {
1043 if (plane.pln_flags & PLN_LAUNCHED)
1045 if (plane.pln_land != land.lnd_uid)
1047 sprintf(buf, "loaded on %s", prland(lp));
1048 gift(lp->lnd_own, player->cnum, &plane, buf);
1049 plane.pln_mission = 0;
1050 putplane(plane.pln_uid, &plane);
1053 sprintf(buf, "unloaded in your %s at %s",
1054 dchr[sectp->sct_type].d_name,
1055 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1056 gift(sectp->sct_own, player->cnum, &land, buf);
1059 putland(land.lnd_uid, &land);
1060 putland(lp->lnd_uid, lp);
1061 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1062 while (nxtitem(&pni, &plane)) {
1063 if (plane.pln_flags & PLN_LAUNCHED)
1065 if (plane.pln_land != land.lnd_uid)
1067 sprintf(buf, "unloaded at %s",
1068 xyas(plane.pln_x, plane.pln_y, sectp->sct_own));
1069 gift(sectp->sct_own, player->cnum, &plane, buf);
1070 plane.pln_mission = 0;
1071 putplane(plane.pln_uid, &plane);
1074 pr("%s %s %s at %s.\n",
1076 (load_unload == UNLOAD) ?
1077 "unloaded from" : "loaded onto",
1078 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));