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
55 * The values 1 and -1 are important below, don't change them.
60 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
61 int noisy, int load_unload, int *nshipsp);
62 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
63 int noisy, int load_unload, int *nshipsp);
64 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
65 struct ichrstr *ich, int load_unload,
67 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
68 int noisy, int load_unload, int *nunitsp);
69 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
70 int noisy, int load_unload, int *nunitsp);
71 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
72 struct ichrstr *ich, int load_unload,
81 struct nstr_item nbst;
90 if (!(p = getstarg(player->argp[1],
91 "What commodity (or 'plane' or 'land')? ", buf))
95 if (!strncmp(p, "plane", 5))
97 else if (!strncmp(p, "land", 4))
99 else if (NULL != (ich = item_by_name(p)))
102 pr("Can't load '%s'\n", p);
106 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
111 if (!snxtitem(&nbst, EF_SHIP, p))
114 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
117 while (nxtitem(&nbst, &ship)) {
120 if (!player->owner && (load_unload == UNLOAD)) {
124 if (ontradingblock(EF_SHIP, &ship)) {
125 pr("You cannot load/unload an item on the trading block!\n");
130 if (ship.shp_own != player->cnum) {
133 if (getrel(getnatp(player->cnum), ship.shp_own) < FRIENDLY)
136 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
138 if ((sect.sct_own != player->cnum) &&
139 (ship.shp_own != player->cnum))
141 if (!player->owner &&
142 !sect_has_dock(§))
146 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
148 pr("You don't own %s \n",
149 xyas(ship.shp_x, ship.shp_y, player->cnum));
152 if (!sect_has_dock(§)) {
154 pr("Sector %s is not a harbor%s%s.\n",
155 xyas(ship.shp_x, ship.shp_y, player->cnum),
156 dchr[SCT_CAPIT].d_nav == NAV_CANAL ? " or a " : "",
157 dchr[SCT_CAPIT].d_nav == NAV_CANAL ?
158 dchr[SCT_CAPIT].d_name : "");
161 if (sect.sct_own != player->cnum && load_unload == UNLOAD
162 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
164 pr("You can't unload into an unfriendly %s\n",
165 dchr[sect.sct_type].d_name);
168 if (sect.sct_effic < 2) {
170 pr("The %s at %s is not 2%% efficient yet.\n",
171 dchr[sect.sct_type].d_name,
172 xyas(ship.shp_x, ship.shp_y, player->cnum));
179 load_plane_ship(§, &ship, noisy, load_unload,
186 load_land_ship(§, &ship, noisy, load_unload,
193 load_comm_ship(§, &ship, ich, load_unload, &nships)))
196 /* load/unload plague */
197 if (sect.sct_pstage == PLG_INFECT
198 && ship.shp_pstage == PLG_HEALTHY)
199 ship.shp_pstage = PLG_EXPOSED;
200 if (ship.shp_pstage == PLG_INFECT
201 && sect.sct_pstage == PLG_HEALTHY)
202 sect.sct_pstage = PLG_EXPOSED;
204 putship(ship.shp_uid, &ship);
207 pr("No ships affected\n");
209 pr("%d ship%s %sloaded\n", nships, splur(nships),
210 load_unload == UNLOAD ? "un" : "");
220 struct nstr_item nbst;
229 if (!(p = getstarg(player->argp[1],
230 "What commodity (or 'plane' or 'land')? ", buf))
233 if (!strncmp(p, "plane", 5))
235 else if (!strncmp(p, "land", 4))
237 else if (NULL != (ich = item_by_name(p)))
240 pr("Can't load '%s'\n", p);
244 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
249 if (!snxtitem(&nbst, EF_LAND, p))
252 load_unload = player->argp[0][1] == 'l' ? LOAD : UNLOAD;
255 while (nxtitem(&nbst, &land)) {
256 if (land.lnd_own == 0)
259 if (player->cnum != land.lnd_own &&
260 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
263 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
266 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
269 if (ontradingblock(EF_LAND, &land)) {
270 pr("You cannot load/unload an item on the trading block!\n");
275 if (sect.sct_own != player->cnum &&
276 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
277 pr("Sector %s is not yours.\n",
278 xyas(land.lnd_x, land.lnd_y, player->cnum));
285 load_land_land(§, &land, noisy, load_unload,
292 load_plane_land(§, &land, noisy, load_unload,
299 load_comm_land(§, &land, ich, load_unload, &nunits)))
302 /* load/unload plague */
303 if (sect.sct_pstage == PLG_INFECT
304 && land.lnd_pstage == PLG_HEALTHY)
305 land.lnd_pstage = PLG_EXPOSED;
306 if (land.lnd_pstage == PLG_INFECT
307 && sect.sct_pstage == PLG_HEALTHY)
308 sect.sct_pstage = PLG_EXPOSED;
311 putland(land.lnd_uid, &land);
314 pr("No units affected\n");
316 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
317 load_unload == UNLOAD ? "un" : "");
322 gift(natid givee, natid giver, void *ptr, int type, char *mesg)
344 wu(0, givee, "%s %s %s\n", cname(giver), p, mesg);
348 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
350 if (!check_sect_ok(sectp))
352 if (!check_ship_ok(shipp))
358 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
360 if (!check_sect_ok(sectp))
362 if (!check_land_ok(landp))
368 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
369 int load_unload, int *nshipsp)
377 struct mchrstr *mcp = mchr + sp->shp_type;
379 if (!(mcp->m_flags & (M_CHOPPER | M_XLIGHT | M_FLY | M_MSL))) {
381 pr("%s cannot carry planes\n", prship(sp));
385 if (load_unload == LOAD &&
386 sp->shp_nchoppers >= mcp->m_nchoppers &&
387 sp->shp_nxlight >= mcp->m_nxlight &&
388 sp->shp_nplane >= 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 if (!snxtitem(&ni, EF_PLANE,
396 p = getstarg(player->argp[3], prompt, buf)))
399 if (!still_ok_ship(sectp, sp))
403 noisy &= isdigit(*p);
405 while (nxtitem(&ni, &pln)) {
406 if (pln.pln_own != player->cnum)
408 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
409 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
410 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
411 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
414 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
417 if (load_unload == LOAD && pln.pln_ship > -1) {
419 pr("%s is already on ship #%d!\n",
420 prplane(&pln), pln.pln_ship);
423 if (load_unload == LOAD && pln.pln_land > -1) {
425 pr("%s is already on land unit #%d!\n",
426 prplane(&pln), pln.pln_land);
430 /* Plane sanity done */
431 /* Find the right ship */
432 if (load_unload == UNLOAD) {
433 if (pln.pln_ship != sp->shp_uid)
435 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
438 /* ship to (plane or missle) sanity */
439 if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) {
440 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
441 strcpy(buf, "planes");
442 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
443 strcpy(buf, "choppers");
444 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
445 strcpy(buf, "missiles");
446 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
447 strcpy(buf, "extra light planes");
448 } /* else impossible */
450 pr("%s cannot carry %s.\n", prship(sp), buf);
453 /* Fit plane on ship */
454 if (load_unload == LOAD) {
455 if (!put_plane_on_ship(&pln, sp)) {
457 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
460 sprintf(buf, "loaded on your %s at %s",
461 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
462 gift(sp->shp_own, player->cnum, &pln, EF_PLANE, buf);
463 makelost(EF_PLANE, pln.pln_own, pln.pln_uid,
464 pln.pln_x, pln.pln_y);
465 pln.pln_own = sp->shp_own;
466 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid,
467 pln.pln_x, pln.pln_y);
469 putplane(pln.pln_uid, &pln);
471 if (!take_plane_off_ship(&pln, sp)) {
472 pr("Unable to take plane off ship!\n");
473 logerror("load: plane %d could not be taken off ship %d\n",
474 pln.pln_uid, sp->shp_uid);
477 sprintf(buf, "unloaded in your %s at %s",
478 dchr[sectp->sct_type].d_name,
479 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
480 gift(sectp->sct_own, player->cnum, &pln, EF_PLANE, buf);
481 makelost(EF_PLANE, pln.pln_own, pln.pln_uid,
482 pln.pln_x, pln.pln_y);
483 pln.pln_own = sectp->sct_own;
484 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid,
485 pln.pln_x, pln.pln_y);
486 putplane(pln.pln_uid, &pln);
488 pr("%s %s %s at %s.\n",
490 (load_unload == UNLOAD) ?
491 "unloaded from" : "loaded onto",
492 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
500 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
501 int load_unload, int *nshipsp)
503 struct nstr_item pni, ni;
513 if (load_unload == LOAD) {
515 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
516 (mchr[(int)sp->shp_type].m_nland == 0)) {
517 if (sp->shp_nland >= 2) {
518 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
521 /* Eh, let 'em load a spy only */
526 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
528 if (mchr[(int)sp->shp_type].m_nland)
529 pr("%s doesn't have room for any more land units!\n",
532 pr("%s cannot carry land units!\n", prship(sp));
537 sprintf(prompt, "Land unit(s) to %s %s? ",
538 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
539 if (!snxtitem(&ni, EF_LAND,
540 p = getstarg(player->argp[3], prompt, buf)))
543 if (!still_ok_ship(sectp, sp))
547 noisy &= isdigit(*p);
549 while (nxtitem(&ni, &land)) {
550 if (land.lnd_own != player->cnum)
553 if (load_unload == LOAD) {
554 if (land.lnd_ship > -1) {
556 pr("%s is already on ship #%d!\n",
557 prland(&land), land.lnd_ship);
560 if (land.lnd_land > -1) {
562 pr("%s is already on land #%d!\n",
563 prland(&land), land.lnd_land);
566 lnd_count_units(&land);
567 if (land.lnd_nland > 0) {
569 pr("%s cannot be loaded since it is carrying units\n",
573 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
575 pr("%s is too heavy to load.\n", prland(&land));
578 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
580 pr("Subs can only carry spy units.\n");
585 /* Unit sanity done */
586 /* Find the right ship */
587 if (load_unload == UNLOAD) {
588 if (land.lnd_ship != sp->shp_uid)
590 if (land.lnd_land > -1)
592 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
595 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
596 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
597 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
599 pr("You can only load light units onto ships,\n");
600 pr("unless the ship is a non-sub supply ship\n");
601 pr("%s not loaded\n", prland(&land));
605 /* Fit unit on ship */
606 if (load_unload == LOAD) {
608 /* We have to check again, since it may have changed */
610 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
611 (mchr[(int)sp->shp_type].m_nland == 0)) {
612 if (sp->shp_nland >= 2) {
613 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
616 /* Eh, let 'em load a spy only */
621 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
623 if (mchr[(int)sp->shp_type].m_nland)
624 pr("%s doesn't have room for any more land units!\n",
627 pr("%s cannot carry land units!\n", prship(sp));
631 sprintf(buf, "loaded on your %s at %s",
632 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
633 gift(sp->shp_own, player->cnum, &land, EF_LAND, buf);
634 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
635 land.lnd_x, land.lnd_y);
636 land.lnd_own = sp->shp_own;
637 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
638 land.lnd_x, land.lnd_y);
639 land.lnd_ship = sp->shp_uid;
641 land.lnd_mission = 0;
644 putland(land.lnd_uid, &land);
645 if (!has_supply(&land))
646 pr("WARNING: %s is out of supply!\n", prland(&land));
647 putship(sp->shp_uid, sp);
648 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
649 while (nxtitem(&pni, &plane)) {
650 if (plane.pln_flags & PLN_LAUNCHED)
652 if (plane.pln_land != land.lnd_uid)
654 sprintf(buf, "loaded on %s", prship(sp));
655 gift(sp->shp_own, player->cnum, &plane, EF_PLANE, buf);
656 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
657 plane.pln_x, plane.pln_y);
658 plane.pln_own = sp->shp_own;
659 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
660 plane.pln_x, plane.pln_y);
661 plane.pln_mission = 0;
662 putplane(plane.pln_uid, &plane);
665 sprintf(buf, "unloaded in your %s at %s",
666 dchr[sectp->sct_type].d_name,
667 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
669 /* Spies are unloaded quietly, others aren't */
670 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
671 gift(sectp->sct_own, player->cnum, &land, EF_LAND, buf);
672 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
673 land.lnd_x, land.lnd_y);
674 land.lnd_own = sectp->sct_own;
675 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
676 land.lnd_x, land.lnd_y);
681 putland(land.lnd_uid, &land);
682 putship(sp->shp_uid, sp);
684 /* Spies are unloaded quietly, others aren't, and
685 in the off chance they can carry a plane (missile?)
686 they are quietly unloaded too. */
687 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
688 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
689 while (nxtitem(&pni, &plane)) {
690 if (plane.pln_flags & PLN_LAUNCHED)
692 if (plane.pln_land != land.lnd_uid)
694 sprintf(buf, "unloaded at %s",
695 xyas(plane.pln_x, plane.pln_y,
697 gift(sectp->sct_own, player->cnum, &plane, EF_PLANE, buf);
698 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
699 plane.pln_x, plane.pln_y);
700 plane.pln_own = sectp->sct_own;
701 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
702 plane.pln_x, plane.pln_y);
703 plane.pln_mission = 0;
704 putplane(plane.pln_uid, &plane);
708 pr("%s %s %s at %s.\n",
710 (load_unload == UNLOAD) ?
711 "unloaded from" : "loaded onto",
712 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
720 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
721 struct ichrstr *ich, int load_unload, int *nshipsp)
723 i_type item = ich->i_uid;
724 struct mchrstr *mcp = &mchr[(int)sp->shp_type];
725 int ship_amt, ship_max, sect_amt, move_amt;
731 sprintf(prompt, "Number of %s to %s %s at %s? ",
733 (load_unload == UNLOAD) ?
734 "unload from" : "load onto",
735 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
736 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
739 if (!still_ok_ship(sectp, sp))
742 ship_amt = sp->shp_item[item];
743 ship_max = mcp->m_item[item];
744 sect_amt = sectp->sct_item[item];
747 move_amt = -amount - ship_amt;
749 move_amt = load_unload == LOAD ? amount : -amount;
750 if (move_amt > ship_max - ship_amt)
751 move_amt = ship_max - ship_amt;
752 if (move_amt < -ship_amt)
753 move_amt = -ship_amt;
754 if (move_amt > sect_amt)
756 if (move_amt < sect_amt - ITEM_MAX)
757 move_amt = sect_amt - ITEM_MAX;
760 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
761 pr("%s civilians refuse to %s at %s!\n",
762 move_amt < 0 ? "Your" : "Foreign",
763 move_amt < 0 ? "disembark" : "board",
764 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
768 if (!want_to_abandon(sectp, item, move_amt, 0))
770 if (!still_ok_ship(sectp, sp))
772 sectp->sct_item[item] = sect_amt - move_amt;
773 sp->shp_item[item] = ship_amt + move_amt;
775 pr("%d %s loaded onto %s at %s\n",
776 move_amt, ich->i_name,
777 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
778 if (sp->shp_own != player->cnum) {
779 wu(0, sp->shp_own, "%s loaded %d %s onto %s at %s\n",
780 cname(player->cnum), move_amt, ich->i_name,
781 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
784 pr("%d %s unloaded from %s at %s\n",
785 -move_amt, ich->i_name,
786 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
787 if (sectp->sct_own != player->cnum) {
788 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
789 cname(player->cnum), -move_amt, ich->i_name,
790 prship(sp), xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
798 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
799 int load_unload, int *nunitsp)
808 if (!lp->lnd_maxlight) {
810 pr("%s cannot carry extra-light planes.\n", prland(lp));
813 count_land_planes(lp);
814 if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) {
816 pr("%s doesn't have room for any more extra-light planes\n",
820 sprintf(prompt, "Plane(s) to %s %s? ",
821 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
822 if (!snxtitem(&ni, EF_PLANE,
823 p = getstarg(player->argp[3], prompt, buf)))
826 if (!still_ok_land(sectp, lp))
830 noisy &= isdigit(*p);
832 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
833 pr("Sector %s is not yours.\n",
834 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
838 while (nxtitem(&ni, &pln)) {
839 if (pln.pln_own != player->cnum)
842 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
844 pr("You can only load xlight planes onto units.\n");
848 if (load_unload == LOAD && pln.pln_ship > -1) {
850 pr("%s is already on ship #%d!\n",
851 prplane(&pln), pln.pln_ship);
854 if (load_unload == LOAD && pln.pln_land > -1) {
856 pr("%s is already on unit #%d!\n",
857 prplane(&pln), pln.pln_land);
860 /* Plane sanity done */
861 /* Find the right unit */
862 if (load_unload == UNLOAD) {
863 if (pln.pln_land != lp->lnd_uid)
865 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
868 /* Fit plane on unit */
869 if (load_unload == LOAD) {
870 if (!put_plane_on_land(&pln, lp)) {
872 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
875 sprintf(buf, "loaded on %s at %s",
876 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
877 gift(lp->lnd_own, player->cnum, &pln, EF_PLANE, buf);
878 makelost(EF_PLANE, pln.pln_own, pln.pln_uid,
879 pln.pln_x, pln.pln_y);
880 pln.pln_own = lp->lnd_own;
881 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid,
882 pln.pln_x, pln.pln_y);
883 putplane(pln.pln_uid, &pln);
885 if (!take_plane_off_land(&pln, lp)) {
886 pr("Unable to take plane off unit!\n");
887 logerror("load: plane %d could not be taken off unit %d\n",
888 pln.pln_uid, lp->lnd_uid);
891 sprintf(buf, "unloaded at your sector at %s",
892 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
893 gift(sectp->sct_own, player->cnum, &pln, EF_PLANE, buf);
894 makelost(EF_PLANE, pln.pln_own, pln.pln_uid,
895 pln.pln_x, pln.pln_y);
896 pln.pln_own = sectp->sct_own;
897 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid,
898 pln.pln_x, pln.pln_y);
899 putplane(pln.pln_uid, &pln);
901 pr("%s %s %s at %s.\n",
903 (load_unload == UNLOAD) ?
904 "unloaded from" : "loaded onto",
905 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
913 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
914 struct ichrstr *ich, int load_unload, int *nunitsp)
916 i_type item = ich->i_uid;
917 struct lchrstr *lcp = &lchr[(int)lp->lnd_type];
918 int land_amt, land_max, sect_amt, move_amt;
924 sprintf(prompt, "Number of %s to %s %s at %s? ",
926 (load_unload == UNLOAD) ?
927 "unload from" : "load onto",
928 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
929 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
932 if (!still_ok_land(sectp, lp))
935 land_amt = lp->lnd_item[item];
936 land_max = lcp->l_item[item];
937 sect_amt = sectp->sct_item[item];
940 move_amt = -amount - land_amt;
942 move_amt = load_unload == LOAD ? amount : -amount;
943 if (move_amt > land_max - land_amt)
944 move_amt = land_max - land_amt;
945 if (move_amt < -land_amt)
946 move_amt = -land_amt;
947 if (move_amt > sect_amt)
949 if (move_amt < sect_amt - ITEM_MAX)
950 move_amt = sect_amt - ITEM_MAX;
953 if (sectp->sct_own != player->cnum && move_amt > 0) {
954 pr("Sector %s is not yours.\n",
955 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
958 if (sectp->sct_oldown != player->cnum && item == I_CIVIL) {
959 pr("%s civilians refuse to %s at %s!\n",
960 move_amt < 0 ? "Your" : "Foreign",
961 move_amt < 0 ? "disembark" : "board",
962 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
965 sectp->sct_item[item] = sect_amt - move_amt;
966 lp->lnd_item[item] = land_amt + move_amt;
968 /* Did we put mils onto this unit? If so, reset the fortification */
969 if (item == I_MILIT && move_amt > 0)
972 pr("%d %s loaded onto %s at %s\n",
973 move_amt, ich->i_name,
974 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
975 if (lp->lnd_own != player->cnum) {
976 wu(0, lp->lnd_own, "%s loaded %d %s onto %s at %s\n",
977 cname(player->cnum), move_amt, ich->i_name,
978 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
981 pr("%d %s unloaded from %s at %s\n",
982 -move_amt, ich->i_name,
983 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
984 if (sectp->sct_own != player->cnum) {
985 wu(0, sectp->sct_own, "%s unloaded %d %s from %s at %s\n",
986 cname(player->cnum), -move_amt, ich->i_name,
987 prland(lp), xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
995 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
996 int load_unload, int *nunitsp)
998 struct nstr_item pni, ni;
1000 struct plnstr plane;
1006 lnd_count_units(lp);
1008 if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) {
1011 pr("%s doesn't have room for any more land units!\n",
1014 pr("%s cannot carry land units!\n", prland(lp));
1018 sprintf(prompt, "Land unit(s) to %s %s? ",
1019 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
1020 if (!snxtitem(&ni, EF_LAND,
1021 p = getstarg(player->argp[3], prompt, buf)))
1024 if (!still_ok_land(sectp, lp))
1028 noisy &= isdigit(*p);
1030 while (nxtitem(&ni, &land)) {
1032 if (land.lnd_own != player->cnum)
1035 if (load_unload == LOAD) {
1036 if (land.lnd_ship > -1) {
1038 pr("%s is already on ship #%d!\n",
1039 prland(&land), land.lnd_ship);
1042 if (land.lnd_land > -1) {
1044 pr("%s is already on land #%d!\n",
1045 prland(&land), land.lnd_land);
1048 lnd_count_units(&land);
1049 if (land.lnd_nland > 0) {
1051 pr("%s cannot be loaded since it is carrying units\n",
1055 if (land.lnd_uid == lp->lnd_uid) {
1057 pr("%s can't be loaded onto itself!\n", prland(&land));
1060 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
1062 pr("%s is too heavy to load.\n", prland(&land));
1067 /* Unit sanity done */
1068 /* Find the right ship */
1069 if (load_unload == UNLOAD) {
1070 if (land.lnd_land != lp->lnd_uid)
1072 if (land.lnd_ship > -1)
1074 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
1077 /* Fit unit on ship */
1078 if (load_unload == LOAD) {
1079 lnd_count_units(lp);
1080 if (lp->lnd_nland >= lp->lnd_maxland) {
1083 pr("%s doesn't have room for any more land units!\n",
1086 pr("%s cannot carry land units!\n", prland(lp));
1090 sprintf(buf, "loaded on your %s at %s",
1091 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1092 gift(lp->lnd_own, player->cnum, &land, EF_LAND, buf);
1093 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
1094 land.lnd_x, land.lnd_y);
1095 land.lnd_own = lp->lnd_own;
1096 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
1097 land.lnd_x, land.lnd_y);
1098 land.lnd_land = lp->lnd_uid;
1099 land.lnd_harden = 0;
1100 land.lnd_mission = 0;
1101 resupply_all(&land);
1103 putland(land.lnd_uid, &land);
1104 if (!has_supply(&land))
1105 pr("WARNING: %s is out of supply!\n", prland(&land));
1106 putland(lp->lnd_uid, lp);
1107 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1108 while (nxtitem(&pni, &plane)) {
1109 if (plane.pln_flags & PLN_LAUNCHED)
1111 if (plane.pln_land != land.lnd_uid)
1113 sprintf(buf, "loaded on %s", prland(lp));
1114 gift(lp->lnd_own, player->cnum, &plane, EF_PLANE, buf);
1115 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1116 plane.pln_x, plane.pln_y);
1117 plane.pln_own = lp->lnd_own;
1118 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1119 plane.pln_x, plane.pln_y);
1120 plane.pln_mission = 0;
1121 putplane(plane.pln_uid, &plane);
1124 sprintf(buf, "unloaded in your %s at %s",
1125 dchr[sectp->sct_type].d_name,
1126 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1127 gift(sectp->sct_own, player->cnum, &land, EF_LAND, buf);
1128 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
1129 land.lnd_x, land.lnd_y);
1130 land.lnd_own = sectp->sct_own;
1131 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
1132 land.lnd_x, land.lnd_y);
1135 putland(land.lnd_uid, &land);
1136 putland(lp->lnd_uid, lp);
1137 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1138 while (nxtitem(&pni, &plane)) {
1139 if (plane.pln_flags & PLN_LAUNCHED)
1141 if (plane.pln_land != land.lnd_uid)
1143 sprintf(buf, "unloaded at %s",
1144 xyas(plane.pln_x, plane.pln_y, sectp->sct_own));
1145 gift(sectp->sct_own, player->cnum, &plane, EF_PLANE, buf);
1146 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1147 plane.pln_x, plane.pln_y);
1148 plane.pln_own = sectp->sct_own;
1149 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1150 plane.pln_x, plane.pln_y);
1151 plane.pln_mission = 0;
1152 putplane(plane.pln_uid, &plane);
1155 pr("%s %s %s at %s.\n",
1157 (load_unload == UNLOAD) ?
1158 "unloaded from" : "loaded onto",
1159 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));