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 void gift(int givee, int giver, s_char *ptr, int type, s_char *mesg);
59 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
60 int noisy, int load_unload, int *nshipsp);
61 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
62 int noisy, int load_unload, int *nshipsp);
63 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
64 struct ichrstr *ich, int load_unload,
66 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
67 int noisy, int load_unload, int *nunitsp);
68 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
69 int noisy, int load_unload, int *nunitsp);
70 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
71 struct ichrstr *ich, int load_unload,
80 struct nstr_item nbst;
89 if (!(p = getstarg(player->argp[1],
90 "What commodity (or 'plane' or 'land')? ", buf))
94 if (!strncmp(p, "plane", 5))
96 else if (!strncmp(p, "land", 4))
98 else if (NULL != (ich = whatitem(p, (s_char *)0)))
101 pr("Bad commodity.\n");
105 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
110 if (!snxtitem(&nbst, EF_SHIP, p))
113 nbst.flags &= ~(EFF_OWNER);
115 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
118 while (nxtitem(&nbst, (s_char *)&ship)) {
121 if (!player->owner && (load_unload == UNLOAD)) {
125 if (ontradingblock(EF_SHIP, (int *)&ship)) {
126 pr("You cannot load/unload an item on the trading block!\n");
131 if (ship.shp_own != player->cnum) {
134 if (getrel(getnatp(player->cnum), ship.shp_own) < FRIENDLY)
137 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
139 if ((sect.sct_own != player->cnum) &&
140 (ship.shp_own != player->cnum))
142 if (!player->owner &&
143 sect.sct_type != SCT_HARBR &&
144 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT))
148 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
150 pr("You don't own %s \n",
151 xyas(ship.shp_x, ship.shp_y, player->cnum));
154 if (sect.sct_type != SCT_HARBR &&
155 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) {
157 pr("Sector %s is not a harbor%s.\n",
158 xyas(ship.shp_x, ship.shp_y, player->cnum),
159 opt_BIG_CITY ? " or a city" : "");
162 if (sect.sct_own != player->cnum && load_unload == UNLOAD
163 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
165 pr("You can't unload into an unfriendly %s\n",
166 dchr[sect.sct_type].d_name);
169 if (sect.sct_effic < 2) {
171 pr("The %s at %s is not 2%% efficient yet.\n",
172 dchr[sect.sct_type].d_name,
173 xyas(ship.shp_x, ship.shp_y, player->cnum));
180 load_plane_ship(§, &ship, noisy, load_unload,
187 load_land_ship(§, &ship, noisy, load_unload,
194 load_comm_ship(§, &ship, ich, load_unload, &nships)))
197 /* load/unload plague */
198 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
199 getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY)
200 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
201 if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_INFECT &&
202 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
203 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
205 putship(ship.shp_uid, &ship);
208 pr("No ships affected\n");
210 pr("%d ship%s %sloaded\n", nships, splur(nships),
211 load_unload == UNLOAD ? "un" : "");
221 struct nstr_item nbst;
230 if (!(p = getstarg(player->argp[1],
231 "What commodity (or 'plane' or 'land')? ", buf))
234 if (!strncmp(p, "plane", 5))
236 else if (!strncmp(p, "land", 4))
238 else if (NULL != (ich = whatitem(p, (s_char *)0)))
241 pr("Bad commodity.\n");
245 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
250 if (!snxtitem(&nbst, EF_LAND, p))
253 load_unload = *(*player->argp + 1) == 'l' ? LOAD : UNLOAD;
255 nbst.flags &= ~(EFF_OWNER);
258 while (nxtitem(&nbst, (s_char *)&land)) {
259 if (land.lnd_own == 0)
262 if (player->cnum != land.lnd_own &&
263 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
266 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
269 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
272 if (ontradingblock(EF_LAND, (int *)&land)) {
273 pr("You cannot load/unload an item on the trading block!\n");
278 if (sect.sct_own != player->cnum &&
279 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
280 pr("Sector %s is not yours.\n",
281 xyas(land.lnd_x, land.lnd_y, player->cnum));
288 load_land_land(§, &land, noisy, load_unload,
295 load_plane_land(§, &land, noisy, load_unload,
302 load_comm_land(§, &land, ich, load_unload, &nunits)))
305 /* load/unload plague */
306 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
307 getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY)
308 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
309 if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_INFECT &&
310 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
311 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
314 putland(land.lnd_uid, &land);
317 pr("No units affected\n");
319 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
320 load_unload == UNLOAD ? "un" : "");
325 gift(int givee, int giver, s_char *ptr, int type, s_char *mesg)
327 s_char *p, line[256];
335 p = prship((struct shpstr *)ptr);
338 p = prplane((struct plnstr *)ptr);
341 p = prland((struct lndstr *)ptr);
345 sprintf(line, "%s %s %s\n", cname(giver), p, mesg);
350 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
352 if (!check_sect_ok(sectp))
354 if (!check_ship_ok(shipp))
360 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
362 if (!check_sect_ok(sectp))
364 if (!check_land_ok(landp))
370 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
371 int load_unload, int *nshipsp)
379 struct mchrstr *mcp = mchr + sp->shp_type;
381 if (!(mcp->m_flags & (M_CHOPPER | M_XLIGHT | M_FLY | M_MSL))) {
383 pr("%s cannot carry planes\n", prship(sp));
387 if (load_unload == LOAD &&
388 sp->shp_nchoppers >= mcp->m_nchoppers &&
389 sp->shp_nxlight >= mcp->m_nxlight &&
390 sp->shp_nplane >= mcp->m_nplanes) {
392 pr("%s doesn't have room for any more planes\n", prship(sp));
395 sprintf(prompt, "Plane(s) to %s %s? ",
396 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
398 (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf)))
401 if (!still_ok_ship(sectp, sp))
405 noisy &= isdigit(*p);
407 while (nxtitem(&ni, (s_char *)&pln)) {
408 if (pln.pln_own != player->cnum)
410 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
411 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
412 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
413 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
416 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
419 if (load_unload == LOAD && pln.pln_ship > -1) {
421 pr("%s is already on ship #%d!\n",
422 prplane(&pln), pln.pln_ship);
425 if (load_unload == LOAD && pln.pln_land > -1) {
427 pr("%s is already on land unit #%d!\n",
428 prplane(&pln), pln.pln_land);
432 /* Plane sanity done */
433 /* Find the right ship */
434 if (load_unload == UNLOAD) {
435 if (pln.pln_ship != sp->shp_uid)
437 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
440 /* ship to (plane or missle) sanity */
441 if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) {
442 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
443 strcpy(buf, "planes");
444 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
445 strcpy(buf, "choppers");
446 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
447 strcpy(buf, "missiles");
448 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
449 strcpy(buf, "extra light planes");
450 } /* else impossible */
452 pr("%s cannot carry %s.\n", prship(sp), buf);
455 /* Fit plane on ship */
456 if (load_unload == LOAD) {
457 if (!put_plane_on_ship(&pln, sp)) {
459 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
462 sprintf(buf, "loaded on your %s at %s",
463 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
464 gift(sp->shp_own, player->cnum, (s_char *)&pln, EF_PLANE, buf);
465 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
467 pln.pln_own = sp->shp_own;
468 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
471 putplane(pln.pln_uid, &pln);
473 if (!take_plane_off_ship(&pln, sp)) {
474 pr("Unable to take plane off ship!\n");
475 logerror("load: plane %d could not be taken off ship %d\n",
476 pln.pln_uid, sp->shp_uid);
479 sprintf(buf, "unloaded in your %s at %s",
480 dchr[sectp->sct_type].d_name,
481 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
482 gift(sectp->sct_own, player->cnum, (s_char *)&pln,
484 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
486 pln.pln_own = sectp->sct_own;
487 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
489 putplane(pln.pln_uid, &pln);
491 pr("%s %s %s at %s.\n",
493 (load_unload == UNLOAD) ?
494 "unloaded from" : "loaded onto",
495 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
503 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
504 int load_unload, int *nshipsp)
506 struct nstr_item pni, ni;
516 if (load_unload == LOAD) {
518 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
519 (mchr[(int)sp->shp_type].m_nland == 0)) {
520 if (sp->shp_nland >= 2) {
521 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
524 /* Eh, let 'em load a spy only */
529 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
531 if (mchr[(int)sp->shp_type].m_nland)
532 pr("%s doesn't have room for any more land units!\n",
535 pr("%s cannot carry land units!\n", prship(sp));
540 sprintf(prompt, "Land unit(s) to %s %s? ",
541 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
543 (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf)))
546 if (!still_ok_ship(sectp, sp))
550 noisy &= isdigit(*p);
552 while (nxtitem(&ni, (s_char *)&land)) {
553 if (land.lnd_own != player->cnum)
556 if (load_unload == LOAD) {
557 if (land.lnd_ship > -1) {
559 pr("%s is already on ship #%d!\n",
560 prland(&land), land.lnd_ship);
563 if (land.lnd_land > -1) {
565 pr("%s is already on land #%d!\n",
566 prland(&land), land.lnd_land);
569 lnd_count_units(&land);
570 if (land.lnd_nland > 0) {
572 pr("%s cannot be loaded since it is carrying units\n",
576 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
578 pr("%s is too heavy to load.\n", prland(&land));
581 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
583 pr("Subs can only carry spy units.\n");
588 /* Unit sanity done */
589 /* Find the right ship */
590 if (load_unload == UNLOAD) {
591 if (land.lnd_ship != sp->shp_uid)
593 if (land.lnd_land > -1)
595 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
598 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
599 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
600 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
602 pr("You can only load light units onto ships,\n");
603 pr("unless the ship is a non-sub supply ship\n");
604 pr("%s not loaded\n", prland(&land));
608 /* Fit unit on ship */
609 if (load_unload == LOAD) {
611 /* We have to check again, since it may have changed */
613 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
614 (mchr[(int)sp->shp_type].m_nland == 0)) {
615 if (sp->shp_nland >= 2) {
616 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
619 /* Eh, let 'em load a spy only */
624 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
626 if (mchr[(int)sp->shp_type].m_nland)
627 pr("%s doesn't have room for any more land units!\n", prship(sp));
629 pr("%s cannot carry land units!\n", prship(sp));
634 if (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland) {
636 if (mchr[(int)sp->shp_type].m_nland)
637 pr("%s doesn't have room for any more land units!\n", prship(sp));
639 pr("%s cannot carry land units!\n", prship(sp));
643 sprintf(buf, "loaded on your %s at %s",
644 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
645 gift(sp->shp_own, player->cnum, (s_char *)&land, EF_LAND, buf);
646 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
648 land.lnd_own = sp->shp_own;
649 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
651 land.lnd_ship = sp->shp_uid;
653 land.lnd_mission = 0;
656 putland(land.lnd_uid, &land);
657 if (!has_supply(&land))
658 pr("WARNING: %s is out of supply!\n", prland(&land));
659 putship(sp->shp_uid, sp);
660 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
661 while (nxtitem(&pni, (s_char *)&plane)) {
662 if (plane.pln_flags & PLN_LAUNCHED)
664 if (plane.pln_land != land.lnd_uid)
666 sprintf(buf, "loaded on %s", prship(sp));
667 gift(sp->shp_own, player->cnum, (s_char *)&plane,
669 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
670 plane.pln_x, plane.pln_y);
671 plane.pln_own = sp->shp_own;
672 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
673 plane.pln_x, plane.pln_y);
674 plane.pln_mission = 0;
675 putplane(plane.pln_uid, &plane);
678 sprintf(buf, "unloaded in your %s at %s",
679 dchr[sectp->sct_type].d_name,
680 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
682 /* Spies are unloaded quietly, others aren't */
683 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
684 gift(sectp->sct_own, player->cnum, (s_char *)&land,
686 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
687 land.lnd_x, land.lnd_y);
688 land.lnd_own = sectp->sct_own;
689 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
690 land.lnd_x, land.lnd_y);
693 land.lnd_ship = (-1);
695 putland(land.lnd_uid, &land);
696 putship(sp->shp_uid, sp);
698 /* Spies are unloaded quietly, others aren't, and
699 in the off chance they can carry a plane (missile?)
700 they are quietly unloaded too. */
701 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
702 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
703 while (nxtitem(&pni, (s_char *)&plane)) {
704 if (plane.pln_flags & PLN_LAUNCHED)
706 if (plane.pln_land != land.lnd_uid)
708 sprintf(buf, "unloaded at %s",
709 xyas(plane.pln_x, plane.pln_y,
711 gift(sectp->sct_own, player->cnum, (s_char *)&plane,
713 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
714 plane.pln_x, plane.pln_y);
715 plane.pln_own = sectp->sct_own;
716 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
717 plane.pln_x, plane.pln_y);
718 plane.pln_mission = 0;
719 putplane(plane.pln_uid, &plane);
723 pr("%s %s %s at %s.\n",
725 (load_unload == UNLOAD) ?
726 "unloaded from" : "loaded onto",
727 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
735 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
736 struct ichrstr *ich, int load_unload, int *nshipsp)
738 register int item = ich->i_vtype;
739 register int max_amt;
740 register int move_amt;
741 register int ship_amt;
742 register int sect_amt;
744 int upto = 0, abs_max;
749 sprintf(prompt, "Number of %s to %s %s at %s? ",
751 (load_unload == UNLOAD) ?
752 "unload from" : "load onto",
753 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
754 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
757 if (!still_ok_ship(sectp, sp))
762 /* We want to load up to this amount */
767 ship_amt = getvar(item, (s_char *)sp, EF_SHIP);
768 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
769 if (sectp->sct_oldown != player->cnum && item == V_CIVIL) {
770 pr("%s civilians refuse to %s at %s!\n",
771 load_unload == UNLOAD ? "Your" : "Foreign",
772 load_unload == UNLOAD ?
773 "disembark" : "board",
774 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
777 if (load_unload == UNLOAD) {
778 abs_max = max_amt = min(9999 - sect_amt, ship_amt);
780 struct mchrstr *vbase;
781 vbase = &mchr[(int)sp->shp_type];
782 abs_max = max_amt = vl_find(item, vbase->m_vtype,
783 vbase->m_vamt, (int)vbase->m_nv);
784 max_amt = min(sect_amt, max_amt - ship_amt);
786 if (max_amt <= 0 && !upto)
789 move_amt = upto - ship_amt;
790 if (move_amt > sect_amt)
792 if (ship_amt + move_amt > abs_max)
793 move_amt = abs_max - ship_amt;
795 move_amt = load_unload * min(amount, max_amt);
799 if (!want_to_abandon(sectp, item, move_amt, 0))
801 if (!still_ok_ship(sectp, sp))
803 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
804 putvar(item, ship_amt + move_amt, (s_char *)sp, EF_SHIP);
805 if (load_unload == LOAD) {
806 pr("%d %s loaded onto %s at %s\n",
809 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
810 if (sp->shp_own != player->cnum) {
811 sprintf(buf, "%s loaded %d %s onto %s at %s\n",
815 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
816 wu(0, sp->shp_own, buf);
819 pr("%d %s unloaded from %s at %s\n",
822 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
823 if (sectp->sct_own != player->cnum) {
824 sprintf(buf, "%s unloaded %d %s from %s at %s\n",
829 xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
830 wu(0, sectp->sct_own, buf);
838 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
839 int load_unload, int *nunitsp)
848 if (!(lchr[(int)lp->lnd_type].l_flags & L_XLIGHT)) {
850 pr("%s cannot carry extra-light planes.\n", prland(lp));
853 count_land_planes(lp);
854 if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) {
856 pr("%s doesn't have room for any more extra-light planes\n",
860 sprintf(prompt, "Plane(s) to %s %s? ",
861 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
863 (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf)))
866 if (!still_ok_land(sectp, lp))
870 noisy &= isdigit(*p);
872 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
873 pr("Sector %s is not yours.\n",
874 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
878 while (nxtitem(&ni, (s_char *)&pln)) {
879 if (pln.pln_own != player->cnum)
882 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
884 pr("You can only load xlight planes onto units.\n");
888 if (load_unload == LOAD && pln.pln_ship > -1) {
890 pr("%s is already on ship #%d!\n",
891 prplane(&pln), pln.pln_ship);
894 if (load_unload == LOAD && pln.pln_land > -1) {
896 pr("%s is already on unit #%d!\n",
897 prplane(&pln), pln.pln_land);
900 /* Plane sanity done */
901 /* Find the right unit */
902 if (load_unload == UNLOAD) {
903 if (pln.pln_land != lp->lnd_uid)
905 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
908 /* Fit plane on unit */
909 if (load_unload == LOAD) {
910 if (!put_plane_on_land(&pln, lp)) {
912 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
915 sprintf(buf, "loaded on %s at %s",
916 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
917 gift(lp->lnd_own, player->cnum, (s_char *)&pln, EF_PLANE, buf);
918 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
920 pln.pln_own = lp->lnd_own;
921 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
923 putplane(pln.pln_uid, &pln);
925 if (!take_plane_off_land(&pln, lp)) {
926 pr("Unable to take plane off unit!\n");
927 logerror("load: plane %d could not be taken off unit %d\n",
928 pln.pln_uid, lp->lnd_uid);
931 sprintf(buf, "unloaded at your sector at %s",
932 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
933 gift(sectp->sct_own, player->cnum, (s_char *)&pln,
935 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
937 pln.pln_own = sectp->sct_own;
938 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
940 putplane(pln.pln_uid, &pln);
942 pr("%s %s %s at %s.\n",
944 (load_unload == UNLOAD) ?
945 "unloaded from" : "loaded onto",
946 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
954 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
955 struct ichrstr *ich, int load_unload, int *nunitsp)
957 register int item = ich->i_vtype;
958 register int max_amt;
959 register int move_amt;
960 register int land_amt;
961 register int sect_amt;
963 int upto = 0, abs_max;
968 sprintf(prompt, "Number of %s to %s %s at %s? ",
970 (load_unload == UNLOAD) ?
971 "unload from" : "load onto",
972 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
973 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
976 if (!still_ok_land(sectp, lp))
981 /* We want to load up to this amount */
987 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
988 pr("Sector %s is not yours.\n",
989 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
993 land_amt = getvar(item, (s_char *)lp, EF_LAND);
994 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
995 if (sectp->sct_oldown != player->cnum && item == V_CIVIL) {
996 pr("%s civilians refuse to %s at %s!\n",
997 load_unload == UNLOAD ? "Your" : "Foreign",
998 load_unload == UNLOAD ?
999 "disembark" : "board",
1000 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
1003 if (load_unload == UNLOAD) {
1004 abs_max = max_amt = min(9999 - sect_amt, land_amt);
1006 struct lchrstr *vbase;
1007 vbase = &lchr[(int)lp->lnd_type];
1008 abs_max = max_amt = vl_find(item, vbase->l_vtype,
1009 vbase->l_vamt, (int)vbase->l_nv);
1010 max_amt = min(sect_amt, max_amt - land_amt);
1012 if ((max_amt <= 0) && (upto == 0))
1015 move_amt = upto - land_amt;
1016 if (land_amt + move_amt > abs_max)
1017 move_amt = abs_max - land_amt;
1018 if (move_amt > sect_amt)
1019 move_amt = sect_amt;
1021 move_amt = load_unload * min(amount, max_amt);
1024 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
1025 putvar(item, land_amt + move_amt, (s_char *)lp, EF_LAND);
1027 /* Did we put mils onto this unit? If so, reset the fortification */
1028 if (item == V_MILIT && move_amt > 0)
1030 if (load_unload == LOAD) {
1031 pr("%d %s loaded onto %s at %s\n",
1034 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1035 if (lp->lnd_own != player->cnum) {
1036 sprintf(buf, "%s loaded %d %s onto %s at %s\n",
1037 cname(player->cnum),
1040 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1041 wu(0, lp->lnd_own, buf);
1044 pr("%d %s unloaded from %s at %s\n",
1047 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1048 if (sectp->sct_own != player->cnum) {
1049 sprintf(buf, "%s unloaded %d %s from %s at %s\n",
1050 cname(player->cnum),
1054 xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
1055 wu(0, sectp->sct_own, buf);
1064 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
1065 int load_unload, int *nunitsp)
1067 struct nstr_item pni, ni;
1069 struct plnstr plane;
1075 lnd_count_units(lp);
1077 if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) {
1080 pr("%s doesn't have room for any more land units!\n",
1083 pr("%s cannot carry land units!\n", prland(lp));
1087 sprintf(prompt, "Land unit(s) to %s %s? ",
1088 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
1090 (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf)))
1093 if (!still_ok_land(sectp, lp))
1097 noisy &= isdigit(*p);
1099 while (nxtitem(&ni, (s_char *)&land)) {
1101 if (land.lnd_own != player->cnum)
1104 if (load_unload == LOAD) {
1105 if (land.lnd_ship > -1) {
1107 pr("%s is already on ship #%d!\n",
1108 prland(&land), land.lnd_ship);
1111 if (land.lnd_land > -1) {
1113 pr("%s is already on land #%d!\n",
1114 prland(&land), land.lnd_land);
1117 lnd_count_units(&land);
1118 if (land.lnd_nland > 0) {
1120 pr("%s cannot be loaded since it is carrying units\n",
1124 if (land.lnd_uid == lp->lnd_uid) {
1126 pr("%s can't be loaded onto itself!\n", prland(&land));
1129 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
1131 pr("%s is too heavy to load.\n", prland(&land));
1136 /* Unit sanity done */
1137 /* Find the right ship */
1138 if (load_unload == UNLOAD) {
1139 if (land.lnd_land != lp->lnd_uid)
1141 if (land.lnd_ship > -1)
1143 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
1146 /* Fit unit on ship */
1147 if (load_unload == LOAD) {
1148 lnd_count_units(lp);
1149 if (lp->lnd_nland >= lp->lnd_maxland) {
1152 pr("%s doesn't have room for any more land units!\n", prland(lp));
1154 pr("%s cannot carry land units!\n", prland(lp));
1158 sprintf(buf, "loaded on your %s at %s",
1159 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1160 gift(lp->lnd_own, player->cnum, (s_char *)&land, EF_LAND, buf);
1161 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1163 land.lnd_own = lp->lnd_own;
1164 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1166 land.lnd_land = lp->lnd_uid;
1167 land.lnd_harden = 0;
1168 land.lnd_mission = 0;
1169 resupply_all(&land);
1171 putland(land.lnd_uid, &land);
1172 if (!has_supply(&land))
1173 pr("WARNING: %s is out of supply!\n", prland(&land));
1174 putland(lp->lnd_uid, lp);
1175 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1176 while (nxtitem(&pni, (s_char *)&plane)) {
1177 if (plane.pln_flags & PLN_LAUNCHED)
1179 if (plane.pln_land != land.lnd_uid)
1181 sprintf(buf, "loaded on %s", prland(lp));
1182 gift(lp->lnd_own, player->cnum, (s_char *)&plane,
1184 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1185 plane.pln_x, plane.pln_y);
1186 plane.pln_own = lp->lnd_own;
1187 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1188 plane.pln_x, plane.pln_y);
1189 plane.pln_mission = 0;
1190 putplane(plane.pln_uid, &plane);
1193 sprintf(buf, "unloaded in your %s at %s",
1194 dchr[sectp->sct_type].d_name,
1195 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1196 gift(sectp->sct_own, player->cnum, (s_char *)&land,
1198 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1200 land.lnd_own = sectp->sct_own;
1201 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1203 land.lnd_land = (-1);
1205 putland(land.lnd_uid, &land);
1206 putland(lp->lnd_uid, lp);
1207 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1208 while (nxtitem(&pni, (s_char *)&plane)) {
1209 if (plane.pln_flags & PLN_LAUNCHED)
1211 if (plane.pln_land != land.lnd_uid)
1213 sprintf(buf, "unloaded at %s",
1214 xyas(plane.pln_x, plane.pln_y, sectp->sct_own));
1215 gift(sectp->sct_own, player->cnum, (s_char *)&plane,
1217 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1218 plane.pln_x, plane.pln_y);
1219 plane.pln_own = sectp->sct_own;
1220 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1221 plane.pln_x, plane.pln_y);
1222 plane.pln_mission = 0;
1223 putplane(plane.pln_uid, &plane);
1226 pr("%s %s %s at %s.\n",
1228 (load_unload == UNLOAD) ?
1229 "unloaded from" : "loaded onto",
1230 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));