2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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
53 * The values 1 and -1 are important below, don't change them.
58 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
59 int noisy, int load_unload, int *nshipsp);
60 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
61 int noisy, int load_unload, int *nshipsp);
62 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
63 struct ichrstr *ich, int load_unload,
65 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
66 int noisy, int load_unload, int *nunitsp);
67 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
68 int noisy, int load_unload, int *nunitsp);
69 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
70 struct ichrstr *ich, int load_unload,
79 struct nstr_item nbst;
88 if (!(p = getstarg(player->argp[1],
89 "What commodity (or 'plane' or 'land')? ", buf))
93 if (!strncmp(p, "plane", 5))
95 else if (!strncmp(p, "land", 4))
97 else if (NULL != (ich = whatitem(p, (s_char *)0)))
100 pr("Bad commodity.\n");
104 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
109 if (!snxtitem(&nbst, EF_SHIP, p))
112 nbst.flags &= ~(EFF_OWNER);
114 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
117 while (nxtitem(&nbst, (s_char *)&ship)) {
120 if (!player->owner && (load_unload == UNLOAD)) {
124 if (ontradingblock(EF_SHIP, (int *)&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.sct_type != SCT_HARBR &&
143 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT))
147 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
149 pr("You don't own %s \n",
150 xyas(ship.shp_x, ship.shp_y, player->cnum));
153 if (sect.sct_type != SCT_HARBR &&
154 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) {
156 pr("Sector %s is not a harbor%s.\n",
157 xyas(ship.shp_x, ship.shp_y, player->cnum),
158 opt_BIG_CITY ? " or a city" : "");
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 (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
198 getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY)
199 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
200 if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_INFECT &&
201 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
202 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
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 = whatitem(p, (s_char *)0)))
240 pr("Bad commodity.\n");
244 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
249 if (!snxtitem(&nbst, EF_LAND, p))
252 load_unload = *(*player->argp + 1) == 'l' ? LOAD : UNLOAD;
254 nbst.flags &= ~(EFF_OWNER);
257 while (nxtitem(&nbst, (s_char *)&land)) {
258 if (land.lnd_own == 0)
261 if (player->cnum != land.lnd_own &&
262 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
265 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
268 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
271 if (ontradingblock(EF_LAND, (int *)&land)) {
272 pr("You cannot load/unload an item on the trading block!\n");
277 if (sect.sct_own != player->cnum &&
278 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
279 pr("Sector %s is not yours.\n",
280 xyas(land.lnd_x, land.lnd_y, player->cnum));
287 load_land_land(§, &land, noisy, load_unload,
294 load_plane_land(§, &land, noisy, load_unload,
301 load_comm_land(§, &land, ich, load_unload, &nunits)))
304 /* load/unload plague */
305 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
306 getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY)
307 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
308 if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_INFECT &&
309 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
310 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
313 putland(land.lnd_uid, &land);
316 pr("No units affected\n");
318 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
319 load_unload == UNLOAD ? "un" : "");
324 gift(int givee, int giver, s_char *ptr, int type, s_char *mesg)
326 s_char *p, line[256];
334 p = prship((struct shpstr *)ptr);
337 p = prplane((struct plnstr *)ptr);
340 p = prland((struct lndstr *)ptr);
344 sprintf(line, "%s %s %s\n", cname(giver), p, mesg);
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));
397 (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf)))
400 if (!still_ok_ship(sectp, sp))
404 noisy &= isdigit(*p);
406 while (nxtitem(&ni, (s_char *)&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, (s_char *)&pln, EF_PLANE, buf);
464 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
466 pln.pln_own = sp->shp_own;
467 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
470 putplane(pln.pln_uid, &pln);
472 if (!take_plane_off_ship(&pln, sp)) {
473 pr("Unable to take plane off ship!\n");
474 logerror("load: plane %d could not be taken off ship %d\n",
475 pln.pln_uid, sp->shp_uid);
478 sprintf(buf, "unloaded in your %s at %s",
479 dchr[sectp->sct_type].d_name,
480 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
481 gift(sectp->sct_own, player->cnum, (s_char *)&pln,
483 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
485 pln.pln_own = sectp->sct_own;
486 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
488 putplane(pln.pln_uid, &pln);
490 pr("%s %s %s at %s.\n",
492 (load_unload == UNLOAD) ?
493 "unloaded from" : "loaded onto",
494 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
502 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
503 int load_unload, int *nshipsp)
505 struct nstr_item pni, ni;
515 if (load_unload == LOAD) {
517 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
518 (mchr[(int)sp->shp_type].m_nland == 0)) {
519 if (sp->shp_nland >= 2) {
520 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
523 /* Eh, let 'em load a spy only */
528 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
530 if (mchr[(int)sp->shp_type].m_nland)
531 pr("%s doesn't have room for any more land units!\n",
534 pr("%s cannot carry land units!\n", prship(sp));
539 sprintf(prompt, "Land unit(s) to %s %s? ",
540 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
542 (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf)))
545 if (!still_ok_ship(sectp, sp))
549 noisy &= isdigit(*p);
551 while (nxtitem(&ni, (s_char *)&land)) {
552 if (land.lnd_own != player->cnum)
555 if (load_unload == LOAD) {
556 if (land.lnd_ship > -1) {
558 pr("%s is already on ship #%d!\n",
559 prland(&land), land.lnd_ship);
562 if (land.lnd_land > -1) {
564 pr("%s is already on land #%d!\n",
565 prland(&land), land.lnd_land);
568 lnd_count_units(&land);
569 if (land.lnd_nland > 0) {
571 pr("%s cannot be loaded since it is carrying units\n",
575 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
577 pr("%s is too heavy to load.\n", prland(&land));
580 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
582 pr("Subs can only carry spy units.\n");
587 /* Unit sanity done */
588 /* Find the right ship */
589 if (load_unload == UNLOAD) {
590 if (land.lnd_ship != sp->shp_uid)
592 if (land.lnd_land > -1)
594 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
597 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
598 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
599 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
601 pr("You can only load light units onto ships,\n");
602 pr("unless the ship is a non-sub supply ship\n");
603 pr("%s not loaded\n", prland(&land));
607 /* Fit unit on ship */
608 if (load_unload == LOAD) {
610 /* We have to check again, since it may have changed */
612 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
613 (mchr[(int)sp->shp_type].m_nland == 0)) {
614 if (sp->shp_nland >= 2) {
615 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
618 /* Eh, let 'em load a spy only */
623 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
625 if (mchr[(int)sp->shp_type].m_nland)
626 pr("%s doesn't have room for any more land units!\n", prship(sp));
628 pr("%s cannot carry land units!\n", prship(sp));
633 if (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland) {
635 if (mchr[(int)sp->shp_type].m_nland)
636 pr("%s doesn't have room for any more land units!\n", prship(sp));
638 pr("%s cannot carry land units!\n", prship(sp));
642 sprintf(buf, "loaded on your %s at %s",
643 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
644 gift(sp->shp_own, player->cnum, (s_char *)&land, EF_LAND, buf);
645 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
647 land.lnd_own = sp->shp_own;
648 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
650 land.lnd_ship = sp->shp_uid;
652 land.lnd_mission = 0;
655 putland(land.lnd_uid, &land);
656 if (!has_supply(&land))
657 pr("WARNING: %s is out of supply!\n", prland(&land));
658 putship(sp->shp_uid, sp);
659 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
660 while (nxtitem(&pni, (s_char *)&plane)) {
661 if (plane.pln_flags & PLN_LAUNCHED)
663 if (plane.pln_land != land.lnd_uid)
665 sprintf(buf, "loaded on %s", prship(sp));
666 gift(sp->shp_own, player->cnum, (s_char *)&plane,
668 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
669 plane.pln_x, plane.pln_y);
670 plane.pln_own = sp->shp_own;
671 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
672 plane.pln_x, plane.pln_y);
673 plane.pln_mission = 0;
674 putplane(plane.pln_uid, &plane);
677 sprintf(buf, "unloaded in your %s at %s",
678 dchr[sectp->sct_type].d_name,
679 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
681 /* Spies are unloaded quietly, others aren't */
682 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
683 gift(sectp->sct_own, player->cnum, (s_char *)&land,
685 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
686 land.lnd_x, land.lnd_y);
687 land.lnd_own = sectp->sct_own;
688 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
689 land.lnd_x, land.lnd_y);
692 land.lnd_ship = (-1);
694 putland(land.lnd_uid, &land);
695 putship(sp->shp_uid, sp);
697 /* Spies are unloaded quietly, others aren't, and
698 in the off chance they can carry a plane (missile?)
699 they are quietly unloaded too. */
700 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
701 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
702 while (nxtitem(&pni, (s_char *)&plane)) {
703 if (plane.pln_flags & PLN_LAUNCHED)
705 if (plane.pln_land != land.lnd_uid)
707 sprintf(buf, "unloaded at %s",
708 xyas(plane.pln_x, plane.pln_y,
710 gift(sectp->sct_own, player->cnum, (s_char *)&plane,
712 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
713 plane.pln_x, plane.pln_y);
714 plane.pln_own = sectp->sct_own;
715 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
716 plane.pln_x, plane.pln_y);
717 plane.pln_mission = 0;
718 putplane(plane.pln_uid, &plane);
722 pr("%s %s %s at %s.\n",
724 (load_unload == UNLOAD) ?
725 "unloaded from" : "loaded onto",
726 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
734 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
735 struct ichrstr *ich, int load_unload, int *nshipsp)
737 register int item = ich->i_vtype;
738 register int max_amt;
739 register int move_amt;
740 register int ship_amt;
741 register int sect_amt;
743 int upto = 0, abs_max;
748 sprintf(prompt, "Number of %s to %s %s at %s? ",
750 (load_unload == UNLOAD) ?
751 "unload from" : "load onto",
752 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
753 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
756 if (!still_ok_ship(sectp, sp))
761 /* We want to load up to this amount */
766 ship_amt = getvar(item, (s_char *)sp, EF_SHIP);
767 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
768 if (sectp->sct_oldown != player->cnum && item == V_CIVIL) {
769 pr("%s civilians refuse to %s at %s!\n",
770 load_unload == UNLOAD ? "Your" : "Foreign",
771 load_unload == UNLOAD ?
772 "disembark" : "board",
773 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
776 if (load_unload == UNLOAD) {
777 abs_max = max_amt = min(9999 - sect_amt, ship_amt);
779 struct mchrstr *vbase;
780 vbase = &mchr[(int)sp->shp_type];
781 abs_max = max_amt = vl_find(item, vbase->m_vtype,
782 vbase->m_vamt, (int)vbase->m_nv);
783 max_amt = min(sect_amt, max_amt - ship_amt);
785 if (max_amt <= 0 && !upto)
788 move_amt = upto - ship_amt;
789 if (move_amt > sect_amt)
791 if (ship_amt + move_amt > abs_max)
792 move_amt = abs_max - ship_amt;
794 move_amt = load_unload * min(amount, max_amt);
798 if (!want_to_abandon(sectp, item, move_amt, 0))
800 if (!still_ok_ship(sectp, sp))
802 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
803 putvar(item, ship_amt + move_amt, (s_char *)sp, EF_SHIP);
804 if (load_unload == LOAD) {
805 pr("%d %s loaded onto %s at %s\n",
808 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
809 if (sp->shp_own != player->cnum) {
810 sprintf(buf, "%s loaded %d %s onto %s at %s\n",
814 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
815 wu(0, sp->shp_own, buf);
818 pr("%d %s unloaded from %s at %s\n",
821 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
822 if (sectp->sct_own != player->cnum) {
823 sprintf(buf, "%s unloaded %d %s from %s at %s\n",
828 xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
829 wu(0, sectp->sct_own, buf);
837 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
838 int load_unload, int *nunitsp)
847 if (!(lchr[(int)lp->lnd_type].l_flags & L_XLIGHT)) {
849 pr("%s cannot carry extra-light planes.\n", prland(lp));
852 count_land_planes(lp);
853 if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) {
855 pr("%s doesn't have room for any more extra-light planes\n",
859 sprintf(prompt, "Plane(s) to %s %s? ",
860 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
862 (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf)))
865 if (!still_ok_land(sectp, lp))
869 noisy &= isdigit(*p);
871 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
872 pr("Sector %s is not yours.\n",
873 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
877 while (nxtitem(&ni, (s_char *)&pln)) {
878 if (pln.pln_own != player->cnum)
881 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
883 pr("You can only load xlight planes onto units.\n");
887 if (load_unload == LOAD && pln.pln_ship > -1) {
889 pr("%s is already on ship #%d!\n",
890 prplane(&pln), pln.pln_ship);
893 if (load_unload == LOAD && pln.pln_land > -1) {
895 pr("%s is already on unit #%d!\n",
896 prplane(&pln), pln.pln_land);
899 /* Plane sanity done */
900 /* Find the right unit */
901 if (load_unload == UNLOAD) {
902 if (pln.pln_land != lp->lnd_uid)
904 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
907 /* Fit plane on unit */
908 if (load_unload == LOAD) {
909 if (!put_plane_on_land(&pln, lp)) {
911 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
914 sprintf(buf, "loaded on %s at %s",
915 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
916 gift(lp->lnd_own, player->cnum, (s_char *)&pln, EF_PLANE, buf);
917 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
919 pln.pln_own = lp->lnd_own;
920 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
922 putplane(pln.pln_uid, &pln);
924 if (!take_plane_off_land(&pln, lp)) {
925 pr("Unable to take plane off unit!\n");
926 logerror("load: plane %d could not be taken off unit %d\n",
927 pln.pln_uid, lp->lnd_uid);
930 sprintf(buf, "unloaded at your sector at %s",
931 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
932 gift(sectp->sct_own, player->cnum, (s_char *)&pln,
934 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
936 pln.pln_own = sectp->sct_own;
937 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
939 putplane(pln.pln_uid, &pln);
941 pr("%s %s %s at %s.\n",
943 (load_unload == UNLOAD) ?
944 "unloaded from" : "loaded onto",
945 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
953 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
954 struct ichrstr *ich, int load_unload, int *nunitsp)
956 register int item = ich->i_vtype;
957 register int max_amt;
958 register int move_amt;
959 register int land_amt;
960 register int sect_amt;
962 int upto = 0, abs_max;
967 sprintf(prompt, "Number of %s to %s %s at %s? ",
969 (load_unload == UNLOAD) ?
970 "unload from" : "load onto",
971 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
972 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
975 if (!still_ok_land(sectp, lp))
980 /* We want to load up to this amount */
986 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
987 pr("Sector %s is not yours.\n",
988 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
992 land_amt = getvar(item, (s_char *)lp, EF_LAND);
993 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
994 if (sectp->sct_oldown != player->cnum && item == V_CIVIL) {
995 pr("%s civilians refuse to %s at %s!\n",
996 load_unload == UNLOAD ? "Your" : "Foreign",
997 load_unload == UNLOAD ?
998 "disembark" : "board",
999 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
1002 if (load_unload == UNLOAD) {
1003 abs_max = max_amt = min(9999 - sect_amt, land_amt);
1005 struct lchrstr *vbase;
1006 vbase = &lchr[(int)lp->lnd_type];
1007 abs_max = max_amt = vl_find(item, vbase->l_vtype,
1008 vbase->l_vamt, (int)vbase->l_nv);
1009 max_amt = min(sect_amt, max_amt - land_amt);
1011 if ((max_amt <= 0) && (upto == 0))
1014 move_amt = upto - land_amt;
1015 if (land_amt + move_amt > abs_max)
1016 move_amt = abs_max - land_amt;
1017 if (move_amt > sect_amt)
1018 move_amt = sect_amt;
1020 move_amt = load_unload * min(amount, max_amt);
1023 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
1024 putvar(item, land_amt + move_amt, (s_char *)lp, EF_LAND);
1026 /* Did we put mils onto this unit? If so, reset the fortification */
1027 if (item == V_MILIT && move_amt > 0)
1029 if (load_unload == LOAD) {
1030 pr("%d %s loaded onto %s at %s\n",
1033 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1034 if (lp->lnd_own != player->cnum) {
1035 sprintf(buf, "%s loaded %d %s onto %s at %s\n",
1036 cname(player->cnum),
1039 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1040 wu(0, lp->lnd_own, buf);
1043 pr("%d %s unloaded from %s at %s\n",
1046 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1047 if (sectp->sct_own != player->cnum) {
1048 sprintf(buf, "%s unloaded %d %s from %s at %s\n",
1049 cname(player->cnum),
1053 xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
1054 wu(0, sectp->sct_own, buf);
1063 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
1064 int load_unload, int *nunitsp)
1066 struct nstr_item pni, ni;
1068 struct plnstr plane;
1074 lnd_count_units(lp);
1076 if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) {
1079 pr("%s doesn't have room for any more land units!\n",
1082 pr("%s cannot carry land units!\n", prland(lp));
1086 sprintf(prompt, "Land unit(s) to %s %s? ",
1087 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
1089 (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf)))
1092 if (!still_ok_land(sectp, lp))
1096 noisy &= isdigit(*p);
1098 while (nxtitem(&ni, (s_char *)&land)) {
1100 if (land.lnd_own != player->cnum)
1103 if (load_unload == LOAD) {
1104 if (land.lnd_ship > -1) {
1106 pr("%s is already on ship #%d!\n",
1107 prland(&land), land.lnd_ship);
1110 if (land.lnd_land > -1) {
1112 pr("%s is already on land #%d!\n",
1113 prland(&land), land.lnd_land);
1116 lnd_count_units(&land);
1117 if (land.lnd_nland > 0) {
1119 pr("%s cannot be loaded since it is carrying units\n",
1123 if (land.lnd_uid == lp->lnd_uid) {
1125 pr("%s can't be loaded onto itself!\n", prland(&land));
1128 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
1130 pr("%s is too heavy to load.\n", prland(&land));
1135 /* Unit sanity done */
1136 /* Find the right ship */
1137 if (load_unload == UNLOAD) {
1138 if (land.lnd_land != lp->lnd_uid)
1140 if (land.lnd_ship > -1)
1142 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
1145 /* Fit unit on ship */
1146 if (load_unload == LOAD) {
1147 lnd_count_units(lp);
1148 if (lp->lnd_nland >= lp->lnd_maxland) {
1151 pr("%s doesn't have room for any more land units!\n", prland(lp));
1153 pr("%s cannot carry land units!\n", prland(lp));
1157 sprintf(buf, "loaded on your %s at %s",
1158 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1159 gift(lp->lnd_own, player->cnum, (s_char *)&land, EF_LAND, buf);
1160 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1162 land.lnd_own = lp->lnd_own;
1163 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1165 land.lnd_land = lp->lnd_uid;
1166 land.lnd_harden = 0;
1167 land.lnd_mission = 0;
1168 resupply_all(&land);
1170 putland(land.lnd_uid, &land);
1171 if (!has_supply(&land))
1172 pr("WARNING: %s is out of supply!\n", prland(&land));
1173 putland(lp->lnd_uid, lp);
1174 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1175 while (nxtitem(&pni, (s_char *)&plane)) {
1176 if (plane.pln_flags & PLN_LAUNCHED)
1178 if (plane.pln_land != land.lnd_uid)
1180 sprintf(buf, "loaded on %s", prland(lp));
1181 gift(lp->lnd_own, player->cnum, (s_char *)&plane,
1183 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1184 plane.pln_x, plane.pln_y);
1185 plane.pln_own = lp->lnd_own;
1186 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1187 plane.pln_x, plane.pln_y);
1188 plane.pln_mission = 0;
1189 putplane(plane.pln_uid, &plane);
1192 sprintf(buf, "unloaded in your %s at %s",
1193 dchr[sectp->sct_type].d_name,
1194 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1195 gift(sectp->sct_own, player->cnum, (s_char *)&land,
1197 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1199 land.lnd_own = sectp->sct_own;
1200 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1202 land.lnd_land = (-1);
1204 putland(land.lnd_uid, &land);
1205 putland(lp->lnd_uid, lp);
1206 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1207 while (nxtitem(&pni, (s_char *)&plane)) {
1208 if (plane.pln_flags & PLN_LAUNCHED)
1210 if (plane.pln_land != land.lnd_uid)
1212 sprintf(buf, "unloaded at %s",
1213 xyas(plane.pln_x, plane.pln_y, sectp->sct_own));
1214 gift(sectp->sct_own, player->cnum, (s_char *)&plane,
1216 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1217 plane.pln_x, plane.pln_y);
1218 plane.pln_own = sectp->sct_own;
1219 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1220 plane.pln_x, plane.pln_y);
1221 plane.pln_mission = 0;
1222 putplane(plane.pln_uid, &plane);
1225 pr("%s %s %s at %s.\n",
1227 (load_unload == UNLOAD) ?
1228 "unloaded from" : "loaded onto",
1229 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));