2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * aircombat.c: Deal with air to air combat
30 * Known contributors to this file:
32 * Thomas Ruschak, 1992
34 * Markus Armbruster, 2006-2008
50 #include "prototypes.h"
55 #define FLAK_GUN_MAX 14
57 static int plane_caps(struct emp_qelem *);
58 static void ac_intercept(struct emp_qelem *, struct emp_qelem *,
59 struct emp_qelem *, natid, coord, coord);
60 static void ac_dog(struct plist *, struct plist *);
61 static void ac_planedamage(struct plist *, natid, int, natid, int,
63 static void ac_doflak(struct emp_qelem *, struct sctstr *);
64 static void ac_landflak(struct emp_qelem *, coord, coord);
65 static void ac_shipflak(struct emp_qelem *, coord, coord);
66 static void ac_fireflak(struct emp_qelem *, natid, int);
67 static void getilist(struct emp_qelem *, natid);
68 static int do_evade(struct emp_qelem *, struct emp_qelem *);
71 ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
72 coord x, coord y, char *path, int mission_flags,
81 int unfriendly[MAXNOC];
84 struct emp_qelem ilist[MAXNOC];
94 struct natstr *mynatp;
97 struct shiplist *head = NULL;
99 /* We want to only intercept once per sector per owner. So, if we overfly
100 a sector, and then overfly some land units or ships, we don't want to
101 potentially intercept 3 times. */
103 plp = (struct plist *)bomb_list->q_forw;
104 plane_owner = plp->plane.pln_own;
106 strncpy(mypath, path, sizeof(mypath));
109 memset(overfly, 0, sizeof(overfly));
110 memset(gotilist, 0, sizeof(gotilist));
111 memset(unfriendly, 0, sizeof(unfriendly));
112 for (cn = 1; cn < MAXNOC; cn++) {
113 if ((mynatp = getnatp(cn)) == 0)
115 rel = getrel(mynatp, plane_owner);
118 if (plane_owner == cn)
122 if (mission_flags & PM_R) {
123 flags = plane_caps(bomb_list);
125 PR(plane_owner, "\nSPY Plane report\n");
128 } else if (flags & P_A) {
129 PR(plane_owner, "\nAnti-Sub Patrol report\n");
131 PR(plane_owner, "\nReconnaissance report\n");
136 while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) {
137 if ((val = diridx(dir)) == DIR_STOP)
139 /* XXX using xnorm is probably bad */
140 x = xnorm(x + diroff[val][0]);
141 y = ynorm(y + diroff[val][1]);
142 getsect(x, y, §);
144 if (mission_flags & PM_R) {
145 flags = plane_caps(bomb_list);
147 setcont(plane_owner, sect.sct_own, FOUND_FLY);
148 if (sect.sct_type == SCT_WATER) {
149 PR(plane_owner, "flying over %s at %s\n",
150 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
151 if (mission_flags & PM_S)
152 plane_sweep(bomb_list, x, y);
154 plane_sona(bomb_list, x, y, &head);
155 changed += map_set(plane_owner,
156 sect.sct_x, sect.sct_y,
157 dchr[sect.sct_type].d_mnem, 0);
158 } else if (flags & P_S) {
159 satdisp_sect(§, flags & P_I ? 10 : 50);
161 /* This is borrowed from lookout */
162 if (sect.sct_own == plane_owner)
163 PR(plane_owner, "Your ");
165 PR(plane_owner, "%s (#%d) ",
166 cname(sect.sct_own), sect.sct_own);
167 PR(plane_owner, "%s", dchr[sect.sct_type].d_name);
168 changed += map_set(plane_owner,
169 sect.sct_x, sect.sct_y,
170 dchr[sect.sct_type].d_mnem, 0);
171 PR(plane_owner, " %d%% efficient ",
172 (sect.sct_own == plane_owner) ?
173 sect.sct_effic : roundintby((int)sect.sct_effic, 25));
174 civ = sect.sct_item[I_CIVIL];
175 mil = sect.sct_item[I_MILIT];
177 PR(plane_owner, "with %s%d civ ",
178 (sect.sct_own == plane_owner) ?
180 (sect.sct_own == plane_owner) ?
181 civ : roundintby(civ, 25));
183 PR(plane_owner, "with %s%d mil ",
184 (sect.sct_own == plane_owner) ?
186 (sect.sct_own == plane_owner) ?
187 mil : roundintby(mil, 25));
188 PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner));
191 satdisp_units(sect.sct_x, sect.sct_y);
193 PR(plane_owner, "flying over %s at %s\n",
194 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
195 changed += map_set(plane_owner, sect.sct_x, sect.sct_y,
196 dchr[sect.sct_type].d_mnem, 0);
199 evaded = do_evade(bomb_list, esc_list);
203 if (sect.sct_own != 0 && sect.sct_own != plane_owner
204 && getrel(getnatp(sect.sct_own), plane_owner) != ALLIED) {
205 overfly[sect.sct_own]++;
206 PR(sect.sct_own, "%s planes spotted over %s\n",
207 cname(plane_owner), xyas(x, y, sect.sct_own));
209 setcont(sect.sct_own, plane_owner, FOUND_FLY);
213 if (unfriendly[sect.sct_own])
214 ac_doflak(bomb_list, §);
215 /* If bombers left, fire flak from units and ships */
216 if (!QEMPTY(bomb_list))
217 ac_landflak(bomb_list, x, y);
218 if (!QEMPTY(bomb_list))
219 ac_shipflak(bomb_list, x, y);
220 /* mission planes aborted due to flak -- don't send escorts */
221 if (QEMPTY(bomb_list))
225 air_defense(x, y, plane_owner, bomb_list, esc_list);
227 if (sect.sct_own == 0 || sect.sct_own == plane_owner)
230 if (unfriendly[sect.sct_own]) {
231 if (!gotilist[sect.sct_own]) {
232 getilist(&ilist[sect.sct_own], sect.sct_own);
233 gotilist[sect.sct_own]++;
235 ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
240 /* Let's report all of the overflights even if aborted */
241 for (cn = 1; cn < MAXNOC; cn++) {
242 if (plane_owner == cn)
245 nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]);
247 /* If the map changed, update it */
249 writemap(player->cnum);
250 /* Now, if the bomber and escort lists are empty, we are done */
251 if (QEMPTY(bomb_list) && QEMPTY(esc_list))
254 /* Something made it through */
255 /* Go figure out if there are ships in this sector, and who's they are */
256 memset(nats, 0, sizeof(nats));
257 snxtitem_xy(&ni, EF_SHIP, x, y);
258 while (nxtitem(&ni, &ship)) {
259 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
261 nats[ship.shp_own]++;
263 /* Go figure out if there are units in this sector, and who's they are */
264 memset(lnats, 0, sizeof(lnats));
265 snxtitem_xy(&ni, EF_LAND, x, y);
266 while (nxtitem(&ni, &land)) {
267 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
269 lnats[land.lnd_own]++;
272 /* Now, let's make life a little rougher. */
273 for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
274 if (plane_owner == cn)
277 PR(plane_owner, "Flying over %s ships in %s\n",
278 cname(cn), xyas(x, y, plane_owner));
279 PR(cn, "%s planes spotted over ships in %s\n",
280 cname(plane_owner), xyas(x, y, cn));
282 if (lnats[cn] != 0) {
283 PR(plane_owner, "Flying over %s land units in %s\n",
284 cname(cn), xyas(x, y, plane_owner));
285 PR(cn, "%s planes spotted over land units in %s\n",
286 cname(plane_owner), xyas(x, y, cn));
288 if (nats[cn] || lnats[cn]) {
290 setcont(cn, plane_owner, FOUND_FLY);
291 if (unfriendly[cn] && !evaded) {
293 getilist(&ilist[cn], cn);
296 ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x, y);
301 free_shiplist(&head);
302 for (cn = 1; cn < MAXNOC; cn++) {
309 plane_caps(struct emp_qelem *list)
311 struct emp_qelem *qp;
316 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
317 plp = (struct plist *)qp;
318 fl |= plp->pcp->pl_flags;
325 sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
326 natid def_own, natid plane_owner, coord x, coord y,
329 struct emp_qelem *aqp;
330 struct emp_qelem *anext;
331 struct emp_qelem *dqp;
332 struct emp_qelem *dnext;
337 for (aqp = att_list->q_forw,
338 dqp = def_list->q_forw;
339 aqp != att_list && dqp != def_list; aqp = anext) {
341 aplp = (struct plist *)aqp;
342 if (aplp->pcp->pl_cost < 1000)
344 for (; dqp != def_list; dqp = dnext) {
346 dplp = (struct plist *)dqp;
347 if (!(dplp->pcp->pl_flags & P_M))
350 if (dplp->plane.pln_range <
351 mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y))
353 if (CANT_HAPPEN(dplp->plane.pln_flags & PLN_LAUNCHED)
354 || mission_pln_equip(dplp, 0, P_F, 0) < 0) {
359 dplp->plane.pln_flags |= PLN_LAUNCHED;
360 putplane(dplp->plane.pln_uid, &dplp->plane);
363 PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
364 PR(def_own, "Launching SAMs at %s planes over %s!\n",
365 cname(plane_owner), xyas(x, y, def_own));
366 ac_combat_headers(plane_owner, def_own);
374 PR(plane_owner, "\n");
377 if (delete_missiles) {
378 for (; dqp != def_list; dqp = dnext) {
380 dplp = (struct plist *)dqp;
381 if (!(dplp->pcp->pl_flags & P_M))
391 ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
392 struct emp_qelem *def_list, natid def_own, coord x, coord y)
397 struct emp_qelem *next;
398 struct emp_qelem *qp;
399 struct emp_qelem int_list;
404 plp = (struct plist *)bomb_list->q_forw;
405 plane_owner = plp->plane.pln_own;
407 sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0);
408 sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 0);
411 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw)
413 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw)
418 emp_initque(&int_list);
420 for (qp = def_list->q_forw; qp != def_list; qp = next) {
422 plp = (struct plist *)qp;
424 /* SAMs interdict separately */
425 if (plp->pcp->pl_flags & P_M)
427 dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2;
428 if (pp->pln_range < dist)
430 if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED)
431 || mission_pln_equip(plp, 0, P_F, 0) < 0) {
436 /* got one; delete from def_list, add to int_list */
438 emp_insque(qp, &int_list);
439 pp->pln_flags |= PLN_LAUNCHED;
440 pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
441 putplane(pp->pln_uid, pp);
443 if (icount > att_count)
448 PR(plane_owner, "%d %s fighter%s rising to intercept!\n",
449 icount, cname(def_own), icount == 1 ? " is" : "s are");
450 PR(def_own, "%d fighter%s intercepting %s planes over %s!\n",
451 icount, icount == 1 ? " is" : "s are", cname(plane_owner),
452 xyas(x, y, def_own));
453 ac_combat_headers(plane_owner, def_own);
454 ac_airtoair(esc_list, &int_list);
455 ac_airtoair(bomb_list, &int_list);
456 PR(plane_owner, "\n");
462 ac_combat_headers(natid plane_owner, natid def_own)
465 " %-10.10s %-10.10s strength int odds damage results\n",
466 cname(plane_owner), cname(def_own));
468 " %-10.10s %-10.10s strength int odds damage results\n",
469 cname(def_own), cname(plane_owner));
476 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list)
478 struct plist *attacker;
479 struct plist *interceptor;
480 struct emp_qelem *att;
481 struct emp_qelem *in;
485 struct emp_qelem *att_next;
486 struct emp_qelem *in_next;
488 att = att_list->q_forw;
489 in = int_list->q_forw;
492 if (QEMPTY(att_list) || QEMPTY(int_list)) {
496 while (more_att || more_int) {
497 in_next = in->q_forw;
498 att_next = att->q_forw;
499 attacker = (struct plist *)att;
500 interceptor = (struct plist *)in;
501 nplanes = attacker->plane.pln_effic;
502 if (nplanes > interceptor->plane.pln_effic)
503 nplanes = interceptor->plane.pln_effic;
504 ac_dog(attacker, interceptor);
507 if (att == att_list) {
509 if (QEMPTY(att_list))
514 if (in == int_list) {
516 if (QEMPTY(int_list))
525 ac_dog(struct plist *ap, struct plist *dp)
530 natid att_own, def_own;
535 att_own = ap->plane.pln_own;
536 def_own = dp->plane.pln_own;
538 PR(att_own, " %3.3s #%-4d %3.3s #%-4d",
540 ap->plane.pln_uid, dp->pcp->pl_name, dp->plane.pln_uid);
542 PR(def_own, " %3.3s #%-4d %3.3s #%-4d",
544 dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid);
545 att = pln_att(&ap->plane);
547 att = pln_def(&ap->plane);
548 att = att * ap->plane.pln_effic / 100;
549 att = MAX(att, ap->pcp->pl_def / 2);
551 def = pln_def(&dp->plane) * dp->plane.pln_effic / 100;
552 def = MAX(def, dp->pcp->pl_def / 2);
554 if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
556 if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
558 att += ap->pcp->pl_stealth / 25.0;
559 def += dp->pcp->pl_stealth / 25.0;
568 odds = ((double)att / ((double)def + (double)att));
571 intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1;
573 PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds);
574 PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds);
578 while ((intensity--) > 0) {
582 if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF)
586 if ((ap->plane.pln_effic - adam) < PLANE_MINEFF)
591 if (dp->pcp->pl_flags & P_M)
594 PR(att_own, "%3d/%-3d", adam, ddam);
595 PR(def_own, "%3d/%-3d", ddam, adam);
596 ac_planedamage(ap, def_own, adam, def_own, 1, 0, mesg);
597 strncpy(temp, mesg, 14);
598 ac_planedamage(dp, att_own, ddam, att_own, 1, 0, mesg);
599 PR(att_own, "%-13.13s %-13.13s\n", temp, mesg);
600 PR(def_own, "%-13.13s %-13.13s\n", mesg, temp);
603 setcont(att_own, def_own, FOUND_FLY);
604 setcont(def_own, att_own, FOUND_FLY);
609 * zap plane associated with plp.
610 * Damaging country is "from", damage is "dam".
611 * def_own is the country on the other side of the conflict from the plane
612 * owner. The only time def_own != from is when the interceptor is getting
615 * NOTE: This routine removes the appropriate plane element from the
616 * queue if it gets destroyed. That means that the caller must assume
617 * that the current queue pointer is invalid on return from the ac_planedamage
618 * call. (this has caused bugs in the past)
621 ac_planedamage(struct plist *plp, natid from, int dam, natid other,
622 int checkabort, int show, char *mesg)
632 plane_owner = pp->pln_own;
634 sprintf(dmess, " no damage");
639 memset(dmess, 0, sizeof(dmess));
643 if (eff < PLANE_MINEFF) {
644 sprintf(dmess, " shot down");
646 } else if (eff < 80 && chance((80 - eff) / 100.0) && checkabort) {
647 sprintf(dmess, " aborted @%2d%%", eff);
649 } else if (show == 0) {
650 sprintf(dmess, " cleared");
653 if ((plp->pcp->pl_flags & P_M) == 0) {
655 PR(plane_owner, " %s %s takes %d%s.\n",
656 cname(pp->pln_own), prplane(pp), dam, dmess);
658 PR(other, " %s %s takes %d%s.\n",
659 cname(pp->pln_own), prplane(pp), dam, dmess);
662 if (show && checkabort == 1) {
663 PR(plane_owner, "\n");
669 pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
671 if (disp == 1 && from != 0 && (plp->pcp->pl_flags & P_M) == 0)
672 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
675 putplane(pp->pln_uid, pp);
680 ac_doflak(struct emp_qelem *list, struct sctstr *from)
687 plp = (struct plist *)list->q_forw;
688 plane_owner = plp->plane.pln_own;
690 gun = MIN(FLAK_GUN_MAX, from->sct_item[I_GUN]);
691 shell = from->sct_item[I_SHELL];
692 if (gun > shell * 2) {
693 shell += supply_commod(from->sct_own, from->sct_x, from->sct_y,
694 I_SHELL, (gun + 1) / 2 - shell);
695 from->sct_item[I_SHELL] = shell;
701 gun = roundavg(tfact(from->sct_own, 2.0 * gun));
703 PR(plane_owner, "firing %d flak guns in %s...\n",
704 gun, xyas(from->sct_x, from->sct_y, plane_owner));
705 if (from->sct_own != 0)
706 PR(from->sct_own, "firing %d flak guns in %s...\n",
707 gun, xyas(from->sct_x, from->sct_y, from->sct_own));
708 ac_fireflak(list, from->sct_own, gun);
713 ac_shipflak(struct emp_qelem *list, coord x, coord y)
718 double flak, total, ngun;
726 plp = (struct plist *)list->q_forw;
727 plane_owner = plp->plane.pln_own;
729 memset(nats, 0, sizeof(nats));
731 snxtitem_xy(&ni, EF_SHIP, x, y);
732 while (!QEMPTY(list) && nxtitem(&ni, &ship)) {
733 if (ship.shp_own == 0 || ship.shp_own == plane_owner)
735 mcp = &mchr[(int)ship.shp_type];
736 if (mcp->m_flags & M_SUB)
738 rel = getrel(getnatp(ship.shp_own), plane_owner);
742 gun = shp_usable_guns(&ship);
744 shell = ship.shp_item[I_SHELL];
746 shell = supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
748 ship.shp_item[I_SHELL] = shell;
749 putship(ship.shp_uid, &ship);
752 if (gun == 0 || shell == 0)
754 flak = gun * (ship.shp_effic / 100.0);
756 total += techfact(ship.shp_tech, flak * 2.0);
758 if (!nats[ship.shp_own]) {
759 /* First time here, print the message */
760 PR(ship.shp_own, "%s planes spotted over ships in %s\n",
761 cname(plane_owner), xyas(x, y, ship.shp_own));
762 PR(plane_owner, "Flying over %s ships in %s\n",
763 cname(ship.shp_own), xyas(x, y, plane_owner));
764 nats[ship.shp_own] = 1;
766 PR(ship.shp_own, "firing %.0f flak guns from %s...\n",
767 flak, prship(&ship));
771 /* Limit to FLAK_GUN_MAX guns of average tech factor */
772 if (ngun > FLAK_GUN_MAX)
773 total *= FLAK_GUN_MAX / ngun;
775 gun = roundavg(total);
777 PR(plane_owner, "Flak! Ships firing %d flak guns...\n", gun);
778 ac_fireflak(list, from, gun);
783 ac_landflak(struct emp_qelem *list, coord x, coord y)
788 double flak, total, ngun;
796 plp = (struct plist *)list->q_forw;
797 plane_owner = plp->plane.pln_own;
799 memset(nats, 0, sizeof(nats));
801 snxtitem_xy(&ni, EF_LAND, x, y);
802 while (!QEMPTY(list) && nxtitem(&ni, &land)) {
803 if (land.lnd_own == 0 || land.lnd_own == plane_owner)
805 lcp = &lchr[(int)land.lnd_type];
806 aaf = lnd_aaf(&land);
807 if ((lcp->l_flags & L_FLAK) == 0 || aaf == 0)
809 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
811 rel = getrel(getnatp(land.lnd_own), plane_owner);
814 flak = aaf * 1.5 * land.lnd_effic / 100.0;
816 total += techfact(land.lnd_tech, flak * 2.0);
818 if (!nats[land.lnd_own]) {
819 /* First time here, print the message */
820 PR(land.lnd_own, "%s planes spotted over land units in %s\n",
821 cname(plane_owner), xyas(x, y, land.lnd_own));
822 PR(plane_owner, "Flying over %s land units in %s\n",
823 cname(land.lnd_own), xyas(x, y, plane_owner));
824 nats[land.lnd_own] = 1;
826 PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
831 /* Limit to FLAK_GUN_MAX guns of average tech factor */
832 if (ngun > FLAK_GUN_MAX)
833 total *= FLAK_GUN_MAX / ngun;
835 gun = roundavg(total);
837 PR(plane_owner, "Flak! Land units firing %d flak guns...\n", gun);
838 ac_fireflak(list, from, gun);
843 * Called from shipflak, landflak, and doflak.
846 ac_fireflak(struct emp_qelem *list, natid from, int guns)
850 struct emp_qelem *qp;
851 struct emp_qelem *next;
854 plp = (struct plist *)list->q_forw;
856 for (qp = list->q_forw; qp != list; qp = next) {
858 plp = (struct plist *)qp;
859 n = ac_flak_dam(guns, pln_def(&plp->plane), plp->pcp->pl_flags);
860 ac_planedamage(plp, from, n, 0, 2, 1, msg);
865 * Calculate flak damage
868 ac_flak_dam(int guns, int def, int pl_flags)
872 /* <-7 -7 -6 -5 -4 */
873 static float flaktable[18] = { 0.132f, 0.20f, 0.20f, 0.25f, 0.30f,
874 /* -3 -2 -1 0 +1 +2 +3 +4 */
875 0.35f, 0.40f, 0.45f, 0.50f, 0.50f, 0.55f, 0.60f, 0.65f,
876 /* +5 +6 +7 +8 >+8 */
877 0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
878 enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
881 if ((pl_flags & P_T) == 0)
889 mult = flaktable[FLAK_MAX];
894 mult = flaktable[flak];
897 dam = (int)((roll(8) + 2) * mult);
904 * Get a list of planes available for interception duties.
907 getilist(struct emp_qelem *list, natid own)
909 struct plchrstr *pcp;
915 snxtitem_all(&ni, EF_PLANE);
916 while (nxtitem(&ni, &plane)) {
917 if (plane.pln_own != own)
919 pcp = &plchr[(int)plane.pln_type];
920 if ((pcp->pl_flags & P_F) == 0)
922 if (plane.pln_flags & PLN_LAUNCHED)
924 if (plane.pln_mission != 0)
926 if (plane.pln_mobil <= 0)
928 if (plane.pln_effic < 40)
930 if (!pln_airbase_ok(&plane, 0, 0))
933 ip = malloc(sizeof(*ip));
936 ip->pcp = &plchr[(int)plane.pln_type];
938 emp_insque(&ip->queue, list);
943 do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
945 struct emp_qelem *qp;
950 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
951 plp = (struct plist *)qp;
952 if (evade > plp->pcp->pl_stealth / 100.0)
953 evade = plp->pcp->pl_stealth / 100.0;
955 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) {
956 plp = (struct plist *)qp;
957 if (evade > plp->pcp->pl_stealth / 100.0)
958 evade = plp->pcp->pl_stealth / 100.0;