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)) {
356 if (CANT_HAPPEN(dplp->plane.pln_flags & PLN_LAUNCHED)
357 || mission_pln_equip(dplp, 0, P_F, 0) < 0) {
362 dplp->plane.pln_flags |= PLN_LAUNCHED;
363 putplane(dplp->plane.pln_uid, &dplp->plane);
366 PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
367 PR(def_own, "Launching SAMs at %s planes over %s!\n",
368 cname(plane_owner), xyas(x, y, def_own));
369 ac_combat_headers(plane_owner, def_own);
377 PR(plane_owner, "\n");
380 if (delete_missiles) {
381 for (; dqp != def_list; dqp = dnext) {
383 dplp = (struct plist *)dqp;
384 if (!(dplp->pcp->pl_flags & P_M))
394 ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
395 struct emp_qelem *def_list, natid def_own, coord x, coord y)
400 struct emp_qelem *next;
401 struct emp_qelem *qp;
402 struct emp_qelem int_list;
407 plp = (struct plist *)bomb_list->q_forw;
408 plane_owner = plp->plane.pln_own;
410 sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0);
411 sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 1);
414 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw)
416 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw)
421 emp_initque(&int_list);
423 for (qp = def_list->q_forw; qp != def_list; qp = next) {
425 plp = (struct plist *)qp;
427 /* SAMs interdict separately */
428 if (plp->pcp->pl_flags & P_M)
430 dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2;
431 if (pp->pln_range < dist)
433 if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED)
434 || mission_pln_equip(plp, 0, P_F, 0) < 0) {
439 /* got one; delete from def_list, add to int_list */
441 emp_insque(qp, &int_list);
442 pp->pln_flags |= PLN_LAUNCHED;
443 pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
444 putplane(pp->pln_uid, pp);
446 if (icount > att_count)
451 PR(plane_owner, "%d %s fighter%s rising to intercept!\n",
452 icount, cname(def_own), icount == 1 ? " is" : "s are");
453 PR(def_own, "%d fighter%s intercepting %s planes over %s!\n",
454 icount, icount == 1 ? " is" : "s are", cname(plane_owner),
455 xyas(x, y, def_own));
456 ac_combat_headers(plane_owner, def_own);
457 ac_airtoair(esc_list, &int_list);
458 ac_airtoair(bomb_list, &int_list);
459 PR(plane_owner, "\n");
465 ac_combat_headers(natid plane_owner, natid def_own)
468 " %-10.10s %-10.10s strength int odds damage results\n",
469 cname(plane_owner), cname(def_own));
471 " %-10.10s %-10.10s strength int odds damage results\n",
472 cname(def_own), cname(plane_owner));
479 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list)
481 struct plist *attacker;
482 struct plist *interceptor;
483 struct emp_qelem *att;
484 struct emp_qelem *in;
488 struct emp_qelem *att_next;
489 struct emp_qelem *in_next;
491 att = att_list->q_forw;
492 in = int_list->q_forw;
495 if (QEMPTY(att_list) || QEMPTY(int_list)) {
499 while (more_att || more_int) {
500 in_next = in->q_forw;
501 att_next = att->q_forw;
502 attacker = (struct plist *)att;
503 interceptor = (struct plist *)in;
504 nplanes = attacker->plane.pln_effic;
505 if (nplanes > interceptor->plane.pln_effic)
506 nplanes = interceptor->plane.pln_effic;
507 ac_dog(attacker, interceptor);
510 if (att == att_list) {
512 if (QEMPTY(att_list))
517 if (in == int_list) {
519 if (QEMPTY(int_list))
528 ac_dog(struct plist *ap, struct plist *dp)
533 natid att_own, def_own;
538 att_own = ap->plane.pln_own;
539 def_own = dp->plane.pln_own;
541 PR(att_own, " %3.3s #%-4d %3.3s #%-4d",
543 ap->plane.pln_uid, dp->pcp->pl_name, dp->plane.pln_uid);
545 PR(def_own, " %3.3s #%-4d %3.3s #%-4d",
547 dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid);
548 att = pln_att(&ap->plane);
550 att = pln_def(&ap->plane);
551 att = att * ap->plane.pln_effic / 100;
552 att = MAX(att, ap->pcp->pl_def / 2);
554 def = pln_def(&dp->plane) * dp->plane.pln_effic / 100;
555 def = MAX(def, dp->pcp->pl_def / 2);
557 if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
559 if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
561 att += ap->pcp->pl_stealth / 25.0;
562 def += dp->pcp->pl_stealth / 25.0;
571 odds = ((double)att / ((double)def + (double)att));
574 intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1;
576 PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds);
577 PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds);
581 while ((intensity--) > 0) {
585 if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF)
589 if ((ap->plane.pln_effic - adam) < PLANE_MINEFF)
594 if (dp->pcp->pl_flags & P_M)
597 PR(att_own, "%3d/%-3d", adam, ddam);
598 PR(def_own, "%3d/%-3d", ddam, adam);
599 ac_planedamage(ap, def_own, adam, def_own, 1, 0, mesg);
600 strncpy(temp, mesg, 14);
601 ac_planedamage(dp, att_own, ddam, att_own, 1, 0, mesg);
602 PR(att_own, "%-13.13s %-13.13s\n", temp, mesg);
603 PR(def_own, "%-13.13s %-13.13s\n", mesg, temp);
606 setcont(att_own, def_own, FOUND_FLY);
607 setcont(def_own, att_own, FOUND_FLY);
612 * zap plane associated with plp.
613 * Damaging country is "from", damage is "dam".
614 * def_own is the country on the other side of the conflict from the plane
615 * owner. The only time def_own != from is when the interceptor is getting
618 * NOTE: This routine removes the appropriate plane element from the
619 * queue if it gets destroyed. That means that the caller must assume
620 * that the current queue pointer is invalid on return from the ac_planedamage
621 * call. (this has caused bugs in the past)
624 ac_planedamage(struct plist *plp, natid from, int dam, natid other,
625 int checkabort, int show, char *mesg)
635 plane_owner = pp->pln_own;
637 sprintf(dmess, " no damage");
642 memset(dmess, 0, sizeof(dmess));
646 if (eff < PLANE_MINEFF) {
647 sprintf(dmess, " shot down");
649 } else if (eff < 80 && chance((80 - eff) / 100.0) && checkabort) {
650 sprintf(dmess, " aborted @%2d%%", eff);
652 } else if (show == 0) {
653 sprintf(dmess, " cleared");
656 if ((plp->pcp->pl_flags & P_M) == 0) {
658 PR(plane_owner, " %s %s takes %d%s.\n",
659 cname(pp->pln_own), prplane(pp), dam, dmess);
661 PR(other, " %s %s takes %d%s.\n",
662 cname(pp->pln_own), prplane(pp), dam, dmess);
665 if (show && checkabort == 1) {
666 PR(plane_owner, "\n");
672 pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
674 if (disp == 1 && from != 0 && (plp->pcp->pl_flags & P_M) == 0)
675 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
678 putplane(pp->pln_uid, pp);
683 ac_doflak(struct emp_qelem *list, struct sctstr *from)
690 plp = (struct plist *)list->q_forw;
691 plane_owner = plp->plane.pln_own;
693 gun = MIN(FLAK_GUN_MAX, from->sct_item[I_GUN]);
694 shell = from->sct_item[I_SHELL];
695 if (gun > shell * 2) {
696 shell += supply_commod(from->sct_own, from->sct_x, from->sct_y,
697 I_SHELL, (gun + 1) / 2 - shell);
698 from->sct_item[I_SHELL] = shell;
704 gun = roundavg(tfact(from->sct_own, 2.0 * gun));
706 PR(plane_owner, "firing %d flak guns in %s...\n",
707 gun, xyas(from->sct_x, from->sct_y, plane_owner));
708 if (from->sct_own != 0)
709 PR(from->sct_own, "firing %d flak guns in %s...\n",
710 gun, xyas(from->sct_x, from->sct_y, from->sct_own));
711 ac_fireflak(list, from->sct_own, gun);
716 ac_shipflak(struct emp_qelem *list, coord x, coord y)
721 double flak, total, ngun;
729 plp = (struct plist *)list->q_forw;
730 plane_owner = plp->plane.pln_own;
732 memset(nats, 0, sizeof(nats));
734 snxtitem_xy(&ni, EF_SHIP, x, y);
735 while (!QEMPTY(list) && nxtitem(&ni, &ship)) {
736 if (ship.shp_own == 0 || ship.shp_own == plane_owner)
738 mcp = &mchr[(int)ship.shp_type];
739 if (mcp->m_flags & M_SUB)
741 rel = getrel(getnatp(ship.shp_own), plane_owner);
745 gun = shp_usable_guns(&ship);
747 shell = ship.shp_item[I_SHELL];
749 shell = supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
751 ship.shp_item[I_SHELL] = shell;
752 putship(ship.shp_uid, &ship);
755 if (gun == 0 || shell == 0)
757 flak = gun * (ship.shp_effic / 100.0);
759 total += techfact(ship.shp_tech, flak * 2.0);
761 if (!nats[ship.shp_own]) {
762 /* First time here, print the message */
763 PR(ship.shp_own, "%s planes spotted over ships in %s\n",
764 cname(plane_owner), xyas(x, y, ship.shp_own));
765 PR(plane_owner, "Flying over %s ships in %s\n",
766 cname(ship.shp_own), xyas(x, y, plane_owner));
767 nats[ship.shp_own] = 1;
769 PR(ship.shp_own, "firing %.0f flak guns from %s...\n",
770 flak, prship(&ship));
774 /* Limit to FLAK_GUN_MAX guns of average tech factor */
775 if (ngun > FLAK_GUN_MAX)
776 total *= FLAK_GUN_MAX / ngun;
778 gun = roundavg(total);
780 PR(plane_owner, "Flak! Ships firing %d flak guns...\n", gun);
781 ac_fireflak(list, from, gun);
786 ac_landflak(struct emp_qelem *list, coord x, coord y)
791 double flak, total, ngun;
799 plp = (struct plist *)list->q_forw;
800 plane_owner = plp->plane.pln_own;
802 memset(nats, 0, sizeof(nats));
804 snxtitem_xy(&ni, EF_LAND, x, y);
805 while (!QEMPTY(list) && nxtitem(&ni, &land)) {
806 if (land.lnd_own == 0 || land.lnd_own == plane_owner)
808 lcp = &lchr[(int)land.lnd_type];
809 aaf = lnd_aaf(&land);
810 if ((lcp->l_flags & L_FLAK) == 0 || aaf == 0)
812 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
814 rel = getrel(getnatp(land.lnd_own), plane_owner);
817 flak = aaf * 1.5 * land.lnd_effic / 100.0;
819 total += techfact(land.lnd_tech, flak * 2.0);
821 if (!nats[land.lnd_own]) {
822 /* First time here, print the message */
823 PR(land.lnd_own, "%s planes spotted over land units in %s\n",
824 cname(plane_owner), xyas(x, y, land.lnd_own));
825 PR(plane_owner, "Flying over %s land units in %s\n",
826 cname(land.lnd_own), xyas(x, y, plane_owner));
827 nats[land.lnd_own] = 1;
829 PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
834 /* Limit to FLAK_GUN_MAX guns of average tech factor */
835 if (ngun > FLAK_GUN_MAX)
836 total *= FLAK_GUN_MAX / ngun;
838 gun = roundavg(total);
840 PR(plane_owner, "Flak! Land units firing %d flak guns...\n", gun);
841 ac_fireflak(list, from, gun);
846 * Called from shipflak, landflak, and doflak.
849 ac_fireflak(struct emp_qelem *list, natid from, int guns)
853 struct emp_qelem *qp;
854 struct emp_qelem *next;
857 plp = (struct plist *)list->q_forw;
859 for (qp = list->q_forw; qp != list; qp = next) {
861 plp = (struct plist *)qp;
862 n = ac_flak_dam(guns, pln_def(&plp->plane), plp->pcp->pl_flags);
863 ac_planedamage(plp, from, n, 0, 2, 1, msg);
868 * Calculate flak damage
871 ac_flak_dam(int guns, int def, int pl_flags)
875 /* <-7 -7 -6 -5 -4 */
876 static float flaktable[18] = { 0.132f, 0.20f, 0.20f, 0.25f, 0.30f,
877 /* -3 -2 -1 0 +1 +2 +3 +4 */
878 0.35f, 0.40f, 0.45f, 0.50f, 0.50f, 0.55f, 0.60f, 0.65f,
879 /* +5 +6 +7 +8 >+8 */
880 0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
881 enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
884 if ((pl_flags & P_T) == 0)
892 mult = flaktable[FLAK_MAX];
897 mult = flaktable[flak];
900 dam = (int)((roll(8) + 2) * mult);
907 * Get a list of planes available for interception duties.
910 getilist(struct emp_qelem *list, natid own)
912 struct plchrstr *pcp;
918 snxtitem_all(&ni, EF_PLANE);
919 while (nxtitem(&ni, &plane)) {
920 if (plane.pln_own != own)
922 pcp = &plchr[(int)plane.pln_type];
923 if ((pcp->pl_flags & P_F) == 0)
925 if (plane.pln_flags & PLN_LAUNCHED)
927 if (plane.pln_mission != 0)
929 if (plane.pln_mobil <= 0)
931 if (plane.pln_effic < 40)
933 if (!pln_airbase_ok(&plane, 0, 0))
936 ip = malloc(sizeof(*ip));
939 ip->pcp = &plchr[(int)plane.pln_type];
941 emp_insque(&ip->queue, list);
946 do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
948 struct emp_qelem *qp;
953 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
954 plp = (struct plist *)qp;
955 if (evade > plp->pcp->pl_stealth / 100.0)
956 evade = plp->pcp->pl_stealth / 100.0;
958 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) {
959 plp = (struct plist *)qp;
960 if (evade > plp->pcp->pl_stealth / 100.0)
961 evade = plp->pcp->pl_stealth / 100.0;