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
55 * The values 1 and -1 are important below, don't change them.
60 void gift(int givee, int giver, s_char *ptr, int type, s_char *mesg);
61 static int load_plane_ship(struct sctstr *sectp, struct shpstr *sp,
62 int noisy, int load_unload, int *nshipsp);
63 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp,
64 int noisy, int load_unload, int *nshipsp);
65 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
66 struct ichrstr *ich, int load_unload,
68 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp,
69 int noisy, int load_unload, int *nunitsp);
70 static int load_land_land(struct sctstr *sectp, struct lndstr *lp,
71 int noisy, int load_unload, int *nunitsp);
72 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp,
73 struct ichrstr *ich, int load_unload,
82 struct nstr_item nbst;
91 if (!(p = getstarg(player->argp[1],
92 "What commodity (or 'plane' or 'land')? ", buf))
96 if (!strncmp(p, "plane", 5))
98 else if (!strncmp(p, "land", 4))
100 else if (NULL != (ich = whatitem(p, (s_char *)0)))
103 pr("Bad commodity.\n");
107 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
112 if (!snxtitem(&nbst, EF_SHIP, p))
115 nbst.flags &= ~(EFF_OWNER);
117 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
120 while (nxtitem(&nbst, (s_char *)&ship)) {
123 if (!player->owner && (load_unload == UNLOAD)) {
127 if (ontradingblock(EF_SHIP, (int *)&ship)) {
128 pr("You cannot load/unload an item on the trading block!\n");
133 if (ship.shp_own != player->cnum) {
136 if (getrel(getnatp(player->cnum), ship.shp_own) < FRIENDLY)
139 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
141 if ((sect.sct_own != player->cnum) &&
142 (ship.shp_own != player->cnum))
144 if (!player->owner &&
145 sect.sct_type != SCT_HARBR &&
146 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT))
150 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
152 pr("You don't own %s \n",
153 xyas(ship.shp_x, ship.shp_y, player->cnum));
156 if (sect.sct_type != SCT_HARBR &&
157 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) {
159 pr("Sector %s is not a harbor%s.\n",
160 xyas(ship.shp_x, ship.shp_y, player->cnum),
161 opt_BIG_CITY ? " or a city" : "");
164 if (sect.sct_own != player->cnum && load_unload == UNLOAD
165 && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
167 pr("You can't unload into an unfriendly %s\n",
168 dchr[sect.sct_type].d_name);
171 if (sect.sct_effic < 2) {
173 pr("The %s at %s is not 2%% efficient yet.\n",
174 dchr[sect.sct_type].d_name,
175 xyas(ship.shp_x, ship.shp_y, player->cnum));
182 load_plane_ship(§, &ship, noisy, load_unload,
189 load_land_ship(§, &ship, noisy, load_unload,
196 load_comm_ship(§, &ship, ich, load_unload, &nships)))
199 /* load/unload plague */
200 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
201 getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY)
202 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
203 if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_INFECT &&
204 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
205 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
207 putship(ship.shp_uid, &ship);
210 pr("No ships affected\n");
212 pr("%d ship%s %sloaded\n", nships, splur(nships),
213 load_unload == UNLOAD ? "un" : "");
223 struct nstr_item nbst;
232 if (!(p = getstarg(player->argp[1],
233 "What commodity (or 'plane' or 'land')? ", buf))
236 if (!strncmp(p, "plane", 5))
238 else if (!strncmp(p, "land", 4))
240 else if (NULL != (ich = whatitem(p, (s_char *)0)))
243 pr("Bad commodity.\n");
247 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
252 if (!snxtitem(&nbst, EF_LAND, p))
255 load_unload = *(*player->argp + 1) == 'l' ? LOAD : UNLOAD;
257 nbst.flags &= ~(EFF_OWNER);
260 while (nxtitem(&nbst, (s_char *)&land)) {
261 if (land.lnd_own == 0)
264 if (player->cnum != land.lnd_own &&
265 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
268 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
271 if (sect.sct_own != player->cnum && land.lnd_own != player->cnum)
274 if (ontradingblock(EF_LAND, (int *)&land)) {
275 pr("You cannot load/unload an item on the trading block!\n");
280 if (sect.sct_own != player->cnum &&
281 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
282 pr("Sector %s is not yours.\n",
283 xyas(land.lnd_x, land.lnd_y, player->cnum));
290 load_land_land(§, &land, noisy, load_unload,
297 load_plane_land(§, &land, noisy, load_unload,
304 load_comm_land(§, &land, ich, load_unload, &nunits)))
307 /* load/unload plague */
308 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
309 getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY)
310 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
311 if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_INFECT &&
312 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
313 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
316 putland(land.lnd_uid, &land);
319 pr("No units affected\n");
321 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
322 load_unload == UNLOAD ? "un" : "");
327 gift(int givee, int giver, s_char *ptr, int type, s_char *mesg)
329 s_char *p, line[256];
337 p = prship((struct shpstr *)ptr);
340 p = prplane((struct plnstr *)ptr);
343 p = prland((struct lndstr *)ptr);
347 sprintf(line, "%s %s %s\n", cname(giver), p, mesg);
352 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
354 if (!check_sect_ok(sectp))
356 if (!check_ship_ok(shipp))
362 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
364 if (!check_sect_ok(sectp))
366 if (!check_land_ok(landp))
372 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
373 int load_unload, int *nshipsp)
381 struct mchrstr *mcp = mchr + sp->shp_type;
383 if (!(mcp->m_flags & (M_CHOPPER | M_XLIGHT | M_FLY | M_MSL))) {
385 pr("%s cannot carry planes\n", prship(sp));
389 if (load_unload == LOAD &&
390 sp->shp_nchoppers >= mcp->m_nchoppers &&
391 sp->shp_nxlight >= mcp->m_nxlight &&
392 sp->shp_nplane >= mcp->m_nplanes) {
394 pr("%s doesn't have room for any more planes\n", prship(sp));
397 sprintf(prompt, "Plane(s) to %s %s? ",
398 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
400 (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf)))
403 if (!still_ok_ship(sectp, sp))
407 noisy &= isdigit(*p);
409 while (nxtitem(&ni, (s_char *)&pln)) {
410 if (pln.pln_own != player->cnum)
412 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
413 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
414 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
415 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
418 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
421 if (load_unload == LOAD && pln.pln_ship > -1) {
423 pr("%s is already on ship #%d!\n",
424 prplane(&pln), pln.pln_ship);
427 if (load_unload == LOAD && pln.pln_land > -1) {
429 pr("%s is already on land unit #%d!\n",
430 prplane(&pln), pln.pln_land);
434 /* Plane sanity done */
435 /* Find the right ship */
436 if (load_unload == UNLOAD) {
437 if (pln.pln_ship != sp->shp_uid)
439 } else if (sp->shp_x != pln.pln_x || sp->shp_y != pln.pln_y)
442 /* ship to (plane or missle) sanity */
443 if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) {
444 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
445 strcpy(buf, "planes");
446 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
447 strcpy(buf, "choppers");
448 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
449 strcpy(buf, "missiles");
450 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
451 strcpy(buf, "extra light planes");
452 } /* else impossible */
454 pr("%s cannot carry %s.\n", prship(sp), buf);
457 /* Fit plane on ship */
458 if (load_unload == LOAD) {
459 if (!put_plane_on_ship(&pln, sp)) {
461 pr("Can't put plane %d on this ship!\n", pln.pln_uid);
464 sprintf(buf, "loaded on your %s at %s",
465 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
466 gift(sp->shp_own, player->cnum, (s_char *)&pln, EF_PLANE, buf);
467 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
469 pln.pln_own = sp->shp_own;
470 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
473 putplane(pln.pln_uid, &pln);
475 if (!take_plane_off_ship(&pln, sp)) {
476 pr("Unable to take plane off ship!\n");
477 logerror("load: plane %d could not be taken off ship %d\n",
478 pln.pln_uid, sp->shp_uid);
481 sprintf(buf, "unloaded in your %s at %s",
482 dchr[sectp->sct_type].d_name,
483 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
484 gift(sectp->sct_own, player->cnum, (s_char *)&pln,
486 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
488 pln.pln_own = sectp->sct_own;
489 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
491 putplane(pln.pln_uid, &pln);
493 pr("%s %s %s at %s.\n",
495 (load_unload == UNLOAD) ?
496 "unloaded from" : "loaded onto",
497 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
505 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy,
506 int load_unload, int *nshipsp)
508 struct nstr_item pni, ni;
518 if (load_unload == LOAD) {
520 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
521 (mchr[(int)sp->shp_type].m_nland == 0)) {
522 if (sp->shp_nland >= 2) {
523 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
526 /* Eh, let 'em load a spy only */
531 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
533 if (mchr[(int)sp->shp_type].m_nland)
534 pr("%s doesn't have room for any more land units!\n",
537 pr("%s cannot carry land units!\n", prship(sp));
542 sprintf(prompt, "Land unit(s) to %s %s? ",
543 load_unload == LOAD ? "load onto" : "unload from", prship(sp));
545 (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf)))
548 if (!still_ok_ship(sectp, sp))
552 noisy &= isdigit(*p);
554 while (nxtitem(&ni, (s_char *)&land)) {
555 if (land.lnd_own != player->cnum)
558 if (load_unload == LOAD) {
559 if (land.lnd_ship > -1) {
561 pr("%s is already on ship #%d!\n",
562 prland(&land), land.lnd_ship);
565 if (land.lnd_land > -1) {
567 pr("%s is already on land #%d!\n",
568 prland(&land), land.lnd_land);
571 lnd_count_units(&land);
572 if (land.lnd_nland > 0) {
574 pr("%s cannot be loaded since it is carrying units\n",
578 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
580 pr("%s is too heavy to load.\n", prland(&land));
583 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
585 pr("Subs can only carry spy units.\n");
590 /* Unit sanity done */
591 /* Find the right ship */
592 if (load_unload == UNLOAD) {
593 if (land.lnd_ship != sp->shp_uid)
595 if (land.lnd_land > -1)
597 } else if (sp->shp_x != land.lnd_x || sp->shp_y != land.lnd_y)
600 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
601 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
602 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
604 pr("You can only load light units onto ships,\n");
605 pr("unless the ship is a non-sub supply ship\n");
606 pr("%s not loaded\n", prland(&land));
610 /* Fit unit on ship */
611 if (load_unload == LOAD) {
613 /* We have to check again, since it may have changed */
615 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
616 (mchr[(int)sp->shp_type].m_nland == 0)) {
617 if (sp->shp_nland >= 2) {
618 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
621 /* Eh, let 'em load a spy only */
626 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
628 if (mchr[(int)sp->shp_type].m_nland)
629 pr("%s doesn't have room for any more land units!\n", prship(sp));
631 pr("%s cannot carry land units!\n", prship(sp));
636 if (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland) {
638 if (mchr[(int)sp->shp_type].m_nland)
639 pr("%s doesn't have room for any more land units!\n", prship(sp));
641 pr("%s cannot carry land units!\n", prship(sp));
645 sprintf(buf, "loaded on your %s at %s",
646 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
647 gift(sp->shp_own, player->cnum, (s_char *)&land, EF_LAND, buf);
648 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
650 land.lnd_own = sp->shp_own;
651 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
653 land.lnd_ship = sp->shp_uid;
655 land.lnd_mission = 0;
658 putland(land.lnd_uid, &land);
659 if (!has_supply(&land))
660 pr("WARNING: %s is out of supply!\n", prland(&land));
661 putship(sp->shp_uid, sp);
662 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
663 while (nxtitem(&pni, (s_char *)&plane)) {
664 if (plane.pln_flags & PLN_LAUNCHED)
666 if (plane.pln_land != land.lnd_uid)
668 sprintf(buf, "loaded on %s", prship(sp));
669 gift(sp->shp_own, player->cnum, (s_char *)&plane,
671 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
672 plane.pln_x, plane.pln_y);
673 plane.pln_own = sp->shp_own;
674 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
675 plane.pln_x, plane.pln_y);
676 plane.pln_mission = 0;
677 putplane(plane.pln_uid, &plane);
680 sprintf(buf, "unloaded in your %s at %s",
681 dchr[sectp->sct_type].d_name,
682 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
684 /* Spies are unloaded quietly, others aren't */
685 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
686 gift(sectp->sct_own, player->cnum, (s_char *)&land,
688 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
689 land.lnd_x, land.lnd_y);
690 land.lnd_own = sectp->sct_own;
691 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
692 land.lnd_x, land.lnd_y);
695 land.lnd_ship = (-1);
697 putland(land.lnd_uid, &land);
698 putship(sp->shp_uid, sp);
700 /* Spies are unloaded quietly, others aren't, and
701 in the off chance they can carry a plane (missile?)
702 they are quietly unloaded too. */
703 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
704 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
705 while (nxtitem(&pni, (s_char *)&plane)) {
706 if (plane.pln_flags & PLN_LAUNCHED)
708 if (plane.pln_land != land.lnd_uid)
710 sprintf(buf, "unloaded at %s",
711 xyas(plane.pln_x, plane.pln_y,
713 gift(sectp->sct_own, player->cnum, (s_char *)&plane,
715 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
716 plane.pln_x, plane.pln_y);
717 plane.pln_own = sectp->sct_own;
718 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
719 plane.pln_x, plane.pln_y);
720 plane.pln_mission = 0;
721 putplane(plane.pln_uid, &plane);
725 pr("%s %s %s at %s.\n",
727 (load_unload == UNLOAD) ?
728 "unloaded from" : "loaded onto",
729 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
737 load_comm_ship(struct sctstr *sectp, struct shpstr *sp,
738 struct ichrstr *ich, int load_unload, int *nshipsp)
740 register int item = ich->i_vtype;
741 register int max_amt;
742 register int move_amt;
743 register int ship_amt;
744 register int sect_amt;
746 int upto = 0, abs_max;
751 sprintf(prompt, "Number of %s to %s %s at %s? ",
753 (load_unload == UNLOAD) ?
754 "unload from" : "load onto",
755 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
756 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
759 if (!still_ok_ship(sectp, sp))
764 /* We want to load up to this amount */
769 ship_amt = getvar(item, (s_char *)sp, EF_SHIP);
770 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
771 if (sectp->sct_oldown != player->cnum && item == V_CIVIL) {
772 pr("%s civilians refuse to %s at %s!\n",
773 load_unload == UNLOAD ? "Your" : "Foreign",
774 load_unload == UNLOAD ?
775 "disembark" : "board",
776 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
779 if (load_unload == UNLOAD) {
780 abs_max = max_amt = min(9999 - sect_amt, ship_amt);
782 struct mchrstr *vbase;
783 vbase = &mchr[(int)sp->shp_type];
784 abs_max = max_amt = vl_find(item, vbase->m_vtype,
785 vbase->m_vamt, (int)vbase->m_nv);
786 max_amt = min(sect_amt, max_amt - ship_amt);
788 if (max_amt <= 0 && !upto)
791 move_amt = upto - ship_amt;
792 if (move_amt > sect_amt)
794 if (ship_amt + move_amt > abs_max)
795 move_amt = abs_max - ship_amt;
797 move_amt = load_unload * min(amount, max_amt);
801 if (!want_to_abandon(sectp, item, move_amt, 0))
803 if (!still_ok_ship(sectp, sp))
805 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
806 putvar(item, ship_amt + move_amt, (s_char *)sp, EF_SHIP);
807 if (load_unload == LOAD) {
808 pr("%d %s loaded onto %s at %s\n",
811 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
812 if (sp->shp_own != player->cnum) {
813 sprintf(buf, "%s loaded %d %s onto %s at %s\n",
817 prship(sp), xyas(sp->shp_x, sp->shp_y, sp->shp_own));
818 wu(0, sp->shp_own, buf);
821 pr("%d %s unloaded from %s at %s\n",
824 prship(sp), xyas(sp->shp_x, sp->shp_y, player->cnum));
825 if (sectp->sct_own != player->cnum) {
826 sprintf(buf, "%s unloaded %d %s from %s at %s\n",
831 xyas(sp->shp_x, sp->shp_y, sectp->sct_own));
832 wu(0, sectp->sct_own, buf);
840 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
841 int load_unload, int *nunitsp)
850 if (!(lchr[(int)lp->lnd_type].l_flags & L_XLIGHT)) {
852 pr("%s cannot carry extra-light planes.\n", prland(lp));
855 count_land_planes(lp);
856 if (load_unload == LOAD && lp->lnd_nxlight >= lp->lnd_maxlight) {
858 pr("%s doesn't have room for any more extra-light planes\n",
862 sprintf(prompt, "Plane(s) to %s %s? ",
863 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
865 (&ni, EF_PLANE, p = getstarg(player->argp[3], prompt, buf)))
868 if (!still_ok_land(sectp, lp))
872 noisy &= isdigit(*p);
874 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
875 pr("Sector %s is not yours.\n",
876 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
880 while (nxtitem(&ni, (s_char *)&pln)) {
881 if (pln.pln_own != player->cnum)
884 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
886 pr("You can only load xlight planes onto units.\n");
890 if (load_unload == LOAD && pln.pln_ship > -1) {
892 pr("%s is already on ship #%d!\n",
893 prplane(&pln), pln.pln_ship);
896 if (load_unload == LOAD && pln.pln_land > -1) {
898 pr("%s is already on unit #%d!\n",
899 prplane(&pln), pln.pln_land);
902 /* Plane sanity done */
903 /* Find the right unit */
904 if (load_unload == UNLOAD) {
905 if (pln.pln_land != lp->lnd_uid)
907 } else if (lp->lnd_x != pln.pln_x || lp->lnd_y != pln.pln_y)
910 /* Fit plane on unit */
911 if (load_unload == LOAD) {
912 if (!put_plane_on_land(&pln, lp)) {
914 pr("Can't put plane %d on this unit!\n", pln.pln_uid);
917 sprintf(buf, "loaded on %s at %s",
918 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
919 gift(lp->lnd_own, player->cnum, (s_char *)&pln, EF_PLANE, buf);
920 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
922 pln.pln_own = lp->lnd_own;
923 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
925 putplane(pln.pln_uid, &pln);
927 if (!take_plane_off_land(&pln, lp)) {
928 pr("Unable to take plane off unit!\n");
929 logerror("load: plane %d could not be taken off unit %d\n",
930 pln.pln_uid, lp->lnd_uid);
933 sprintf(buf, "unloaded at your sector at %s",
934 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
935 gift(sectp->sct_own, player->cnum, (s_char *)&pln,
937 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
939 pln.pln_own = sectp->sct_own;
940 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x,
942 putplane(pln.pln_uid, &pln);
944 pr("%s %s %s at %s.\n",
946 (load_unload == UNLOAD) ?
947 "unloaded from" : "loaded onto",
948 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
956 load_comm_land(struct sctstr *sectp, struct lndstr *lp,
957 struct ichrstr *ich, int load_unload, int *nunitsp)
959 register int item = ich->i_vtype;
960 register int max_amt;
961 register int move_amt;
962 register int land_amt;
963 register int sect_amt;
965 int upto = 0, abs_max;
970 sprintf(prompt, "Number of %s to %s %s at %s? ",
972 (load_unload == UNLOAD) ?
973 "unload from" : "load onto",
974 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
975 if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
978 if (!still_ok_land(sectp, lp))
983 /* We want to load up to this amount */
989 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
990 pr("Sector %s is not yours.\n",
991 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
995 land_amt = getvar(item, (s_char *)lp, EF_LAND);
996 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
997 if (sectp->sct_oldown != player->cnum && item == V_CIVIL) {
998 pr("%s civilians refuse to %s at %s!\n",
999 load_unload == UNLOAD ? "Your" : "Foreign",
1000 load_unload == UNLOAD ?
1001 "disembark" : "board",
1002 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
1005 if (load_unload == UNLOAD) {
1006 abs_max = max_amt = min(9999 - sect_amt, land_amt);
1008 struct lchrstr *vbase;
1009 vbase = &lchr[(int)lp->lnd_type];
1010 abs_max = max_amt = vl_find(item, vbase->l_vtype,
1011 vbase->l_vamt, (int)vbase->l_nv);
1012 max_amt = min(sect_amt, max_amt - land_amt);
1014 if ((max_amt <= 0) && (upto == 0))
1017 move_amt = upto - land_amt;
1018 if (land_amt + move_amt > abs_max)
1019 move_amt = abs_max - land_amt;
1020 if (move_amt > sect_amt)
1021 move_amt = sect_amt;
1023 move_amt = load_unload * min(amount, max_amt);
1026 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
1027 putvar(item, land_amt + move_amt, (s_char *)lp, EF_LAND);
1029 /* Did we put mils onto this unit? If so, reset the fortification */
1030 if (item == V_MILIT && move_amt > 0)
1032 if (load_unload == LOAD) {
1033 pr("%d %s loaded onto %s at %s\n",
1036 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1037 if (lp->lnd_own != player->cnum) {
1038 sprintf(buf, "%s loaded %d %s onto %s at %s\n",
1039 cname(player->cnum),
1042 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1043 wu(0, lp->lnd_own, buf);
1046 pr("%d %s unloaded from %s at %s\n",
1049 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1050 if (sectp->sct_own != player->cnum) {
1051 sprintf(buf, "%s unloaded %d %s from %s at %s\n",
1052 cname(player->cnum),
1056 xyas(lp->lnd_x, lp->lnd_y, sectp->sct_own));
1057 wu(0, sectp->sct_own, buf);
1066 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy,
1067 int load_unload, int *nunitsp)
1069 struct nstr_item pni, ni;
1071 struct plnstr plane;
1077 lnd_count_units(lp);
1079 if (load_unload == LOAD && lp->lnd_nland >= lp->lnd_maxland) {
1082 pr("%s doesn't have room for any more land units!\n",
1085 pr("%s cannot carry land units!\n", prland(lp));
1089 sprintf(prompt, "Land unit(s) to %s %s? ",
1090 load_unload == LOAD ? "load onto" : "unload from", prland(lp));
1092 (&ni, EF_LAND, p = getstarg(player->argp[3], prompt, buf)))
1095 if (!still_ok_land(sectp, lp))
1099 noisy &= isdigit(*p);
1101 while (nxtitem(&ni, (s_char *)&land)) {
1103 if (land.lnd_own != player->cnum)
1106 if (load_unload == LOAD) {
1107 if (land.lnd_ship > -1) {
1109 pr("%s is already on ship #%d!\n",
1110 prland(&land), land.lnd_ship);
1113 if (land.lnd_land > -1) {
1115 pr("%s is already on land #%d!\n",
1116 prland(&land), land.lnd_land);
1119 lnd_count_units(&land);
1120 if (land.lnd_nland > 0) {
1122 pr("%s cannot be loaded since it is carrying units\n",
1126 if (land.lnd_uid == lp->lnd_uid) {
1128 pr("%s can't be loaded onto itself!\n", prland(&land));
1131 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
1133 pr("%s is too heavy to load.\n", prland(&land));
1138 /* Unit sanity done */
1139 /* Find the right ship */
1140 if (load_unload == UNLOAD) {
1141 if (land.lnd_land != lp->lnd_uid)
1143 if (land.lnd_ship > -1)
1145 } else if (lp->lnd_x != land.lnd_x || lp->lnd_y != land.lnd_y)
1148 /* Fit unit on ship */
1149 if (load_unload == LOAD) {
1150 lnd_count_units(lp);
1151 if (lp->lnd_nland >= lp->lnd_maxland) {
1154 pr("%s doesn't have room for any more land units!\n", prland(lp));
1156 pr("%s cannot carry land units!\n", prland(lp));
1160 sprintf(buf, "loaded on your %s at %s",
1161 prland(lp), xyas(lp->lnd_x, lp->lnd_y, lp->lnd_own));
1162 gift(lp->lnd_own, player->cnum, (s_char *)&land, EF_LAND, buf);
1163 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1165 land.lnd_own = lp->lnd_own;
1166 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1168 land.lnd_land = lp->lnd_uid;
1169 land.lnd_harden = 0;
1170 land.lnd_mission = 0;
1171 resupply_all(&land);
1173 putland(land.lnd_uid, &land);
1174 if (!has_supply(&land))
1175 pr("WARNING: %s is out of supply!\n", prland(&land));
1176 putland(lp->lnd_uid, lp);
1177 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1178 while (nxtitem(&pni, (s_char *)&plane)) {
1179 if (plane.pln_flags & PLN_LAUNCHED)
1181 if (plane.pln_land != land.lnd_uid)
1183 sprintf(buf, "loaded on %s", prland(lp));
1184 gift(lp->lnd_own, player->cnum, (s_char *)&plane,
1186 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1187 plane.pln_x, plane.pln_y);
1188 plane.pln_own = lp->lnd_own;
1189 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1190 plane.pln_x, plane.pln_y);
1191 plane.pln_mission = 0;
1192 putplane(plane.pln_uid, &plane);
1195 sprintf(buf, "unloaded in your %s at %s",
1196 dchr[sectp->sct_type].d_name,
1197 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
1198 gift(sectp->sct_own, player->cnum, (s_char *)&land,
1200 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1202 land.lnd_own = sectp->sct_own;
1203 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
1205 land.lnd_land = (-1);
1207 putland(land.lnd_uid, &land);
1208 putland(lp->lnd_uid, lp);
1209 snxtitem_xy(&pni, EF_PLANE, land.lnd_x, land.lnd_y);
1210 while (nxtitem(&pni, (s_char *)&plane)) {
1211 if (plane.pln_flags & PLN_LAUNCHED)
1213 if (plane.pln_land != land.lnd_uid)
1215 sprintf(buf, "unloaded at %s",
1216 xyas(plane.pln_x, plane.pln_y, sectp->sct_own));
1217 gift(sectp->sct_own, player->cnum, (s_char *)&plane,
1219 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
1220 plane.pln_x, plane.pln_y);
1221 plane.pln_own = sectp->sct_own;
1222 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
1223 plane.pln_x, plane.pln_y);
1224 plane.pln_mission = 0;
1225 putplane(plane.pln_uid, &plane);
1228 pr("%s %s %s at %s.\n",
1230 (load_unload == UNLOAD) ?
1231 "unloaded from" : "loaded onto",
1232 prland(lp), xyas(lp->lnd_x, lp->lnd_y, player->cnum));