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
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 or canal.\n",
149 xyas(ship.shp_x, ship.shp_y, player->cnum));
152 if (sect.sct_own != player->cnum && load_unload == UNLOAD
153 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
155 pr("You can't unload into an unfriendly %s\n",
156 dchr[sect.sct_type].d_name);
159 if (sect.sct_effic < 2) {
161 pr("The %s at %s is not 2%% efficient yet.\n",
162 dchr[sect.sct_type].d_name,
163 xyas(ship.shp_x, ship.shp_y, player->cnum));
170 load_plane_ship(§, &ship, noisy, load_unload,
177 load_land_ship(§, &ship, noisy, load_unload,
184 load_comm_ship(§, &ship, ich, load_unload, &nships)))
187 /* load/unload plague */
188 if (sect.sct_pstage == PLG_INFECT
189 && ship.shp_pstage == PLG_HEALTHY)
190 ship.shp_pstage = PLG_EXPOSED;
191 if (ship.shp_pstage == PLG_INFECT
192 && sect.sct_pstage == PLG_HEALTHY)
193 sect.sct_pstage = PLG_EXPOSED;
195 putship(ship.shp_uid, &ship);
198 pr("No ships affected\n");
200 pr("%d ship%s %sloaded\n", nships, splur(nships),
201 load_unload == UNLOAD ? "un" : "");
211 struct nstr_item nbst;
220 if (!(p = getstarg(player->argp[1],
221 "What commodity (or 'plane' or 'land')? ", buf))
224 if (!strncmp(p, "plane", 5))
226 else if (!strncmp(p, "land", 4))
228 else if (NULL != (ich = item_by_name(p)))
231 pr("Can't load '%s'\n", p);
235 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
240 if (!snxtitem(&nbst, EF_LAND, p))
243 load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
246 while (nxtitem(&nbst, &land)) {
247 if (land.lnd_own == 0)
250 if (player->cnum != land.lnd_own &&
251 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
254 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
257 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
260 if (ontradingblock(EF_LAND, &land)) {
261 pr("You cannot load/unload an item on the trading block!\n");
266 if (sect.sct_own != player->cnum &&
267 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
268 pr("Sector %s is not yours.\n",
269 xyas(land.lnd_x, land.lnd_y, player->cnum));
276 load_land_land(§, &land, noisy, load_unload,
283 load_plane_land(§, &land, noisy, load_unload,
290 load_comm_land(§, &land, ich, load_unload, &nunits)))
293 /* load/unload plague */
294 if (sect.sct_pstage == PLG_INFECT
295 && land.lnd_pstage == PLG_HEALTHY)
296 land.lnd_pstage = PLG_EXPOSED;
297 if (land.lnd_pstage == PLG_INFECT
298 && sect.sct_pstage == PLG_HEALTHY)
299 sect.sct_pstage = PLG_EXPOSED;
302 putland(land.lnd_uid, &land);
305 pr("No units affected\n");
307 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
308 load_unload == UNLOAD ? "un" : "");
313 gift(natid givee, natid giver, void *ptr, char *mesg)
315 struct empobj *gen = ptr;
318 wu(0, givee, "%s %s %s\n", cname(giver), obj_nameof(gen), mesg);
320 makelost(gen->ef_type, gen->own, gen->uid, gen->x, gen->y);
322 makenotlost(gen->ef_type, gen->own, gen->uid, gen->x, gen->y);
326 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
328 if (!check_sect_ok(sectp))
330 if (!check_ship_ok(shipp))
336 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
338 if (!check_sect_ok(sectp))
340 if (!check_land_ok(landp))
346 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
347 int load_unload, int *nshipsp)
355 struct mchrstr *mcp = mchr + sp->shp_type;
357 if (mcp->m_nplanes + mcp->m_nchoppers + mcp->m_nxlight == 0) {
359 pr("%s cannot carry planes\n", prship(sp));
363 if (load_unload == LOAD &&
364 sp->shp_nchoppers >= mcp->m_nchoppers &&
365 sp->shp_nxlight >= mcp->m_nxlight &&
366 sp->shp_nplane >= mcp->m_nplanes) {
368 pr("%s doesn't have room for any more planes\n", prship(sp));
371 sprintf(prompt, "Plane(s) to %s %s? ",
372 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
373 if (!snxtitem(&ni, EF_PLANE,
374 p = getstarg(player->argp[3], prompt, buf)))
377 if (!still_ok_ship(sectp, sp))
380 if (noisy && p && *p)
383 while (nxtitem(&ni, &pln)) {
384 if (pln.pln_own != player->cnum)
386 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
387 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
388 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
389 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
392 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
395 if (load_unload == LOAD && pln.pln_ship > -1) {
397 pr("%s is already on ship #%d!\n",
398 prplane(&pln), pln.pln_ship);
401 if (load_unload == LOAD && pln.pln_land > -1) {
403 pr("%s is already on land unit #%d!\n",
404 prplane(&pln), pln.pln_land);
407 if (pln.pln_harden != 0) {
409 pr("%s has been hardened and can't be loaded\n",
414 /* Plane sanity done */
415 /* Find the right ship */
416 if (load_unload == UNLOAD) {
417 if (pln.pln_ship != sp->shp_uid)
419 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
422 /* ship to (plane or missle) sanity */
423 if (!could_be_on_ship(&pln, sp)) {
424 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
425 strcpy(buf, "planes");
426 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
427 strcpy(buf, "choppers");
428 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
429 strcpy(buf, "missiles");
430 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
431 strcpy(buf, "extra light planes");
432 } /* else impossible */
434 pr("%s cannot carry %s.\n", prship(sp), buf);
437 /* Fit plane on ship */
438 if (load_unload == LOAD) {
439 if (!put_plane_on_ship(&pln, sp)) {
441 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
444 sprintf(buf, "loaded on your %s at %s",
445 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
446 gift(sp->shp_own, player->cnum, &pln, buf);
448 putplane(pln.pln_uid, &pln);
450 take_plane_off_ship(&pln, sp);
451 sprintf(buf, "unloaded in your %s at %s",
452 dchr[sectp->sct_type].d_name,
453 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
454 gift(sectp->sct_own, player->cnum, &pln, buf);
455 putplane(pln.pln_uid, &pln);
457 pr("%s %s %s at %s.\n",
459 (load_unload == UNLOAD) ?
460 "unloaded from" : "loaded onto",
461 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
469 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
470 int load_unload, int *nshipsp)
472 struct nstr_item pni, ni;
482 if (load_unload == LOAD) {
484 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
485 (mchr[(int)sp->shp_type].m_nland == 0)) {
486 if (sp->shp_nland >= 2) {
487 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
490 /* Eh, let 'em load a spy only */
495 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
497 if (mchr[(int)sp->shp_type].m_nland)
498 pr("%s doesn't have room for any more land units!\n",
501 pr("%s cannot carry land units!\n", prship(sp));
506 sprintf(prompt, "Land unit(s) to %s %s? ",
507 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
508 if (!snxtitem(&ni, EF_LAND,
509 p = getstarg(player->argp[3], prompt, buf)))
512 if (!still_ok_ship(sectp, sp))
515 if (noisy && p && *p)
518 while (nxtitem(&ni, &land)) {
519 if (land.lnd_own != player->cnum)
522 if (load_unload == LOAD) {
523 if (land.lnd_ship > -1) {
525 pr("%s is already on ship #%d!\n",
526 prland(&land), land.lnd_ship);
529 if (land.lnd_land > -1) {
531 pr("%s is already on land #%d!\n",
532 prland(&land), land.lnd_land);
535 lnd_count_units(&land);
536 if (land.lnd_nland > 0) {
538 pr("%s cannot be loaded since it is carrying units\n",
542 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
544 pr("%s is too heavy to load.\n", prland(&land));
547 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
549 pr("Subs can only carry spy units.\n");
554 /* Unit sanity done */
555 /* Find the right ship */
556 if (load_unload == UNLOAD) {
557 if (land.lnd_ship != sp->shp_uid)
559 if (land.lnd_land > -1)
561 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
564 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
565 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
566 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
568 pr("You can only load light units onto ships,\n");
569 pr("unless the ship is a non-sub supply ship\n");
570 pr("%s not loaded\n", prland(&land));
574 /* Fit unit on ship */
575 if (load_unload == LOAD) {
577 /* We have to check again, since it may have changed */
579 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
580 (mchr[(int)sp->shp_type].m_nland == 0)) {
581 if (sp->shp_nland >= 2) {
582 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
585 /* Eh, let 'em load a spy only */
590 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
592 if (mchr[(int)sp->shp_type].m_nland)
593 pr("%s doesn't have room for any more land units!\n",
596 pr("%s cannot carry land units!\n", prship(sp));
600 sprintf(buf, "loaded on your %s at %s",
601 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
602 gift(sp->shp_own, player->cnum, &land, buf);
603 land.lnd_ship = sp->shp_uid;
605 land.lnd_mission = 0;
608 putland(land.lnd_uid, &land);
609 if (!has_supply(&land))
610 pr("WARNING: %s is out of supply!\n", prland(&land));
611 putship(sp->shp_uid, sp);
612 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
613 while (nxtitem(&pni, &plane)) {
614 if (plane.pln_flags & PLN_LAUNCHED)
616 if (plane.pln_land != land.lnd_uid)
618 sprintf(buf, "loaded on %s", prship(sp));
619 gift(sp->shp_own, player->cnum, &plane, buf);
620 plane.pln_mission = 0;
621 putplane(plane.pln_uid, &plane);
624 sprintf(buf, "unloaded in your %s at %s",
625 dchr[sectp->sct_type].d_name,
626 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
628 /* Spies are unloaded quietly, others aren't */
629 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
630 gift(sectp->sct_own, player->cnum, &land, buf);
633 putland(land.lnd_uid, &land);
634 putship(sp->shp_uid, sp);
636 /* Spies are unloaded quietly, others aren't, and
637 in the off chance they can carry a plane (missile?)
638 they are quietly unloaded too. */
639 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
640 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
641 while (nxtitem(&pni, &plane)) {
642 if (plane.pln_flags & PLN_LAUNCHED)
644 if (plane.pln_land != land.lnd_uid)
646 sprintf(buf, "unloaded at %s",
647 xyas(plane.pln_x, plane.pln_y,
649 gift(sectp->sct_own, player->cnum, &plane, buf);
650 plane.pln_mission = 0;
651 putplane(plane.pln_uid, &plane);
655 pr("%s %s %s at %s.\n",
657 (load_unload == UNLOAD) ?
658 "unloaded from" : "loaded onto",
659 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
667 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
668 struct ichrstr *ich, int load_unload, int *nshipsp)
670 i_type item = ich->i_uid;
671 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
672 int ship_amt, ship_max, sect_amt, move_amt;
678 sprintf(prompt, "Number of %s to %s %s at %s? ",
680 (load_unload == UNLOAD) ?
681 "unload from" : "load onto",
682 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
683 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
686 if (!still_ok_ship(sectp, sp))
689 ship_amt = sp->shp_item[item];
690 ship_max = mcp->m_item[item];
691 sect_amt = sectp->sct_item[item];
694 move_amt = -amount - ship_amt;
696 move_amt = load_unload == LOAD ? amount : -amount;
697 if (move_amt > ship_max - ship_amt)
698 move_amt = ship_max - ship_amt;
699 if (move_amt < -ship_amt)
700 move_amt = -ship_amt;
701 if (move_amt > sect_amt)
703 if (move_amt < sect_amt - ITEM_MAX)
704 move_amt = sect_amt - ITEM_MAX;
707 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
708 pr("%s civilians refuse to %s at %s!\n",
709 move_amt < 0 ? "Your" : "Foreign",
710 move_amt < 0 ? "disembark" : "board",
711 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
715 if (!want_to_abandon(sectp, item, move_amt, 0))
717 if (!still_ok_ship(sectp, sp))
719 sectp->sct_item[item] = sect_amt - move_amt;
720 sp->shp_item[item] = ship_amt + move_amt;
722 pr("%d %s loaded onto %s at %s\n",
723 move_amt, ich->i_name,
724 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
725 if (sp->shp_own != player->cnum) {
726 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
727 cname(player->cnum), move_amt, ich->i_name,
728 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
731 pr("%d %s unloaded from %s at %s\n",
732 -move_amt, ich->i_name,
733 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
734 if (sectp->sct_own != player->cnum) {
735 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
736 cname(player->cnum), -move_amt, ich->i_name,
737 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
745 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
746 int load_unload, int *nunitsp)
754 struct lchrstr *lcp = lchr + lp->lnd_type;
756 if (!lcp->l_nxlight) {
758 pr("%s cannot carry extra-light planes.\n", prland(lp));
761 count_land_planes(lp);
762 if (load_unload == LOAD && lp->lnd_nxlight >= lcp->l_nxlight) {
764 pr("%s doesn't have room for any more extra-light planes\n",
768 sprintf(prompt, "Plane(s) to %s %s? ",
769 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
770 if (!snxtitem(&ni, EF_PLANE,
771 p = getstarg(player->argp[3], prompt, buf)))
774 if (!still_ok_land(sectp, lp))
777 if (noisy && p && *p)
780 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
781 pr("Sector %s is not yours.\n",
782 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
786 while (nxtitem(&ni, &pln)) {
787 if (pln.pln_own != player->cnum)
790 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
792 pr("You can only load xlight planes onto units.\n");
796 if (load_unload == LOAD && pln.pln_ship > -1) {
798 pr("%s is already on ship #%d!\n",
799 prplane(&pln), pln.pln_ship);
802 if (load_unload == LOAD && pln.pln_land > -1) {
804 pr("%s is already on unit #%d!\n",
805 prplane(&pln), pln.pln_land);
808 if (pln.pln_harden != 0) {
810 pr("%s has been hardened and can't be loaded\n",
815 /* Plane sanity done */
816 /* Find the right unit */
817 if (load_unload == UNLOAD) {
818 if (pln.pln_land != lp->lnd_uid)
820 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
823 /* Fit plane on unit */
824 if (load_unload == LOAD) {
825 if (!put_plane_on_land(&pln, lp)) {
827 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
830 sprintf(buf, "loaded on %s at %s",
831 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
832 gift(lp->lnd_own, player->cnum, &pln, buf);
833 putplane(pln.pln_uid, &pln);
835 take_plane_off_land(&pln, lp);
836 sprintf(buf, "unloaded at your sector at %s",
837 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
838 gift(sectp->sct_own, player->cnum, &pln, buf);
839 putplane(pln.pln_uid, &pln);
841 pr("%s %s %s at %s.\n",
843 (load_unload == UNLOAD) ?
844 "unloaded from" : "loaded onto",
845 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
853 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
854 struct ichrstr *ich, int load_unload, int *nunitsp)
856 i_type item = ich->i_uid;
857 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
858 int land_amt, land_max, sect_amt, move_amt;
864 sprintf(prompt, "Number of %s to %s %s at %s? ",
866 (load_unload == UNLOAD) ?
867 "unload from" : "load onto",
868 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
869 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
872 if (!still_ok_land(sectp, lp))
875 land_amt = lp->lnd_item[item];
876 land_max = lcp->l_item[item];
877 sect_amt = sectp->sct_item[item];
880 move_amt = -amount - land_amt;
882 move_amt = load_unload == LOAD ? amount : -amount;
883 if (move_amt > land_max - land_amt)
884 move_amt = land_max - land_amt;
885 if (move_amt < -land_amt)
886 move_amt = -land_amt;
887 if (move_amt > sect_amt)
889 if (move_amt < sect_amt - ITEM_MAX)
890 move_amt = sect_amt - ITEM_MAX;
893 if (sectp->sct_own != player->cnum && move_amt > 0) {
894 pr("Sector %s is not yours.\n",
895 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
898 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
899 pr("%s civilians refuse to %s at %s!\n",
900 move_amt < 0 ? "Your" : "Foreign",
901 move_amt < 0 ? "disembark" : "board",
902 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
905 sectp->sct_item[item] = sect_amt - move_amt;
906 lp->lnd_item[item] = land_amt + move_amt;
908 /* Did we put mils onto this unit? If so, reset the fortification */
909 if (item == I_MILIT && move_amt > 0)
912 pr("%d %s loaded onto %s at %s\n",
913 move_amt, ich->i_name,
914 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
915 if (lp->lnd_own != player->cnum) {
916 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
917 cname(player->cnum), move_amt, ich->i_name,
918 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
921 pr("%d %s unloaded from %s at %s\n",
922 -move_amt, ich->i_name,
923 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
924 if (sectp->sct_own != player->cnum) {
925 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
926 cname(player->cnum), -move_amt, ich->i_name,
927 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
935 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
936 int load_unload, int *nunitsp)
938 struct nstr_item pni, ni;
948 if (load_unload == LOAD
949 && lp->lnd_nland >= lchr[lp->lnd_type].l_nland) {
952 pr("%s doesn't have room for any more land units!\n",
955 pr("%s cannot carry land units!\n", prland(lp));
959 sprintf(prompt, "Land unit(s) to %s %s? ",
960 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
961 if (!snxtitem(&ni, EF_LAND,
962 p = getstarg(player->argp[3], prompt, buf)))
965 if (!still_ok_land(sectp, lp))
968 if (noisy && p && *p)
971 while (nxtitem(&ni, &land)) {
973 if (land.lnd_own != player->cnum)
976 if (load_unload == LOAD) {
977 if (land.lnd_ship > -1) {
979 pr("%s is already on ship #%d!\n",
980 prland(&land), land.lnd_ship);
983 if (land.lnd_land > -1) {
985 pr("%s is already on land #%d!\n",
986 prland(&land), land.lnd_land);
989 lnd_count_units(&land);
990 if (land.lnd_nland > 0) {
992 pr("%s cannot be loaded since it is carrying units\n",
996 if (land.lnd_uid == lp->lnd_uid) {
998 pr("%s can't be loaded onto itself!\n", prland(&land));
1001 if (lchr[(int)land.lnd_type].l_flags & (L_HEAVY | L_TRAIN)) {
1003 pr("%s is too heavy to load.\n", prland(&land));
1008 /* Unit sanity done */
1009 /* Find the right ship */
1010 if (load_unload == UNLOAD) {
1011 if (land.lnd_land != lp->lnd_uid)
1013 if (land.lnd_ship > -1)
1015 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
1018 /* Fit unit on ship */
1019 if (load_unload == LOAD) {
1020 lnd_count_units(lp);
1021 if (lp->lnd_nland >= lchr[lp->lnd_type].l_nland) {
1024 pr("%s doesn't have room for any more land units!\n",
1027 pr("%s cannot carry land units!\n", prland(lp));
1031 sprintf(buf, "loaded on your %s at %s",
1032 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1033 gift(lp->lnd_own, player->cnum, &land, buf);
1034 land.lnd_land = lp->lnd_uid;
1035 land.lnd_harden = 0;
1036 land.lnd_mission = 0;
1037 resupply_all(&land);
1039 putland(land.lnd_uid, &land);
1040 if (!has_supply(&land))
1041 pr("WARNING: %s is out of supply!\n", prland(&land));
1042 putland(lp->lnd_uid, lp);
1043 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1044 while (nxtitem(&pni, &plane)) {
1045 if (plane.pln_flags & PLN_LAUNCHED)
1047 if (plane.pln_land != land.lnd_uid)
1049 sprintf(buf, "loaded on %s", prland(lp));
1050 gift(lp->lnd_own, player->cnum, &plane, buf);
1051 plane.pln_mission = 0;
1052 putplane(plane.pln_uid, &plane);
1055 sprintf(buf, "unloaded in your %s at %s",
1056 dchr[sectp->sct_type].d_name,
1057 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1058 gift(sectp->sct_own, player->cnum, &land, buf);
1061 putland(land.lnd_uid, &land);
1062 putland(lp->lnd_uid, lp);
1063 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1064 while (nxtitem(&pni, &plane)) {
1065 if (plane.pln_flags & PLN_LAUNCHED)
1067 if (plane.pln_land != land.lnd_uid)
1069 sprintf(buf, "unloaded at %s",
1070 xyas(plane.pln_x, plane.pln_y, sectp->sct_own));
1071 gift(sectp->sct_own, player->cnum, &plane, buf);
1072 plane.pln_mission = 0;
1073 putplane(plane.pln_uid, &plane);
1076 pr("%s %s %s at %s.\n",
1078 (load_unload == UNLOAD) ?
1079 "unloaded from" : "loaded onto",
1080 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));