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 * plnsub.c: Plane subroutine stuff
30 * Known contributors to this file:
33 * Steve McClure, 1998-2000
51 #include "prototypes.h"
54 static int pln_equip(struct plist *, struct ichrstr *, int, s_char);
57 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
68 if ((target->sct_own && target->sct_own != player->cnum &&
69 (getrel(getnatp(target->sct_own), player->cnum) != ALLIED)) &&
70 (target->sct_type != SCT_HARBR) &&
71 (target->sct_type != SCT_BSPAN)) {
72 pr("Nowhere to land at sector %s!\n",
73 xyas(target->sct_x, target->sct_y, player->cnum));
76 if (target->sct_type == SCT_MOUNT) {
77 pr("Nowhere to land at sector %s!\n",
78 xyas(target->sct_x, target->sct_y, player->cnum));
82 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
84 if (target->sct_type == SCT_WATER || target->sct_type == SCT_HARBR
85 || target->sct_type == SCT_BSPAN) {
86 nships = carriersatxy(target->sct_x, target->sct_y,
87 M_FLY | M_CHOPPER, 0, player->cnum);
89 if (target->sct_type == SCT_WATER) {
90 pr("Nowhere to land at sector %s!\n",
91 xyas(target->sct_x, target->sct_y, player->cnum));
94 if ((target->sct_own && target->sct_own != player->cnum)
95 && (getrel(getnatp(target->sct_own), player->cnum) !=
97 pr("Nowhere to land at sector %s!\n",
98 xyas(target->sct_x, target->sct_y, player->cnum));
109 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
112 if (n < 0 || !getship(n, &ship)
114 && (getrel(getnatp(ship.shp_own), player->cnum)
119 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
120 pr("Ship #%d not in %s\n", n,
121 xyas(target->sct_x, target->sct_y, player->cnum));
124 if (!(mchr[(int)ship.shp_type].m_flags & M_FLY)
125 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
126 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
128 pr("Can't land on %s.\n", prship(&ship));
131 pr("landing on carrier %d\n", n);
134 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
136 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
138 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
141 if ((target->sct_own && target->sct_own != player->cnum) &&
142 (getrel(getnatp(target->sct_own), player->cnum) != ALLIED) &&
144 pr("Nowhere to land at sector %s!\n",
145 xyas(target->sct_x, target->sct_y, player->cnum));
150 if ((target->sct_own == 0) && (cno < 0)) {
151 pr("Nowhere to land at sector %s!\n",
152 xyas(target->sct_x, target->sct_y, player->cnum));
162 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
164 struct emp_qelem *qp;
171 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
172 plp = (struct plist *)qp;
173 /* XXX - need to restrict # of planes per ship */
176 if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
177 pr("\t%s cannot land on ship #%d! %s aborts!\n",
178 prplane(&plp->plane), cno, prplane(&plp->plane));
179 else if (!put_plane_on_ship(&plp->plane, &ship))
180 pr("\tNo room on ship #%d! %s aborts!\n", cno,
181 prplane(&plp->plane));
183 if (plp->plane.pln_own != ship.shp_own) {
184 /* plp->plane.pln_own = ship.shp_own;*/
186 "%s %s lands on your %s\n",
188 prplane(&plp->plane), prship(&ship));
192 plp->plane.pln_x = tx;
193 plp->plane.pln_y = ty;
194 getsect(tx, ty, §);
195 if (plp->plane.pln_own != sect.sct_own) {
196 /* plp->plane.pln_own = sect.sct_own;*/
198 "%s %s lands at your sector %s\n",
200 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
202 plp->plane.pln_ship = cno;
206 putship(ship.shp_uid, &ship);
210 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
213 struct emp_qelem *qp;
216 struct sctstr *sectp;
225 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
226 plp = (struct plist *)qp;
229 if (type == EF_SECTOR) {
231 if (sectp->sct_type == SCT_WATER && ip->i_vtype == V_SHELL) {
233 sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
234 pr("%d mines laid in %s.\n", amt,
235 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
237 && map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
238 writemap(player->cnum);
242 there = sectp->sct_item[ip->i_vtype];
246 there = sp->shp_item[ip->i_vtype];
247 mp = &mchr[(int)sp->shp_type];
248 max = vl_find(ip->i_vtype, mp->m_vtype,
249 mp->m_vamt, (int)mp->m_nv);
253 pr("%d excess %s discarded\n", max - there, ip->i_name);
257 pr("%d %s landed safely", amt, ip->i_name);
258 if (type == EF_SECTOR) {
260 sectp->sct_item[ip->i_vtype] = there;
261 if (sectp->sct_own != player->cnum)
262 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
263 cname(player->cnum), amt, ip->i_name,
264 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
265 pr(" at %s\n", xyas(tx, ty, player->cnum));
266 putsect((struct sctstr *)ptr);
268 struct shpstr *sp = (struct shpstr *)ptr;
269 sp->shp_item[ip->i_vtype] = there;
270 if (sp->shp_own != player->cnum)
271 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
272 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
273 pr(" on carrier #%d\n", sp->shp_uid);
274 putship(sp->shp_uid, sp);
279 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
280 int ap_to_target, int rangemult, int wantflags, int nowantflags)
287 struct plchrstr *pcp;
290 register int bad, bad1;
294 while (nxtitem(ni, (s_char *)&plane)) {
297 if (plane.pln_mobil <= (s_char)0)
300 if (ontradingblock(EF_PLANE, (int *)&plane)) {
301 pr("plane #%d inelligible - it's for sale.\n",
307 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
309 pr("%s too far from assembly point\n", prplane(&plane));
312 if (plane.pln_effic < 40) {
313 pr("%s not efficient enough (must be 40%%)\n",
317 range += ap_to_target;
318 pcp = &plchr[(int)plane.pln_type];
322 for (x = 0; x < sizeof(wantflags) * 8; x++) {
324 if ((wantflags & y) == y)
325 if ((pcp->pl_flags & y) != y) {
344 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
348 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
350 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
352 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
361 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
363 if ((nowantflags & y) == y)
364 if ((pcp->pl_flags & y) == y)
371 if (plane.pln_range < range) {
372 pr("%s out of range (%d:%d)\n", prplane(&plane),
373 plane.pln_range, range);
376 if (plane.pln_ship >= 0) {
377 if (!getship(plane.pln_ship, &ship) ||
378 plane.pln_own != player->cnum) {
381 pr("(note) ship not valid for %s\n", prplane(&plane));
382 putplane(plane.pln_uid, &plane);
385 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
387 if (ship.shp_effic < SHIP_MINEFF)
389 if (ship.shp_effic < 50)
391 /* Can't fly off non-owned ships or non-allied ship */
392 if ((ship.shp_own != player->cnum) &&
393 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
394 pr("(note) An ally does not own the ship %s is on\n",
399 if (plane.pln_land >= 0) {
400 if (!getland(plane.pln_land, &land) ||
401 (plane.pln_own != player->cnum)) {
404 pr("(note) land unit not valid for %s\n", prplane(&plane));
405 putplane(plane.pln_uid, &plane);
408 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
410 if (land.lnd_effic < LAND_MINEFF)
412 if (land.lnd_effic < 50)
414 /* Can't fly off units in ships or other units */
415 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
417 /* Can't fly off non-owned units or non-allied unit */
418 if ((land.lnd_own != player->cnum) &&
419 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
420 pr("(note) An ally does not own the unit %s is on\n",
425 /* Now, check the sector status if not on a plane or unit */
426 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
427 if (!getsect(plane.pln_x, plane.pln_y, §))
429 /* First, check allied status */
430 /* Can't fly from non-owned sectors or non-allied sectors */
431 if ((sect.sct_own != player->cnum) &&
432 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
433 pr("(note) An ally does not own the sector %s is in\n",
438 if ((pcp->pl_flags & P_V) == 0) {
439 if (sect.sct_type != SCT_AIRPT) {
440 pr("%s not at airport\n", prplane(&plane));
443 if (sect.sct_effic < 40) {
444 pr("%s is not 40%% efficient, %s can't take off from there.\n", xyas(sect.sct_x, sect.sct_y, plane.pln_own), prplane(&plane));
447 if (rangemult == 2 && sect.sct_effic < 60) {
448 pr("%s is not 60%% efficient, %s can't land there.\n",
449 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
455 pr("%s standing by\n", prplane(&plane));
456 plane.pln_mission = 0;
457 putplane(plane.pln_uid, &plane);
458 plp = (struct plist *)malloc(sizeof(struct plist));
464 emp_insque(&plp->queue, list);
469 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
470 int flags, int mission_flags, int *tech)
472 struct emp_qelem *qp;
473 struct emp_qelem *next;
478 for (qp = list->q_forw; qp != list; qp = next) {
480 plp = (struct plist *)qp;
481 if (pln_equip(plp, ip, flags, mission) < 0) {
486 if (flags & (P_S | P_I)) {
487 if (plp->pcp->pl_flags & P_S)
488 mission_flags |= P_S;
489 if (plp->pcp->pl_flags & P_I)
490 mission_flags |= P_I;
492 if (*tech > plp->plane.pln_tech)
493 *tech = plp->plane.pln_tech;
494 if (!(plp->pcp->pl_flags & P_H))
495 /* no stealth on this mission */
496 mission_flags &= ~P_H;
497 if (!(plp->pcp->pl_flags & P_X))
498 /* no stealth on this mission */
499 mission_flags &= ~P_X;
500 if (!(plp->pcp->pl_flags & P_A)) {
501 /* no asw on this mission */
502 mission_flags &= ~P_A;
504 if (!(plp->pcp->pl_flags & P_MINE)) {
505 /* no asw on this mission */
506 mission_flags &= ~P_MINE;
508 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
509 pr("%s equipped\n", prplane(&plp->plane));
511 return mission_flags;
515 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
517 register struct plchrstr *pcp;
530 if (pp->pln_ship >= 0) {
531 getship(pp->pln_ship, &ship);
532 item = ship.shp_item;
534 } else if (pp->pln_land >= 0) {
535 getland(pp->pln_land, &land);
536 item = land.lnd_item;
539 getsect(pp->pln_x, pp->pln_y, §);
540 item = sect.sct_item;
541 own = sect.sct_oldown;
544 if (ip->i_vtype == V_CIVIL) {
545 if (pp->pln_own != own) {
546 pr("You don't control those civilians!\n");
551 if (pcp->pl_fuel > item[I_PETROL]) {
552 pr("%s not enough petrol there!\n", prplane(pp));
555 item[I_PETROL] -= pcp->pl_fuel;
557 if ((flags & P_F) == 0) {
563 if (pp->pln_nuketype == -1) {
565 needed = pp->pln_load;
569 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
572 needed = (pp->pln_load * 2) / ip->i_lbs;
576 needed = (pp->pln_load * 2) / ip->i_lbs;
577 /* Is this mine dropping excursion? */
578 if (itype == I_SHELL && (pcp->pl_flags & P_MINE))
580 /* Is this a cargo drop? */
581 if ((pcp->pl_flags & P_C) == 0 || ip == 0) {
588 if ((pcp->pl_flags & (P_V | P_C)) == 0)
591 needed = pp->pln_load / ip->i_lbs;
594 if (pp->pln_nuketype == (s_char)-1)
600 if (rval < 0 || (itype && needed <= 0)) {
601 pr("%s can't contribute to mission\n", prplane(pp));
605 /* Supply is broken somewhere, so don't use it for now */
606 if (item[itype] < needed && itype == I_SHELL)
607 item[itype] += supply_commod(plp->plane.pln_own,
608 plp->plane.pln_x, plp->plane.pln_y,
611 if (item[itype] < needed) {
612 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
615 item[itype] -= needed;
617 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
622 if (pp->pln_ship >= 0) {
623 if (pp->pln_own != ship.shp_own) {
625 "%s %s prepares for takeoff from ship %s\n",
626 cname(pp->pln_own), prplane(pp), prship(&ship));
628 putship(ship.shp_uid, &ship);
629 } else if (pp->pln_land >= 0) {
630 if (pp->pln_own != land.lnd_own) {
632 "%s %s prepares for takeoff from unit %s\n",
633 cname(pp->pln_own), prplane(pp), prland(&land));
635 putland(land.lnd_uid, &land);
637 if (pp->pln_own != sect.sct_own) {
638 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
639 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
649 pln_put(struct emp_qelem *list)
651 register struct emp_qelem *qp;
652 register struct emp_qelem *newqp;
658 /* Here is where planes return home from bombing runs.
659 We need to make sure they still have somewhere to return
663 plp = (struct plist *)qp;
665 /* Ok, check out where it wants to land */
666 if (pp->pln_ship >= 0) {
667 /* It is landing on a carrier */
668 getship(pp->pln_ship, &ship);
669 /* We should do more, like make sure it's really
670 a carrier, etc. but for now just make sure it's
672 if (ship.shp_effic < SHIP_MINEFF) {
674 "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n",
675 pp->pln_ship, pp->pln_uid);
679 /* Presume we are landing back in a sector. */
680 getsect(pp->pln_x, pp->pln_y, §);
681 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
683 "Nowwhere to land at %s, plane #%d crashes and burns...\n",
684 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
688 putplane(pp->pln_uid, pp);
697 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
699 struct emp_qelem *bomb;
700 struct emp_qelem *esc;
704 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
706 bomb = bomb_list->q_forw;
707 while (bomb != bomb_list) {
708 if (QEMPTY(esc_list)) {
712 esc = esc_list->q_forw;
713 bombp = (struct plist *)bomb;
714 while (esc != esc_list) {
715 escp = (struct plist *)esc;
716 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
728 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
730 struct plchrstr *pcp;
733 pcp = &plchr[(int)plane->pln_type];
734 mcp = &mchr[(int)ship->shp_type];
736 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
737 return 1; /* Already on ship */
739 /* Try to put on ship as a chopper plane */
740 if ((pcp->pl_flags & P_K) &&
741 (mcp->m_flags & M_CHOPPER) &&
742 (ship->shp_nchoppers < mcp->m_nchoppers)) {
744 ship->shp_nchoppers++;
745 plane->pln_x = ship->shp_x;
746 plane->pln_y = ship->shp_y;
747 plane->pln_ship = ship->shp_uid;
748 putship(ship->shp_uid, ship);
749 putplane(plane->pln_uid, plane);
753 /* Try to put on ship as an xlight plane */
754 if ((pcp->pl_flags & P_E) &&
755 (mcp->m_flags & M_XLIGHT) &&
756 (ship->shp_nxlight < mcp->m_nxlight)) {
759 plane->pln_x = ship->shp_x;
760 plane->pln_y = ship->shp_y;
761 plane->pln_ship = ship->shp_uid;
762 putship(ship->shp_uid, ship);
763 putplane(plane->pln_uid, plane);
767 /* Try to put on ship as a normal plane */
768 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
769 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
770 (mcp->m_flags & M_MSL))) &&
771 (ship->shp_nplane < mcp->m_nplanes)) {
774 plane->pln_x = ship->shp_x;
775 plane->pln_y = ship->shp_y;
776 plane->pln_ship = ship->shp_uid;
777 putship(ship->shp_uid, ship);
778 putplane(plane->pln_uid, plane);
787 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
789 struct plchrstr *pcp;
792 pcp = &plchr[(int)plane->pln_type];
793 mcp = &mchr[(int)ship->shp_type];
795 /* Try to take off ship as a chopper plane */
796 if ((pcp->pl_flags & P_K) &&
797 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
799 ship->shp_nchoppers--;
800 plane->pln_ship = -1;
801 putship(ship->shp_uid, ship);
802 putplane(plane->pln_uid, plane);
806 /* Try to take off ship as an xlight plane */
807 if ((pcp->pl_flags & P_E) &&
808 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
811 plane->pln_ship = -1;
812 putship(ship->shp_uid, ship);
813 putplane(plane->pln_uid, plane);
817 /* Try to take off ship as a normal plane */
818 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
819 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
820 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
823 plane->pln_ship = -1;
824 putship(ship->shp_uid, ship);
825 putplane(plane->pln_uid, plane);
834 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
836 struct plchrstr *pcp;
839 pcp = &plchr[(int)plane->pln_type];
840 lcp = &lchr[(int)land->lnd_type];
842 /* Try to take off ship as an xlight plane */
843 if ((pcp->pl_flags & P_E) &&
844 (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) {
847 plane->pln_land = -1;
848 putland(land->lnd_uid, land);
849 putplane(plane->pln_uid, plane);
858 can_be_on_ship(int p, int s)
862 struct plchrstr *pcp;
868 pcp = &plchr[(int)plane.pln_type];
869 mcp = &mchr[(int)ship.shp_type];
871 if (pcp->pl_flags & P_L)
872 if (mcp->m_flags & M_FLY)
875 if (pcp->pl_flags & P_K)
876 if (mcp->m_flags & M_CHOPPER)
879 if (pcp->pl_flags & P_M)
880 if (mcp->m_flags & M_MSL)
883 if (pcp->pl_flags & P_E)
884 if (mcp->m_flags & M_XLIGHT)
891 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
894 struct plchrstr *pcp;
895 struct emp_qelem *qp;
896 struct emp_qelem *next;
902 getsect(x, y, §);
903 mines_there = sect.sct_mines;
905 if (mines_there == 0)
908 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
911 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
914 ip = (struct plist *)qp;
917 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
920 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
922 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
928 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
929 writemap(player->cnum);
930 sect.sct_mines = mines_there;
935 count_planes(struct shpstr *sp)
939 struct plchrstr *pcp;
945 if (sp->shp_effic < SHIP_MINEFF)
948 mcp = &mchr[(int)sp->shp_type];
949 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
950 while (nxtitem(&ni, (s_char *)&plane)) {
951 if (plane.pln_own == 0)
953 if (plane.pln_ship == sp->shp_uid) {
954 pcp = &plchr[(int)plane.pln_type];
955 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
957 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
959 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
964 if (nplane != sp->shp_nplane ||
965 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
966 sp->shp_nplane = nplane;
967 sp->shp_nxlight = nxlight;
968 sp->shp_nchoppers = nchoppers;
969 putship(sp->shp_uid, sp);
974 count_land_planes(struct lndstr *lp)
980 if (lp->lnd_effic < LAND_MINEFF)
983 snxtitem_all(&ni, EF_PLANE);
984 while (nxtitem(&ni, (s_char *)&plane)) {
985 if (plane.pln_own == 0)
987 if (plane.pln_land == lp->lnd_uid)
991 if (lp->lnd_nxlight != nplane) {
992 lp->lnd_nxlight = nplane;
993 putland(lp->lnd_uid, lp);
998 count_sect_planes(struct sctstr *sp)
1001 struct nstr_item ni;
1002 struct plnstr plane;
1004 snxtitem_all(&ni, EF_PLANE);
1005 while (nxtitem(&ni, (s_char *)&plane)) {
1008 if (plane.pln_flags & PLN_LAUNCHED)
1010 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1018 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1020 struct plchrstr *pcp;
1021 struct lchrstr *lcp;
1023 pcp = &plchr[(int)plane->pln_type];
1024 lcp = &lchr[(int)land->lnd_type];
1026 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1027 return 1; /* Already on unit */
1029 /* Try to put on unit as an xlight plane */
1030 if ((pcp->pl_flags & P_E) &&
1031 (lcp->l_flags & L_XLIGHT) &&
1032 (land->lnd_nxlight < lcp->l_nxlight)) {
1034 land->lnd_nxlight++;
1035 plane->pln_x = land->lnd_x;
1036 plane->pln_y = land->lnd_y;
1037 plane->pln_land = land->lnd_uid;
1038 putland(land->lnd_uid, land);
1039 putplane(plane->pln_uid, plane);
1043 /* We have failed */
1048 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1050 struct plchrstr *pcp = plchr + pp->pln_type;
1051 float tfact = (float)(pp->pln_tech - pcp->pl_tech) /
1052 (pp->pln_tech - pcp->pl_tech / 2);
1053 int acc = pp->pln_acc;
1056 if (type == EF_SHIP) {
1057 if (pcp->pl_flags & P_A)
1059 if (!(pcp->pl_flags & P_T))
1062 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1063 (1.0 - (float)acc / 100.0)) - hardtarget;
1065 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1067 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1068 if (hitchance > 100)
1073 /* return 0 if there was a nuclear detonation */
1076 pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp,
1079 struct plchrstr *pcp = plchr + pp->pln_type;
1087 if (pp->pln_nuketype != (s_char)-1) {
1088 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1089 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1090 *nukedamp = detonate(pp, x, y);
1095 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1098 i = roll(pp->pln_load) + 1;
1099 if (i > pp->pln_load)
1102 if (pcp->pl_flags & P_M) {
1103 if (pcp->pl_flags & P_MAR)
1105 } else if (pcp->pl_flags & P_T)
1108 aim = 100 - pp->pln_acc;
1122 hitroll = roll(100);
1123 if (hitroll >= 90) {
1126 mpr(pp->pln_own, "BLAM");
1127 } else if (hitroll < aim) {
1130 mpr(pp->pln_own, "Blam");
1134 mpr(pp->pln_own, "blam");
1137 mpr(pp->pln_own, "-");
1140 mpr(pp->pln_own, "\n");
1147 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1150 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1151 return (int)(100 - 100 * misschance * misschance);
1155 pln_mobcost(int dist, struct plnstr *pp, int flags)
1159 if ((flags & P_F) || (flags & P_ESC))
1160 cost = 10 * 100 / pp->pln_effic;
1162 cost = 20 * 100 / pp->pln_effic;
1164 cost = ldround((double)cost * dist / pp->pln_range_max, 1);
1166 return min(32 + pp->pln_mobil, cost + 5);