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, int type, char *mesg)
318 struct empobj *gen = ptr;
321 if (giver != givee) {
340 wu(0, givee, "%s %s %s\n", cname(giver), p, mesg);
343 makelost(type, gen->own, gen->uid, gen->x, gen->y);
345 makenotlost(type, gen->own, gen->uid, gen->x, gen->y);
349 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
351 if (!check_sect_ok(sectp))
353 if (!check_ship_ok(shipp))
359 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
361 if (!check_sect_ok(sectp))
363 if (!check_land_ok(landp))
369 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
370 int load_unload, int *nshipsp)
378 struct mchrstr *mcp = mchr + sp->shp_type;
380 if (!(mcp->m_flags & (M_CHOPPER | M_XLIGHT | M_FLY | M_MSL))) {
382 pr("%s cannot carry planes\n", prship(sp));
386 if (load_unload == LOAD &&
387 sp->shp_nchoppers >= mcp->m_nchoppers &&
388 sp->shp_nxlight >= mcp->m_nxlight &&
389 sp->shp_nplane >= mcp->m_nplanes) {
391 pr("%s doesn't have room for any more planes\n", prship(sp));
394 sprintf(prompt, "Plane(s) to %s %s? ",
395 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
396 if (!snxtitem(&ni, EF_PLANE,
397 p = getstarg(player->argp[3], prompt, buf)))
400 if (!still_ok_ship(sectp, sp))
404 noisy &= isdigit(*p);
406 while (nxtitem(&ni, &pln)) {
407 if (pln.pln_own != player->cnum)
409 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
410 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
411 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
412 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
415 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
418 if (load_unload == LOAD && pln.pln_ship > -1) {
420 pr("%s is already on ship #%d!\n",
421 prplane(&pln), pln.pln_ship);
424 if (load_unload == LOAD && pln.pln_land > -1) {
426 pr("%s is already on land unit #%d!\n",
427 prplane(&pln), pln.pln_land);
431 /* Plane sanity done */
432 /* Find the right ship */
433 if (load_unload == UNLOAD) {
434 if (pln.pln_ship != sp->shp_uid)
436 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
439 /* ship to (plane or missle) sanity */
440 if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) {
441 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
442 strcpy(buf, "planes");
443 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
444 strcpy(buf, "choppers");
445 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
446 strcpy(buf, "missiles");
447 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
448 strcpy(buf, "extra light planes");
449 } /* else impossible */
451 pr("%s cannot carry %s.\n", prship(sp), buf);
454 /* Fit plane on ship */
455 if (load_unload == LOAD) {
456 if (!put_plane_on_ship(&pln, sp)) {
458 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
461 sprintf(buf, "loaded on your %s at %s",
462 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
463 gift(sp->shp_own, player->cnum, &pln, EF_PLANE, buf);
465 putplane(pln.pln_uid, &pln);
467 if (!take_plane_off_ship(&pln, sp)) {
468 pr("Unable to take plane off ship!\n");
469 logerror("load: plane %d could not be taken off ship %d\n",
470 pln.pln_uid, sp->shp_uid);
473 sprintf(buf, "unloaded in your %s at %s",
474 dchr[sectp->sct_type].d_name,
475 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
476 gift(sectp->sct_own, player->cnum, &pln, EF_PLANE, buf);
477 putplane(pln.pln_uid, &pln);
479 pr("%s %s %s at %s.\n",
481 (load_unload == UNLOAD) ?
482 "unloaded from" : "loaded onto",
483 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
491 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
492 int load_unload, int *nshipsp)
494 struct nstr_item pni, ni;
504 if (load_unload == LOAD) {
506 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
507 (mchr[(int)sp->shp_type].m_nland == 0)) {
508 if (sp->shp_nland >= 2) {
509 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
512 /* Eh, let 'em load a spy only */
517 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
519 if (mchr[(int)sp->shp_type].m_nland)
520 pr("%s doesn't have room for any more land units!\n",
523 pr("%s cannot carry land units!\n", prship(sp));
528 sprintf(prompt, "Land unit(s) to %s %s? ",
529 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
530 if (!snxtitem(&ni, EF_LAND,
531 p = getstarg(player->argp[3], prompt, buf)))
534 if (!still_ok_ship(sectp, sp))
538 noisy &= isdigit(*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 lnd_count_units(&land);
558 if (land.lnd_nland > 0) {
560 pr("%s cannot be loaded since it is carrying units\n",
564 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
566 pr("%s is too heavy to load.\n", prland(&land));
569 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
571 pr("Subs can only carry spy units.\n");
576 /* Unit sanity done */
577 /* Find the right ship */
578 if (load_unload == UNLOAD) {
579 if (land.lnd_ship != sp->shp_uid)
581 if (land.lnd_land > -1)
583 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
586 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
587 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
588 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
590 pr("You can only load light units onto ships,\n");
591 pr("unless the ship is a non-sub supply ship\n");
592 pr("%s not loaded\n", prland(&land));
596 /* Fit unit on ship */
597 if (load_unload == LOAD) {
599 /* We have to check again, since it may have changed */
601 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
602 (mchr[(int)sp->shp_type].m_nland == 0)) {
603 if (sp->shp_nland >= 2) {
604 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
607 /* Eh, let 'em load a spy only */
612 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
614 if (mchr[(int)sp->shp_type].m_nland)
615 pr("%s doesn't have room for any more land units!\n",
618 pr("%s cannot carry land units!\n", prship(sp));
622 sprintf(buf, "loaded on your %s at %s",
623 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
624 gift(sp->shp_own, player->cnum, &land, EF_LAND, buf);
625 land.lnd_ship = sp->shp_uid;
627 land.lnd_mission = 0;
630 putland(land.lnd_uid, &land);
631 if (!has_supply(&land))
632 pr("WARNING: %s is out of supply!\n", prland(&land));
633 putship(sp->shp_uid, sp);
634 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
635 while (nxtitem(&pni, &plane)) {
636 if (plane.pln_flags & PLN_LAUNCHED)
638 if (plane.pln_land != land.lnd_uid)
640 sprintf(buf, "loaded on %s", prship(sp));
641 gift(sp->shp_own, player->cnum, &plane, EF_PLANE, buf);
642 plane.pln_mission = 0;
643 putplane(plane.pln_uid, &plane);
646 sprintf(buf, "unloaded in your %s at %s",
647 dchr[sectp->sct_type].d_name,
648 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
650 /* Spies are unloaded quietly, others aren't */
651 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY))
652 gift(sectp->sct_own, player->cnum, &land, EF_LAND, buf);
655 putland(land.lnd_uid, &land);
656 putship(sp->shp_uid, sp);
658 /* Spies are unloaded quietly, others aren't, and
659 in the off chance they can carry a plane (missile?)
660 they are quietly unloaded too. */
661 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
662 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
663 while (nxtitem(&pni, &plane)) {
664 if (plane.pln_flags & PLN_LAUNCHED)
666 if (plane.pln_land != land.lnd_uid)
668 sprintf(buf, "unloaded at %s",
669 xyas(plane.pln_x, plane.pln_y,
671 gift(sectp->sct_own, player->cnum, &plane, EF_PLANE, buf);
672 plane.pln_mission = 0;
673 putplane(plane.pln_uid, &plane);
677 pr("%s %s %s at %s.\n",
679 (load_unload == UNLOAD) ?
680 "unloaded from" : "loaded onto",
681 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
689 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
690 struct ichrstr *ich, int load_unload, int *nshipsp)
692 i_type item = ich->i_uid;
693 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
694 int ship_amt, ship_max, sect_amt, move_amt;
700 sprintf(prompt, "Number of %s to %s %s at %s? ",
702 (load_unload == UNLOAD) ?
703 "unload from" : "load onto",
704 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
705 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
708 if (!still_ok_ship(sectp, sp))
711 ship_amt = sp->shp_item[item];
712 ship_max = mcp->m_item[item];
713 sect_amt = sectp->sct_item[item];
716 move_amt = -amount - ship_amt;
718 move_amt = load_unload == LOAD ? amount : -amount;
719 if (move_amt > ship_max - ship_amt)
720 move_amt = ship_max - ship_amt;
721 if (move_amt < -ship_amt)
722 move_amt = -ship_amt;
723 if (move_amt > sect_amt)
725 if (move_amt < sect_amt - ITEM_MAX)
726 move_amt = sect_amt - ITEM_MAX;
729 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
730 pr("%s civilians refuse to %s at %s!\n",
731 move_amt < 0 ? "Your" : "Foreign",
732 move_amt < 0 ? "disembark" : "board",
733 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
737 if (!want_to_abandon(sectp, item, move_amt, 0))
739 if (!still_ok_ship(sectp, sp))
741 sectp->sct_item[item] = sect_amt - move_amt;
742 sp->shp_item[item] = ship_amt + move_amt;
744 pr("%d %s loaded onto %s at %s\n",
745 move_amt, ich->i_name,
746 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
747 if (sp->shp_own != player->cnum) {
748 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
749 cname(player->cnum), move_amt, ich->i_name,
750 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
753 pr("%d %s unloaded from %s at %s\n",
754 -move_amt, ich->i_name,
755 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
756 if (sectp->sct_own != player->cnum) {
757 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
758 cname(player->cnum), -move_amt, ich->i_name,
759 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
767 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
768 int load_unload, int *nunitsp)
777 if (!lp->lnd_maxlight) {
779 pr("%s cannot carry extra-light planes.\n", prland(lp));
782 count_land_planes(lp);
783 if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) {
785 pr("%s doesn't have room for any more extra-light planes\n",
789 sprintf(prompt, "Plane(s) to %s %s? ",
790 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
791 if (!snxtitem(&ni, EF_PLANE,
792 p = getstarg(player->argp[3], prompt, buf)))
795 if (!still_ok_land(sectp, lp))
799 noisy &= isdigit(*p);
801 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
802 pr("Sector %s is not yours.\n",
803 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
807 while (nxtitem(&ni, &pln)) {
808 if (pln.pln_own != player->cnum)
811 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
813 pr("You can only load xlight planes onto units.\n");
817 if (load_unload == LOAD && pln.pln_ship > -1) {
819 pr("%s is already on ship #%d!\n",
820 prplane(&pln), pln.pln_ship);
823 if (load_unload == LOAD && pln.pln_land > -1) {
825 pr("%s is already on unit #%d!\n",
826 prplane(&pln), pln.pln_land);
829 /* Plane sanity done */
830 /* Find the right unit */
831 if (load_unload == UNLOAD) {
832 if (pln.pln_land != lp->lnd_uid)
834 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
837 /* Fit plane on unit */
838 if (load_unload == LOAD) {
839 if (!put_plane_on_land(&pln, lp)) {
841 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
844 sprintf(buf, "loaded on %s at %s",
845 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
846 gift(lp->lnd_own, player->cnum, &pln, EF_PLANE, buf);
847 putplane(pln.pln_uid, &pln);
849 if (!take_plane_off_land(&pln, lp)) {
850 pr("Unable to take plane off unit!\n");
851 logerror("load: plane %d could not be taken off unit %d\n",
852 pln.pln_uid, lp->lnd_uid);
855 sprintf(buf, "unloaded at your sector at %s",
856 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
857 gift(sectp->sct_own, player->cnum, &pln, EF_PLANE, buf);
858 putplane(pln.pln_uid, &pln);
860 pr("%s %s %s at %s.\n",
862 (load_unload == UNLOAD) ?
863 "unloaded from" : "loaded onto",
864 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
872 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
873 struct ichrstr *ich, int load_unload, int *nunitsp)
875 i_type item = ich->i_uid;
876 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
877 int land_amt, land_max, sect_amt, move_amt;
883 sprintf(prompt, "Number of %s to %s %s at %s? ",
885 (load_unload == UNLOAD) ?
886 "unload from" : "load onto",
887 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
888 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
891 if (!still_ok_land(sectp, lp))
894 land_amt = lp->lnd_item[item];
895 land_max = lcp->l_item[item];
896 sect_amt = sectp->sct_item[item];
899 move_amt = -amount - land_amt;
901 move_amt = load_unload == LOAD ? amount : -amount;
902 if (move_amt > land_max - land_amt)
903 move_amt = land_max - land_amt;
904 if (move_amt < -land_amt)
905 move_amt = -land_amt;
906 if (move_amt > sect_amt)
908 if (move_amt < sect_amt - ITEM_MAX)
909 move_amt = sect_amt - ITEM_MAX;
912 if (sectp->sct_own != player->cnum && move_amt > 0) {
913 pr("Sector %s is not yours.\n",
914 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
917 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
918 pr("%s civilians refuse to %s at %s!\n",
919 move_amt < 0 ? "Your" : "Foreign",
920 move_amt < 0 ? "disembark" : "board",
921 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
924 sectp->sct_item[item] = sect_amt - move_amt;
925 lp->lnd_item[item] = land_amt + move_amt;
927 /* Did we put mils onto this unit? If so, reset the fortification */
928 if (item == I_MILIT && move_amt > 0)
931 pr("%d %s loaded onto %s at %s\n",
932 move_amt, ich->i_name,
933 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
934 if (lp->lnd_own != player->cnum) {
935 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
936 cname(player->cnum), move_amt, ich->i_name,
937 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
940 pr("%d %s unloaded from %s at %s\n",
941 -move_amt, ich->i_name,
942 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
943 if (sectp->sct_own != player->cnum) {
944 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
945 cname(player->cnum), -move_amt, ich->i_name,
946 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
954 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
955 int load_unload, int *nunitsp)
957 struct nstr_item pni, ni;
967 if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) {
970 pr("%s doesn't have room for any more land units!\n",
973 pr("%s cannot carry land units!\n", prland(lp));
977 sprintf(prompt, "Land unit(s) to %s %s? ",
978 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
979 if (!snxtitem(&ni, EF_LAND,
980 p = getstarg(player->argp[3], prompt, buf)))
983 if (!still_ok_land(sectp, lp))
987 noisy &= isdigit(*p);
989 while (nxtitem(&ni, &land)) {
991 if (land.lnd_own != player->cnum)
994 if (load_unload == LOAD) {
995 if (land.lnd_ship > -1) {
997 pr("%s is already on ship #%d!\n",
998 prland(&land), land.lnd_ship);
1001 if (land.lnd_land > -1) {
1003 pr("%s is already on land #%d!\n",
1004 prland(&land), land.lnd_land);
1007 lnd_count_units(&land);
1008 if (land.lnd_nland > 0) {
1010 pr("%s cannot be loaded since it is carrying units\n",
1014 if (land.lnd_uid == lp->lnd_uid) {
1016 pr("%s can't be loaded onto itself!\n", prland(&land));
1019 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
1021 pr("%s is too heavy to load.\n", prland(&land));
1026 /* Unit sanity done */
1027 /* Find the right ship */
1028 if (load_unload == UNLOAD) {
1029 if (land.lnd_land != lp->lnd_uid)
1031 if (land.lnd_ship > -1)
1033 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
1036 /* Fit unit on ship */
1037 if (load_unload == LOAD) {
1038 lnd_count_units(lp);
1039 if (lp->lnd_nland >= lp->lnd_maxland) {
1042 pr("%s doesn't have room for any more land units!\n",
1045 pr("%s cannot carry land units!\n", prland(lp));
1049 sprintf(buf, "loaded on your %s at %s",
1050 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1051 gift(lp->lnd_own, player->cnum, &land, EF_LAND, buf);
1052 land.lnd_land = lp->lnd_uid;
1053 land.lnd_harden = 0;
1054 land.lnd_mission = 0;
1055 resupply_all(&land);
1057 putland(land.lnd_uid, &land);
1058 if (!has_supply(&land))
1059 pr("WARNING: %s is out of supply!\n", prland(&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, "loaded on %s", prland(lp));
1068 gift(lp->lnd_own, player->cnum, &plane, EF_PLANE, buf);
1069 plane.pln_mission = 0;
1070 putplane(plane.pln_uid, &plane);
1073 sprintf(buf, "unloaded in your %s at %s",
1074 dchr[sectp->sct_type].d_name,
1075 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1076 gift(sectp->sct_own, player->cnum, &land, EF_LAND, buf);
1079 putland(land.lnd_uid, &land);
1080 putland(lp->lnd_uid, lp);
1081 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1082 while (nxtitem(&pni, &plane)) {
1083 if (plane.pln_flags & PLN_LAUNCHED)
1085 if (plane.pln_land != land.lnd_uid)
1087 sprintf(buf, "unloaded at %s",
1088 xyas(plane.pln_x, plane.pln_y, sectp->sct_own));
1089 gift(sectp->sct_own, player->cnum, &plane, EF_PLANE, buf);
1090 plane.pln_mission = 0;
1091 putplane(plane.pln_uid, &plane);
1094 pr("%s %s %s at %s.\n",
1096 (load_unload == UNLOAD) ?
1097 "unloaded from" : "loaded onto",
1098 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));