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, int noisy, int load_unload, int *nshipsp);
62 static int load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp);
63 static int load_comm_ship(struct sctstr *sectp, struct shpstr *sp, struct ichrstr *ich, int load_unload, int *nshipsp);
64 static int load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp);
65 static int load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp);
66 static int load_comm_land(struct sctstr *sectp, struct lndstr *lp, struct ichrstr *ich, int load_unload, int *nunitsp);
74 struct nstr_item nbst;
83 if (!(p = getstarg(player->argp[1],
84 "What commodity (or 'plane' or 'land')? ", buf)) || !*p)
87 if (!strncmp(p, "plane", 5))
89 else if (!strncmp(p, "land", 4))
91 else if (NULL != (ich = whatitem(p, (s_char *)0)))
94 pr("Bad commodity.\n");
98 if (!(p = getstarg(player->argp[2], "Ship(s): ", buf)) || !*p)
103 if (!snxtitem(&nbst, EF_SHIP, p))
106 nbst.flags &= ~(EFF_OWNER);
108 load_unload = **player->argp == 'l' ? LOAD : UNLOAD;
111 while (nxtitem(&nbst, (s_char *)&ship)) {
114 if (!player->owner && (load_unload == UNLOAD)) {
118 if (ontradingblock(EF_SHIP, (int *)&ship)) {
119 pr("You cannot load/unload an item on the trading block!\n");
124 if (ship.shp_own != player->cnum) {
127 if (getrel(getnatp(player->cnum),ship.shp_own) < FRIENDLY)
130 if (!getsect(ship.shp_x, ship.shp_y, §)) /* XXX */
132 if ((sect.sct_own != player->cnum) &&
133 (ship.shp_own != player->cnum))
135 if (!player->owner &&
136 sect.sct_type != SCT_HARBR &&
137 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT))
141 if ((sect.sct_own != player->cnum) && (load_unload == LOAD)) {
143 pr("You don't own %s \n",
144 xyas(ship.shp_x, ship.shp_y, player->cnum));
147 if (sect.sct_type != SCT_HARBR &&
148 (!opt_BIG_CITY || sect.sct_type != SCT_CAPIT)) {
150 pr("Sector %s is not a harbor%s.\n",
151 xyas(ship.shp_x, ship.shp_y, player->cnum),
152 opt_BIG_CITY?" or a city":"");
155 if (sect.sct_own != player->cnum && load_unload == UNLOAD && getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY) {
157 pr("You can't unload into an unfriendly %s\n",
158 dchr[sect.sct_type].d_name);
161 if (sect.sct_effic < 2) {
163 pr("The %s at %s is not 2%% efficient yet.\n",
164 dchr[sect.sct_type].d_name,
165 xyas(ship.shp_x, ship.shp_y, player->cnum));
170 if (0 != (retval=load_plane_ship(§, &ship, noisy, load_unload, &nships)))
174 if (0 != (retval=load_land_ship(§, &ship, noisy, load_unload, &nships)))
178 if (0 != (retval=load_comm_ship(§, &ship, ich, load_unload, &nships)))
181 /* load/unload plague */
182 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
183 getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_HEALTHY)
184 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&ship, EF_SHIP);
185 if (getvar(V_PSTAGE, (s_char *)&ship, EF_SHIP) == PLG_INFECT &&
186 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
187 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
189 putship(ship.shp_uid, &ship);
192 pr("No ships affected\n");
194 pr("%d ship%s %sloaded\n", nships, splur(nships),
195 load_unload == UNLOAD ? "un" : "");
205 struct nstr_item nbst;
214 if (!(p = getstarg(player->argp[1],
215 "What commodity (or 'plane' or 'land')? ", buf)) || !*p)
217 if (!strncmp(p, "plane", 5))
219 else if (!strncmp(p, "land", 4))
221 else if (NULL != (ich = whatitem(p, (s_char *)0)))
224 pr("Bad commodity.\n");
228 if (!(p = getstarg(player->argp[2], "Unit(s): ", buf)) || !*p)
233 if (!snxtitem(&nbst, EF_LAND, p))
236 load_unload = *(*player->argp+1) == 'l' ? LOAD : UNLOAD;
238 nbst.flags &= ~(EFF_OWNER);
241 while (nxtitem(&nbst, (s_char *)&land)) {
242 if (land.lnd_own == 0)
245 if (player->cnum != land.lnd_own &&
246 getrel(getnatp(player->cnum), land.lnd_own) != ALLIED)
249 if (!getsect(land.lnd_x, land.lnd_y, §)) /* XXX */
252 if (sect.sct_own != player->cnum &&
253 land.lnd_own != player->cnum)
256 if (ontradingblock(EF_LAND, (int *)&land)) {
257 pr("You cannot load/unload an item on the trading block!\n");
262 if (sect.sct_own != player->cnum &&
263 getrel(getnatp(sect.sct_own), land.lnd_own) != ALLIED) {
264 pr("Sector %s is not yours.\n",
265 xyas(land.lnd_x, land.lnd_y, player->cnum));
270 if (0 != (retval=load_land_land(§, &land, noisy, load_unload, &nunits)))
274 if (0 != (retval=load_plane_land(§, &land, noisy, load_unload, &nunits)))
278 if (0 != (retval=load_comm_land(§, &land, ich, load_unload, &nunits)))
281 /* load/unload plague */
282 if (getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_INFECT &&
283 getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_HEALTHY)
284 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)&land, EF_LAND);
285 if (getvar(V_PSTAGE, (s_char *)&land, EF_LAND) == PLG_INFECT &&
286 getvar(V_PSTAGE, (s_char *)§, EF_SECTOR) == PLG_HEALTHY)
287 putvar(V_PSTAGE, PLG_EXPOSED, (s_char *)§, EF_SECTOR);
290 putland(land.lnd_uid, &land);
293 pr("No units affected\n");
295 pr("%d unit%s %sloaded\n", nunits, splur(nunits),
296 load_unload == UNLOAD ? "un" : "");
301 gift(int givee, int giver, s_char *ptr, int type, s_char *mesg)
303 s_char *p, line[256];
310 case EF_SHIP: p = prship((struct shpstr *)ptr);
312 case EF_PLANE: p = prplane((struct plnstr *)ptr);
314 case EF_LAND: p = prland((struct lndstr *)ptr);
318 sprintf(line,"%s %s %s\n",cname(giver),p,mesg);
323 still_ok_ship(struct sctstr *sectp, struct shpstr *shipp)
325 if (!check_sect_ok(sectp))
327 if (!check_ship_ok(shipp))
333 still_ok_land(struct sctstr *sectp, struct lndstr *landp)
335 if (!check_sect_ok(sectp))
337 if (!check_land_ok(landp))
343 load_plane_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp)
351 struct mchrstr *mcp = mchr + sp->shp_type;
353 if (!(mcp->m_flags & (M_CHOPPER|M_XLIGHT|M_FLY|M_MSL))) {
355 pr("%s cannot carry planes\n", prship(sp));
359 if (load_unload==LOAD &&
360 sp->shp_nchoppers >= mcp->m_nchoppers &&
361 sp->shp_nxlight >= mcp->m_nxlight &&
362 sp->shp_nplane >= mcp->m_nplanes) {
364 pr("%s doesn't have room for any more planes\n",
368 sprintf(prompt, "Plane(s) to %s %s? ",
369 load_unload==LOAD?"load onto":"unload from",
371 if (!snxtitem(&ni, EF_PLANE, p=getstarg(player->argp[3], prompt, buf)))
374 if (!still_ok_ship(sectp, sp))
378 noisy &= isdigit(*p);
380 while(nxtitem(&ni, (s_char *)&pln)) {
381 if (pln.pln_own != player->cnum)
383 if (!(plchr[(int)pln.pln_type].pl_flags & P_L)
384 && !(plchr[(int)pln.pln_type].pl_flags & P_E)
385 && !(plchr[(int)pln.pln_type].pl_flags & P_K)
386 && !(plchr[(int)pln.pln_type].pl_flags & P_M)
389 pr("You can only load light planes, helos, xtra-light, or missiles onto ships.\n");
392 if (load_unload == LOAD && pln.pln_ship > -1) {
394 pr("%s is already on ship #%d!\n",
395 prplane(&pln), pln.pln_ship);
398 if (load_unload == LOAD && pln.pln_land > -1) {
400 pr("%s is already on land unit #%d!\n",
401 prplane(&pln), pln.pln_land);
405 /* Plane sanity done */
406 /* Find the right ship */
407 if (load_unload == UNLOAD) {
408 if (pln.pln_ship != sp->shp_uid)
410 } else if (sp->shp_x != pln.pln_x
411 || sp->shp_y != pln.pln_y)
414 /* ship to (plane or missle) sanity */
415 if (!can_be_on_ship(pln.pln_uid, sp->shp_uid)) {
416 if (plchr[(int)pln.pln_type].pl_flags & P_L) {
417 strcpy(buf, "planes");
418 } else if (plchr[(int)pln.pln_type].pl_flags & P_K) {
419 strcpy(buf, "choppers");
420 } else if (plchr[(int)pln.pln_type].pl_flags & P_M) {
421 strcpy(buf, "missiles");
422 } else if (plchr[(int)pln.pln_type].pl_flags & P_E) {
423 strcpy(buf, "extra light planes");
424 } /* else impossible */
426 pr("%s cannot carry %s.\n",
431 /* Fit plane on ship */
432 if (load_unload == LOAD){
433 if (!put_plane_on_ship(&pln,sp)){
435 pr("Can't put plane %d on this ship!\n",pln.pln_uid);
438 sprintf(buf, "loaded on your %s at %s",
439 prship(sp),xyas(sp->shp_x,
440 sp->shp_y, sp->shp_own));
441 gift(sp->shp_own, player->cnum, (s_char *)&pln,
443 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
444 pln.pln_own = sp->shp_own;
445 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
447 putplane(pln.pln_uid,&pln);
449 if (!take_plane_off_ship(&pln,sp)) {
450 pr("Unable to take plane off ship!\n");
451 logerror("load: plane %d could not be taken off ship %d\n",pln.pln_uid,sp->shp_uid);
454 sprintf(buf, "unloaded in your %s at %s",
455 dchr[sectp->sct_type].d_name,
456 xyas(sectp->sct_x,sectp->sct_y,
458 gift(sectp->sct_own, player->cnum, (s_char *)&pln,
460 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
461 pln.pln_own = sectp->sct_own;
462 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
463 putplane(pln.pln_uid,&pln);
465 pr("%s %s %s at %s.\n",
467 (load_unload==UNLOAD)?
468 "unloaded from":"loaded onto",
470 xyas(sp->shp_x, sp->shp_y, player->cnum));
478 load_land_ship(struct sctstr *sectp, struct shpstr *sp, int noisy, int load_unload, int *nshipsp)
480 struct nstr_item pni, ni;
490 if (load_unload == LOAD) {
492 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
493 (mchr[(int)sp->shp_type].m_nland == 0)) {
494 if (sp->shp_nland >= 2) {
495 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
498 /* Eh, let 'em load a spy only */
503 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
505 if (mchr[(int)sp->shp_type].m_nland)
506 pr("%s doesn't have room for any more land units!\n",prship(sp));
508 pr("%s cannot carry land units!\n",prship(sp));
513 sprintf(prompt, "Land unit(s) to %s %s? ",
514 load_unload==LOAD?"load onto":"unload from",
516 if (!snxtitem(&ni, EF_LAND, p=getstarg(player->argp[3], prompt, buf)))
519 if (!still_ok_ship(sectp, sp))
523 noisy &= isdigit(*p);
525 while(nxtitem(&ni, (s_char *)&land)) {
526 if (land.lnd_own != player->cnum)
529 if (load_unload == LOAD) {
530 if (land.lnd_ship > -1) {
532 pr("%s is already on ship #%d!\n",
533 prland(&land), land.lnd_ship);
536 if (land.lnd_land > -1) {
538 pr("%s is already on land #%d!\n",
539 prland(&land), land.lnd_land);
542 lnd_count_units(&land);
543 if (land.lnd_nland > 0) {
545 pr("%s cannot be loaded since it is carrying units\n",
549 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
551 pr("%s is too heavy to load.\n", prland(&land));
554 if (load_spy && !(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
556 pr("Subs can only carry spy units.\n");
561 /* Unit sanity done */
562 /* Find the right ship */
563 if (load_unload == UNLOAD) {
564 if (land.lnd_ship != sp->shp_uid)
566 if (land.lnd_land > -1)
568 } else if (sp->shp_x != land.lnd_x
569 || sp->shp_y != land.lnd_y)
572 if ((!(lchr[(int)land.lnd_type].l_flags & L_LIGHT)) &&
573 (!((mchr[(int)sp->shp_type].m_flags & M_SUPPLY) &&
574 (!(mchr[(int)sp->shp_type].m_flags & M_SUB))))) {
576 pr("You can only load light units onto ships,\n");
577 pr("unless the ship is a non-sub supply ship\n");
578 pr("%s not loaded\n", prland(&land));
582 /* Fit unit on ship */
583 if (load_unload == LOAD) {
585 /* We have to check again, since it may have changed */
587 if ((mchr[(int)sp->shp_type].m_flags & M_SUB) &&
588 (mchr[(int)sp->shp_type].m_nland == 0)) {
589 if (sp->shp_nland >= 2) {
590 pr("Non-land unit carrying subs can only carry up to two spy units.\n");
593 /* Eh, let 'em load a spy only */
598 (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland)) {
600 if (mchr[(int)sp->shp_type].m_nland)
601 pr("%s doesn't have room for any more land units!\n",prship(sp));
603 pr("%s cannot carry land units!\n",prship(sp));
608 if (sp->shp_nland >= mchr[(int)sp->shp_type].m_nland) {
610 if (mchr[(int)sp->shp_type].m_nland)
611 pr("%s doesn't have room for any more land units!\n",prship(sp));
613 pr("%s cannot carry land units!\n",prship(sp));
617 sprintf(buf, "loaded on your %s at %s",
618 prship(sp),xyas(sp->shp_x,sp->shp_y,
620 gift(sp->shp_own,player->cnum,(s_char *)&land,
622 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
624 land.lnd_own = sp->shp_own;
625 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x,
627 land.lnd_ship = sp->shp_uid;
629 land.lnd_mission = 0;
632 putland(land.lnd_uid,&land);
633 if (!has_supply(&land))
634 pr("WARNING: %s is out of supply!\n",
636 putship(sp->shp_uid,sp);
637 snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y);
638 while (nxtitem(&pni, (s_char *)&plane)){
639 if (plane.pln_flags & PLN_LAUNCHED)
641 if (plane.pln_land != land.lnd_uid)
643 sprintf(buf, "loaded on %s",
645 gift(sp->shp_own,player->cnum,(s_char *)&plane,
647 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
649 plane.pln_own = sp->shp_own;
650 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
651 plane.pln_x, plane.pln_y);
652 plane.pln_mission = 0;
653 putplane(plane.pln_uid,&plane);
656 sprintf(buf, "unloaded in your %s at %s",
657 dchr[sectp->sct_type].d_name,
658 xyas(sectp->sct_x,sectp->sct_y,
661 /* Spies are unloaded quietly, others aren't */
662 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
663 gift(sectp->sct_own,player->cnum,(s_char *)&land,
665 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
666 land.lnd_x, land.lnd_y);
667 land.lnd_own = sectp->sct_own;
668 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
669 land.lnd_x, land.lnd_y);
672 land.lnd_ship = (-1);
674 putland(land.lnd_uid,&land);
675 putship(sp->shp_uid,sp);
677 /* Spies are unloaded quietly, others aren't, and
678 in the off chance they can carry a plane (missile?)
679 they are quietly unloaded too. */
680 if (!(lchr[(int)land.lnd_type].l_flags & L_SPY)) {
681 snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y);
682 while (nxtitem(&pni, (s_char *)&plane)){
683 if (plane.pln_flags & PLN_LAUNCHED)
685 if (plane.pln_land != land.lnd_uid)
687 sprintf(buf, "unloaded at %s",
688 xyas(plane.pln_x,plane.pln_y,
690 gift(sectp->sct_own,player->cnum,(s_char *)&plane,
692 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
693 plane.pln_x, plane.pln_y);
694 plane.pln_own = sectp->sct_own;
695 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
696 plane.pln_x, plane.pln_y);
697 plane.pln_mission = 0;
698 putplane(plane.pln_uid,&plane);
702 pr("%s %s %s at %s.\n",
704 (load_unload==UNLOAD)?
705 "unloaded from":"loaded onto",
707 xyas(sp->shp_x, sp->shp_y, player->cnum));
715 load_comm_ship(struct sctstr *sectp, struct shpstr *sp, struct ichrstr *ich, int load_unload, int *nshipsp)
717 register int item = ich->i_vtype;
718 register int max_amt;
719 register int move_amt;
720 register int ship_amt;
721 register int sect_amt;
728 sprintf(prompt, "Number of %s to %s %s at %s? ",
730 (load_unload==UNLOAD)?
731 "unload from":"load onto",
733 xyas(sp->shp_x, sp->shp_y, player->cnum));
734 if (!(p = getstarg(player->argp[3], prompt, buf)) ||
738 if (!still_ok_ship(sectp, sp))
743 /* We want to load up to this amount */
748 ship_amt = getvar(item, (s_char *)sp, EF_SHIP);
749 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
750 if (sectp->sct_oldown != player->cnum &&
752 pr("%s civilians refuse to %s at %s!\n",
753 load_unload == UNLOAD ? "Your" : "Foreign",
754 load_unload == UNLOAD ?
755 "disembark" : "board",
756 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
759 if (load_unload == UNLOAD) {
760 abs_max = max_amt = min(9999 - sect_amt, ship_amt);
762 struct mchrstr *vbase;
763 vbase = &mchr[(int)sp->shp_type];
764 abs_max = max_amt = vl_find(item, vbase->m_vtype,
765 vbase->m_vamt, (int) vbase->m_nv);
766 max_amt = min(sect_amt, max_amt - ship_amt);
768 if (max_amt <= 0 && !upto)
771 move_amt = upto - ship_amt;
772 if (move_amt > sect_amt)
774 if (ship_amt+move_amt > abs_max)
775 move_amt = abs_max - ship_amt;
777 move_amt = load_unload * min(amount, max_amt);
781 if (!want_to_abandon(sectp, item, move_amt, 0))
783 if (!still_ok_ship(sectp, sp))
785 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
786 putvar(item, ship_amt + move_amt, (s_char *)sp, EF_SHIP);
787 if (load_unload == LOAD) {
788 pr("%d %s loaded onto %s at %s\n",
792 xyas(sp->shp_x, sp->shp_y, player->cnum));
793 if (sp->shp_own != player->cnum) {
794 sprintf(buf,"%s loaded %d %s onto %s at %s\n",
799 xyas(sp->shp_x, sp->shp_y,
801 wu(0, sp->shp_own, buf);
804 pr("%d %s unloaded from %s at %s\n",
808 xyas(sp->shp_x, sp->shp_y, player->cnum));
809 if (sectp->sct_own != player->cnum) {
810 sprintf(buf,"%s unloaded %d %s from %s at %s\n",
815 xyas(sp->shp_x, sp->shp_y,
817 wu(0, sectp->sct_own, buf);
825 load_plane_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp)
834 if (!(lchr[(int)lp->lnd_type].l_flags & L_XLIGHT)) {
836 pr("%s cannot carry extra-light planes.\n",
840 count_land_planes(lp);
841 if (load_unload==LOAD &&
842 lp->lnd_nxlight >= lp->lnd_maxlight) {
844 pr("%s doesn't have room for any more extra-light planes\n",
848 sprintf(prompt, "Plane(s) to %s %s? ",
849 load_unload==LOAD?"load onto":"unload from",
851 if (!snxtitem(&ni, EF_PLANE, p=getstarg(player->argp[3], prompt, buf)))
854 if (!still_ok_land(sectp, lp))
858 noisy &= isdigit(*p);
860 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
861 pr("Sector %s is not yours.\n",
862 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
866 while(nxtitem(&ni, (s_char *)&pln)) {
867 if (pln.pln_own != player->cnum)
870 if (!(plchr[(int)pln.pln_type].pl_flags & P_E)) {
872 pr("You can only load xlight planes onto units.\n");
876 if (load_unload == LOAD && pln.pln_ship > -1) {
878 pr("%s is already on ship #%d!\n",
879 prplane(&pln), pln.pln_ship);
882 if (load_unload == LOAD && pln.pln_land > -1) {
884 pr("%s is already on unit #%d!\n",
885 prplane(&pln), pln.pln_land);
888 /* Plane sanity done */
889 /* Find the right unit */
890 if (load_unload == UNLOAD) {
891 if (pln.pln_land != lp->lnd_uid)
893 } else if (lp->lnd_x != pln.pln_x
894 || lp->lnd_y != pln.pln_y)
897 /* Fit plane on unit */
898 if (load_unload == LOAD){
899 if (!put_plane_on_land(&pln,lp)){
901 pr("Can't put plane %d on this unit!\n",pln.pln_uid);
904 sprintf(buf, "loaded on %s at %s",
905 prland(lp), xyas(lp->lnd_x,
906 lp->lnd_y, lp->lnd_own));
907 gift(lp->lnd_own,player->cnum,(s_char *)&pln,
909 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
910 pln.pln_own = lp->lnd_own;
911 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
912 putplane(pln.pln_uid,&pln);
914 if (!take_plane_off_land(&pln,lp)){
915 pr("Unable to take plane off unit!\n");
916 logerror("load: plane %d could not be taken off unit %d\n",pln.pln_uid,lp->lnd_uid);
919 sprintf(buf, "unloaded at your sector at %s",
920 xyas(sectp->sct_x,sectp->sct_y,
922 gift(sectp->sct_own,player->cnum,(s_char *)&pln,
924 makelost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
925 pln.pln_own = sectp->sct_own;
926 makenotlost(EF_PLANE, pln.pln_own, pln.pln_uid, pln.pln_x, pln.pln_y);
927 putplane(pln.pln_uid,&pln);
929 pr("%s %s %s at %s.\n",
931 (load_unload==UNLOAD)?
932 "unloaded from":"loaded onto",
934 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
942 load_comm_land(struct sctstr *sectp, struct lndstr *lp, struct ichrstr *ich, int load_unload, int *nunitsp)
944 register int item = ich->i_vtype;
945 register int max_amt;
946 register int move_amt;
947 register int land_amt;
948 register int sect_amt;
955 sprintf(prompt, "Number of %s to %s %s at %s? ",
957 (load_unload==UNLOAD)?
958 "unload from":"load onto",
960 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
961 if (!(p = getstarg(player->argp[3], prompt, buf)) ||
965 if (!still_ok_land(sectp, lp))
970 /* We want to load up to this amount */
976 if (sectp->sct_own != player->cnum && load_unload == LOAD) {
977 pr("Sector %s is not yours.\n",
978 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
982 land_amt = getvar(item, (s_char *)lp, EF_LAND);
983 sect_amt = getvar(item, (s_char *)sectp, EF_SECTOR);
984 if (sectp->sct_oldown != player->cnum && item == V_CIVIL) {
985 pr("%s civilians refuse to %s at %s!\n",
986 load_unload == UNLOAD ? "Your" : "Foreign",
987 load_unload == UNLOAD ?
988 "disembark" : "board",
989 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
992 if (load_unload == UNLOAD) {
993 abs_max = max_amt = min(9999 - sect_amt, land_amt);
995 struct lchrstr *vbase;
996 vbase = &lchr[(int)lp->lnd_type];
997 abs_max = max_amt = vl_find(item, vbase->l_vtype,
998 vbase->l_vamt, (int) vbase->l_nv);
999 max_amt = min(sect_amt, max_amt - land_amt);
1001 if ((max_amt <= 0) && (upto == 0))
1004 move_amt = upto - land_amt;
1005 if (land_amt+move_amt > abs_max)
1006 move_amt = abs_max - land_amt;
1007 if (move_amt > sect_amt)
1008 move_amt = sect_amt;
1010 move_amt = load_unload * min(amount, max_amt);
1013 putvar(item, sect_amt - move_amt, (s_char *)sectp, EF_SECTOR);
1014 putvar(item, land_amt + move_amt, (s_char *)lp, EF_LAND);
1016 /* Did we put mils onto this unit? If so, reset the fortification */
1017 if (item == V_MILIT && move_amt > 0)
1019 if (load_unload == LOAD) {
1020 pr("%d %s loaded onto %s at %s\n",
1024 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1025 if (lp->lnd_own != player->cnum) {
1026 sprintf(buf,"%s loaded %d %s onto %s at %s\n",
1027 cname(player->cnum),
1031 xyas(lp->lnd_x, lp->lnd_y,
1033 wu(0, lp->lnd_own, buf);
1036 pr("%d %s unloaded from %s at %s\n",
1040 xyas(lp->lnd_x, lp->lnd_y, player->cnum));
1041 if (sectp->sct_own != player->cnum) {
1042 sprintf(buf,"%s unloaded %d %s from %s at %s\n",
1043 cname(player->cnum),
1047 xyas(lp->lnd_x, lp->lnd_y,
1049 wu(0, sectp->sct_own, buf);
1058 load_land_land(struct sctstr *sectp, struct lndstr *lp, int noisy, int load_unload, int *nunitsp)
1060 struct nstr_item pni, ni;
1062 struct plnstr plane;
1068 lnd_count_units(lp);
1070 if (load_unload==LOAD &&
1071 lp->lnd_nland >= lp->lnd_maxland) {
1074 pr("%s doesn't have room for any more land units!\n",prland(lp));
1076 pr("%s cannot carry land units!\n",prland(lp));
1080 sprintf(prompt, "Land unit(s) to %s %s? ",
1081 load_unload==LOAD?"load onto":"unload from",
1083 if (!snxtitem(&ni, EF_LAND, p=getstarg(player->argp[3], prompt, buf)))
1086 if (!still_ok_land(sectp, lp))
1090 noisy &= isdigit(*p);
1092 while(nxtitem(&ni, (s_char *)&land)) {
1094 if (land.lnd_own != player->cnum)
1097 if (load_unload == LOAD) {
1098 if (land.lnd_ship > -1) {
1100 pr("%s is already on ship #%d!\n",
1101 prland(&land), land.lnd_ship);
1104 if (land.lnd_land > -1) {
1106 pr("%s is already on land #%d!\n",
1107 prland(&land), land.lnd_land);
1110 lnd_count_units(&land);
1111 if (land.lnd_nland > 0) {
1113 pr("%s cannot be loaded since it is carrying units\n",
1117 if (land.lnd_uid == lp->lnd_uid) {
1119 pr("%s can't be loaded onto itself!\n", prland(&land));
1122 if (lchr[(int)land.lnd_type].l_flags & L_HEAVY) {
1124 pr("%s is too heavy to load.\n", prland(&land));
1129 /* Unit sanity done */
1130 /* Find the right ship */
1131 if (load_unload == UNLOAD) {
1132 if (land.lnd_land != lp->lnd_uid)
1134 if (land.lnd_ship > -1)
1136 } else if (lp->lnd_x != land.lnd_x
1137 || lp->lnd_y != land.lnd_y)
1140 /* Fit unit on ship */
1141 if (load_unload == LOAD) {
1142 lnd_count_units(lp);
1143 if (lp->lnd_nland >= lp->lnd_maxland) {
1146 pr("%s doesn't have room for any more land units!\n",prland(lp));
1148 pr("%s cannot carry land units!\n",prland(lp));
1152 sprintf(buf, "loaded on your %s at %s",
1153 prland(lp),xyas(lp->lnd_x,lp->lnd_y,
1155 gift(lp->lnd_own,player->cnum,(s_char *)&land,
1157 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y);
1158 land.lnd_own = lp->lnd_own;
1159 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y);
1160 land.lnd_land = lp->lnd_uid;
1161 land.lnd_harden = 0;
1162 land.lnd_mission = 0;
1163 resupply_all(&land);
1165 putland(land.lnd_uid,&land);
1166 if (!has_supply(&land))
1167 pr("WARNING: %s is out of supply!\n",
1169 putland(lp->lnd_uid,lp);
1170 snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y);
1171 while (nxtitem(&pni, (s_char *)&plane)){
1172 if (plane.pln_flags & PLN_LAUNCHED)
1174 if (plane.pln_land != land.lnd_uid)
1176 sprintf(buf, "loaded on %s",
1178 gift(lp->lnd_own,player->cnum,(s_char *)&plane,
1180 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y);
1181 plane.pln_own = lp->lnd_own;
1182 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y);
1183 plane.pln_mission = 0;
1184 putplane(plane.pln_uid,&plane);
1187 sprintf(buf, "unloaded in your %s at %s",
1188 dchr[sectp->sct_type].d_name,
1189 xyas(sectp->sct_x,sectp->sct_y,
1191 gift(sectp->sct_own,player->cnum,(s_char *)&land,
1193 makelost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y);
1194 land.lnd_own = sectp->sct_own;
1195 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid, land.lnd_x, land.lnd_y);
1196 land.lnd_land = (-1);
1198 putland(land.lnd_uid,&land);
1199 putland(lp->lnd_uid,lp);
1200 snxtitem_xy(&pni,EF_PLANE,land.lnd_x,land.lnd_y);
1201 while (nxtitem(&pni, (s_char *)&plane)){
1202 if (plane.pln_flags & PLN_LAUNCHED)
1204 if (plane.pln_land != land.lnd_uid)
1206 sprintf(buf, "unloaded at %s",
1207 xyas(plane.pln_x,plane.pln_y,
1209 gift(sectp->sct_own,player->cnum,(s_char *)&plane,
1211 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y);
1212 plane.pln_own = sectp->sct_own;
1213 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y);
1214 plane.pln_mission = 0;
1215 putplane(plane.pln_uid,&plane);
1218 pr("%s %s %s at %s.\n",
1220 (load_unload==UNLOAD)?
1221 "unloaded from":"loaded onto",
1223 xyas(lp->lnd_x, lp->lnd_y, player->cnum));