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 int all_missiles(struct emp_qelem *);
61 static void ac_dog(struct plist *, struct plist *);
62 static void ac_planedamage(struct plist *, natid, int, natid, int,
64 static void ac_doflak(struct emp_qelem *, struct sctstr *);
65 static void ac_landflak(struct emp_qelem *, coord, coord);
66 static void ac_shipflak(struct emp_qelem *, coord, coord);
67 static void ac_fireflak(struct emp_qelem *, natid, int);
68 static void getilist(struct emp_qelem *, natid);
69 static int do_evade(struct emp_qelem *, struct emp_qelem *);
72 ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
73 coord x, coord y, char *path, int mission_flags,
76 int val, non_missiles;
82 int unfriendly[MAXNOC];
85 struct emp_qelem ilist[MAXNOC], *qp;
95 struct natstr *over, *mynatp;
98 struct shiplist *head = NULL;
100 /* We want to only intercept once per sector per owner. So, if we overfly
101 a sector, and then overfly some land units or ships, we don't want to
102 potentially intercept 3 times. */
104 plp = (struct plist *)bomb_list->q_forw;
105 plane_owner = plp->plane.pln_own;
107 strncpy(mypath, path, sizeof(mypath));
110 memset(overfly, 0, sizeof(overfly));
111 memset(gotilist, 0, sizeof(gotilist));
112 memset(unfriendly, 0, sizeof(unfriendly));
113 for (cn = 1; cn < MAXNOC; cn++) {
114 if ((mynatp = getnatp(cn)) == 0)
116 rel = getrel(mynatp, plane_owner);
119 if (plane_owner == cn)
123 if (mission_flags & PM_R) {
124 flags = plane_caps(bomb_list);
126 PR(plane_owner, "\nSPY Plane report\n");
129 } else if (flags & P_A) {
130 PR(plane_owner, "\nAnti-Sub Patrol report\n");
132 PR(plane_owner, "\nReconnaissance report\n");
137 while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) {
138 if ((val = diridx(dir)) == DIR_STOP)
140 /* XXX using xnorm is probably bad */
141 x = xnorm(x + diroff[val][0]);
142 y = ynorm(y + diroff[val][1]);
143 getsect(x, y, §);
144 over = getnatp(sect.sct_own);
146 if (mission_flags & PM_R) {
147 flags = plane_caps(bomb_list);
149 setcont(plane_owner, sect.sct_own, FOUND_FLY);
150 if (sect.sct_type == SCT_WATER) {
151 PR(plane_owner, "flying over %s at %s\n",
152 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
153 if (mission_flags & PM_S)
154 plane_sweep(bomb_list, x, y);
156 plane_sona(bomb_list, x, y, &head);
157 changed += map_set(plane_owner,
158 sect.sct_x, sect.sct_y,
159 dchr[sect.sct_type].d_mnem, 0);
160 } else if (flags & P_S) {
161 satdisp_sect(§, flags & P_I ? 10 : 50);
163 /* This is borrowed from lookout */
164 if (sect.sct_own == plane_owner)
165 PR(plane_owner, "Your ");
167 PR(plane_owner, "%s (#%d) ",
168 cname(sect.sct_own), sect.sct_own);
169 PR(plane_owner, "%s", dchr[sect.sct_type].d_name);
170 changed += map_set(plane_owner,
171 sect.sct_x, sect.sct_y,
172 dchr[sect.sct_type].d_mnem, 0);
173 PR(plane_owner, " %d%% efficient ",
174 (sect.sct_own == plane_owner) ?
175 sect.sct_effic : roundintby((int)sect.sct_effic, 25));
176 civ = sect.sct_item[I_CIVIL];
177 mil = sect.sct_item[I_MILIT];
179 PR(plane_owner, "with %s%d civ ",
180 (sect.sct_own == plane_owner) ?
182 (sect.sct_own == plane_owner) ?
183 civ : roundintby(civ, 25));
185 PR(plane_owner, "with %s%d mil ",
186 (sect.sct_own == plane_owner) ?
188 (sect.sct_own == plane_owner) ?
189 mil : roundintby(mil, 25));
190 PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner));
193 satdisp_units(sect.sct_x, sect.sct_y);
195 PR(plane_owner, "flying over %s at %s\n",
196 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
197 changed += map_set(plane_owner, sect.sct_x, sect.sct_y,
198 dchr[sect.sct_type].d_mnem, 0);
200 if ((rel = getrel(over, plane_owner)) == ALLIED)
203 evaded = do_evade(bomb_list, esc_list);
205 if (sect.sct_own != 0 && sect.sct_own != plane_owner && !evaded) {
206 /* We only show planes overhead if they didn't
208 overfly[sect.sct_own]++;
209 PR(sect.sct_own, "%s planes spotted over %s\n",
210 cname(plane_owner), xyas(x, y, sect.sct_own));
212 setcont(cn, plane_owner, FOUND_FLY);
217 if (unfriendly[sect.sct_own])
218 ac_doflak(bomb_list, §);
219 /* If bombers left, fire flak from units and ships */
220 if (!QEMPTY(bomb_list))
221 ac_landflak(bomb_list, x, y);
222 if (!QEMPTY(bomb_list))
223 ac_shipflak(bomb_list, x, y);
225 /* mission planes aborted due to flak -- don't send escorts */
226 if (QEMPTY(bomb_list))
228 if (!no_air_defense && !evaded)
229 air_defense(x, y, plane_owner, bomb_list, esc_list);
231 if (sect.sct_own == 0 || sect.sct_own == plane_owner)
238 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
239 struct plist *ip = (struct plist *)qp;
240 if (!(plchr[(int)ip->plane.pln_type].pl_flags & P_M))
247 if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) {
248 getilist(&ilist[sect.sct_own], sect.sct_own);
249 gotilist[sect.sct_own]++;
253 ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
257 /* Let's report all of the overflights even if aborted */
258 for (cn = 1; cn < MAXNOC; cn++) {
259 if (plane_owner == cn)
262 nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]);
264 /* If the map changed, update it */
266 writemap(player->cnum);
267 /* Now, if the bomber and escort lists are empty, we are done */
268 if (QEMPTY(bomb_list) && QEMPTY(esc_list))
271 /* Something made it through */
272 /* Go figure out if there are ships in this sector, and who's they are */
273 memset(nats, 0, sizeof(nats));
274 snxtitem_xy(&ni, EF_SHIP, x, y);
275 while (nxtitem(&ni, &ship)) {
276 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
278 nats[ship.shp_own]++;
280 /* Go figure out if there are units in this sector, and who's they are */
281 memset(lnats, 0, sizeof(lnats));
282 snxtitem_xy(&ni, EF_LAND, x, y);
283 while (nxtitem(&ni, &land)) {
284 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
286 lnats[land.lnd_own]++;
289 /* Now, let's make life a little rougher. */
290 for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
291 if (plane_owner == cn)
294 PR(plane_owner, "Flying over %s ships in %s\n",
295 cname(cn), xyas(x, y, plane_owner));
296 PR(cn, "%s planes spotted over ships in %s\n",
297 cname(plane_owner), xyas(x, y, cn));
299 if (lnats[cn] != 0) {
300 PR(plane_owner, "Flying over %s land units in %s\n",
301 cname(cn), xyas(x, y, plane_owner));
302 PR(cn, "%s planes spotted over land units in %s\n",
303 cname(plane_owner), xyas(x, y, cn));
305 if (nats[cn] || lnats[cn]) {
307 setcont(cn, plane_owner, FOUND_FLY);
308 if (unfriendly[cn] && !evaded) {
310 getilist(&ilist[cn], cn);
313 ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x, y);
318 free_shiplist(&head);
319 for (cn = 1; cn < MAXNOC; cn++) {
326 plane_caps(struct emp_qelem *list)
328 struct emp_qelem *qp;
333 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
334 plp = (struct plist *)qp;
335 fl |= plp->pcp->pl_flags;
342 count_non_missiles(struct emp_qelem *list)
344 struct emp_qelem *qp;
348 /* don't intercept missiles */
349 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
350 plp = (struct plist *)qp;
351 if (!(plp->pcp->pl_flags & P_M))
358 sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
359 natid def_own, natid plane_owner, coord x, coord y,
362 struct emp_qelem *aqp;
363 struct emp_qelem *anext;
364 struct emp_qelem *dqp;
365 struct emp_qelem *dnext;
370 for (aqp = att_list->q_forw,
371 dqp = def_list->q_forw;
372 aqp != att_list && dqp != def_list; aqp = anext) {
374 aplp = (struct plist *)aqp;
375 if (aplp->pcp->pl_flags & P_M)
377 if (aplp->pcp->pl_cost < 1000)
379 for (; dqp != def_list; dqp = dnext) {
381 dplp = (struct plist *)dqp;
382 if (!(dplp->pcp->pl_flags & P_M))
385 if (dplp->plane.pln_range <
386 mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) {
391 if (CANT_HAPPEN(dplp->plane.pln_flags & PLN_LAUNCHED)
392 || mission_pln_equip(dplp, 0, P_F, 0) < 0) {
397 dplp->plane.pln_flags |= PLN_LAUNCHED;
398 putplane(dplp->plane.pln_uid, &dplp->plane);
401 PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
402 PR(def_own, "Launching SAMs at %s planes over %s!\n",
403 cname(plane_owner), xyas(x, y, def_own));
404 ac_combat_headers(plane_owner, def_own);
412 PR(plane_owner, "\n");
415 if (delete_missiles) {
416 for (; dqp != def_list; dqp = dnext) {
418 dplp = (struct plist *)dqp;
419 if (!(dplp->pcp->pl_flags & P_M))
429 ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
430 struct emp_qelem *def_list, natid def_own, coord x, coord y)
435 struct emp_qelem *next;
436 struct emp_qelem *qp;
437 struct emp_qelem int_list;
442 plp = (struct plist *)bomb_list->q_forw;
443 plane_owner = plp->plane.pln_own;
447 sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0);
448 sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 1);
449 if (!(att_count = count_non_missiles(bomb_list) +
450 count_non_missiles(esc_list)))
453 emp_initque(&int_list);
454 for (qp = def_list->q_forw; qp != def_list; qp = next) {
456 plp = (struct plist *)qp;
458 /* SAMs interdict separately */
459 if (plp->pcp->pl_flags & P_M)
461 dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2;
462 if (pp->pln_range < dist)
464 if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED)
465 || mission_pln_equip(plp, 0, P_F, 0) < 0) {
470 /* got one; delete from def_list, add to int_list */
472 emp_insque(qp, &int_list);
473 pp->pln_flags |= PLN_LAUNCHED;
474 pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
475 putplane(pp->pln_uid, pp);
477 if (icount > att_count)
482 PR(plane_owner, "%d %s fighter%s rising to intercept!\n",
483 icount, cname(def_own), icount == 1 ? " is" : "s are");
484 PR(def_own, "%d fighter%s intercepting %s planes over %s!\n",
485 icount, icount == 1 ? " is" : "s are", cname(plane_owner),
486 xyas(x, y, def_own));
487 ac_combat_headers(plane_owner, def_own);
488 ac_airtoair(esc_list, &int_list);
489 ac_airtoair(bomb_list, &int_list);
490 PR(plane_owner, "\n");
496 ac_combat_headers(natid plane_owner, natid def_own)
499 " %-10.10s %-10.10s strength int odds damage results\n",
500 cname(plane_owner), cname(def_own));
502 " %-10.10s %-10.10s strength int odds damage results\n",
503 cname(def_own), cname(plane_owner));
510 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list)
512 struct plist *attacker;
513 struct plist *interceptor;
514 struct emp_qelem *att;
515 struct emp_qelem *in;
519 struct emp_qelem *att_next;
520 struct emp_qelem *in_next;
522 att = att_list->q_forw;
523 in = int_list->q_forw;
526 if (QEMPTY(att_list) || QEMPTY(int_list)) {
530 while (more_att || more_int) {
531 in_next = in->q_forw;
532 att_next = att->q_forw;
533 attacker = (struct plist *)att;
535 /* skip missiles. If only missiles left, we're done */
536 if (plchr[(int)attacker->plane.pln_type].pl_flags & P_M) {
538 if (att == att_list) {
540 if (QEMPTY(att_list))
545 if (all_missiles(att_list))
549 interceptor = (struct plist *)in;
550 nplanes = attacker->plane.pln_effic;
551 if (nplanes > interceptor->plane.pln_effic)
552 nplanes = interceptor->plane.pln_effic;
553 ac_dog(attacker, interceptor);
556 if (att == att_list) {
558 if (QEMPTY(att_list))
563 if (in == int_list) {
565 if (QEMPTY(int_list))
574 all_missiles(struct emp_qelem *att_list)
576 struct emp_qelem *qp;
579 qp = att_list->q_forw;
580 while (qp != att_list) {
581 p = (struct plist *)qp;
582 if (!(plchr[(int)p->plane.pln_type].pl_flags & P_M))
591 ac_dog(struct plist *ap, struct plist *dp)
596 natid att_own, def_own;
601 att_own = ap->plane.pln_own;
602 def_own = dp->plane.pln_own;
604 PR(att_own, " %3.3s #%-4d %3.3s #%-4d",
606 ap->plane.pln_uid, dp->pcp->pl_name, dp->plane.pln_uid);
608 PR(def_own, " %3.3s #%-4d %3.3s #%-4d",
610 dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid);
611 att = pln_att(&ap->plane);
613 att = pln_def(&ap->plane);
614 att = att * ap->plane.pln_effic / 100;
615 att = MAX(att, ap->pcp->pl_def / 2);
617 def = pln_def(&dp->plane) * dp->plane.pln_effic / 100;
618 def = MAX(def, dp->pcp->pl_def / 2);
620 if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
622 if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
624 att += ap->pcp->pl_stealth / 25.0;
625 def += dp->pcp->pl_stealth / 25.0;
634 odds = ((double)att / ((double)def + (double)att));
637 intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1;
639 PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds);
640 PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds);
644 while ((intensity--) > 0) {
648 if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF)
652 if ((ap->plane.pln_effic - adam) < PLANE_MINEFF)
657 if (dp->pcp->pl_flags & P_M)
660 PR(att_own, "%3d/%-3d", adam, ddam);
661 PR(def_own, "%3d/%-3d", ddam, adam);
662 ac_planedamage(ap, def_own, adam, def_own, 1, 0, mesg);
663 strncpy(temp, mesg, 14);
664 ac_planedamage(dp, att_own, ddam, att_own, 1, 0, mesg);
665 PR(att_own, "%-13.13s %-13.13s\n", temp, mesg);
666 PR(def_own, "%-13.13s %-13.13s\n", mesg, temp);
669 setcont(att_own, def_own, FOUND_FLY);
670 setcont(def_own, att_own, FOUND_FLY);
675 * zap plane associated with plp.
676 * Damaging country is "from", damage is "dam".
677 * def_own is the country on the other side of the conflict from the plane
678 * owner. The only time def_own != from is when the interceptor is getting
681 * NOTE: This routine removes the appropriate plane element from the
682 * queue if it gets destroyed. That means that the caller must assume
683 * that the current queue pointer is invalid on return from the ac_planedamage
684 * call. (this has caused bugs in the past)
687 ac_planedamage(struct plist *plp, natid from, int dam, natid other,
688 int checkabort, int show, char *mesg)
698 plane_owner = pp->pln_own;
700 sprintf(dmess, " no damage");
705 memset(dmess, 0, sizeof(dmess));
709 if (eff < PLANE_MINEFF) {
710 sprintf(dmess, " shot down");
712 } else if (eff < 80 && chance((80 - eff) / 100.0) && checkabort) {
713 sprintf(dmess, " aborted @%2d%%", eff);
715 } else if (show == 0) {
716 sprintf(dmess, " cleared");
719 if ((plp->pcp->pl_flags & P_M) == 0) {
721 PR(plane_owner, " %s %s takes %d%s.\n",
722 cname(pp->pln_own), prplane(pp), dam, dmess);
724 PR(other, " %s %s takes %d%s.\n",
725 cname(pp->pln_own), prplane(pp), dam, dmess);
728 if (show && checkabort == 1) {
729 PR(plane_owner, "\n");
735 pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
737 if (disp == 1 && from != 0 && (plp->pcp->pl_flags & P_M) == 0)
738 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
741 putplane(pp->pln_uid, pp);
746 ac_doflak(struct emp_qelem *list, struct sctstr *from)
753 plp = (struct plist *)list->q_forw;
754 plane_owner = plp->plane.pln_own;
756 gun = MIN(FLAK_GUN_MAX, from->sct_item[I_GUN]);
757 shell = from->sct_item[I_SHELL];
758 if (gun > shell * 2) {
759 shell += supply_commod(from->sct_own, from->sct_x, from->sct_y,
760 I_SHELL, (gun + 1) / 2 - shell);
761 from->sct_item[I_SHELL] = shell;
767 gun = roundavg(tfact(from->sct_own, 2.0 * gun));
769 PR(plane_owner, "firing %d flak guns in %s...\n",
770 gun, xyas(from->sct_x, from->sct_y, plane_owner));
771 if (from->sct_own != 0)
772 PR(from->sct_own, "firing %d flak guns in %s...\n",
773 gun, xyas(from->sct_x, from->sct_y, from->sct_own));
774 ac_fireflak(list, from->sct_own, gun);
779 ac_shipflak(struct emp_qelem *list, coord x, coord y)
784 double flak, total, ngun;
792 plp = (struct plist *)list->q_forw;
793 plane_owner = plp->plane.pln_own;
795 memset(nats, 0, sizeof(nats));
797 snxtitem_xy(&ni, EF_SHIP, x, y);
798 while (!QEMPTY(list) && nxtitem(&ni, &ship)) {
799 if (ship.shp_own == 0 || ship.shp_own == plane_owner)
801 mcp = &mchr[(int)ship.shp_type];
802 if (mcp->m_flags & M_SUB)
804 rel = getrel(getnatp(ship.shp_own), plane_owner);
808 gun = shp_usable_guns(&ship);
810 shell = ship.shp_item[I_SHELL];
812 shell = supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
814 ship.shp_item[I_SHELL] = shell;
815 putship(ship.shp_uid, &ship);
818 if (gun == 0 || shell == 0)
820 flak = gun * (ship.shp_effic / 100.0);
822 total += techfact(ship.shp_tech, flak * 2.0);
824 if (!nats[ship.shp_own]) {
825 /* First time here, print the message */
826 PR(ship.shp_own, "%s planes spotted over ships in %s\n",
827 cname(plane_owner), xyas(x, y, ship.shp_own));
828 PR(plane_owner, "Flying over %s ships in %s\n",
829 cname(ship.shp_own), xyas(x, y, plane_owner));
830 nats[ship.shp_own] = 1;
832 PR(ship.shp_own, "firing %.0f flak guns from %s...\n",
833 flak, prship(&ship));
837 /* Limit to FLAK_GUN_MAX guns of average tech factor */
838 if (ngun > FLAK_GUN_MAX)
839 total *= FLAK_GUN_MAX / ngun;
841 gun = roundavg(total);
843 PR(plane_owner, "Flak! Ships firing %d flak guns...\n", gun);
844 ac_fireflak(list, from, gun);
849 ac_landflak(struct emp_qelem *list, coord x, coord y)
854 double flak, total, ngun;
862 plp = (struct plist *)list->q_forw;
863 plane_owner = plp->plane.pln_own;
865 memset(nats, 0, sizeof(nats));
867 snxtitem_xy(&ni, EF_LAND, x, y);
868 while (!QEMPTY(list) && nxtitem(&ni, &land)) {
869 if (land.lnd_own == 0 || land.lnd_own == plane_owner)
871 lcp = &lchr[(int)land.lnd_type];
872 aaf = lnd_aaf(&land);
873 if ((lcp->l_flags & L_FLAK) == 0 || aaf == 0)
875 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
877 rel = getrel(getnatp(land.lnd_own), plane_owner);
880 flak = aaf * 1.5 * land.lnd_effic / 100.0;
882 total += techfact(land.lnd_tech, flak * 2.0);
884 if (!nats[land.lnd_own]) {
885 /* First time here, print the message */
886 PR(land.lnd_own, "%s planes spotted over land units in %s\n",
887 cname(plane_owner), xyas(x, y, land.lnd_own));
888 PR(plane_owner, "Flying over %s land units in %s\n",
889 cname(land.lnd_own), xyas(x, y, plane_owner));
890 nats[land.lnd_own] = 1;
892 PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
897 /* Limit to FLAK_GUN_MAX guns of average tech factor */
898 if (ngun > FLAK_GUN_MAX)
899 total *= FLAK_GUN_MAX / ngun;
901 gun = roundavg(total);
903 PR(plane_owner, "Flak! Land units firing %d flak guns...\n", gun);
904 ac_fireflak(list, from, gun);
909 * Called from shipflak, landflak, and doflak.
912 ac_fireflak(struct emp_qelem *list, natid from, int guns)
916 struct emp_qelem *qp;
917 struct emp_qelem *next;
920 plp = (struct plist *)list->q_forw;
922 for (qp = list->q_forw; qp != list; qp = next) {
924 plp = (struct plist *)qp;
925 n = ac_flak_dam(guns, pln_def(&plp->plane), plp->pcp->pl_flags);
926 ac_planedamage(plp, from, n, 0, 2, 1, msg);
931 * Calculate flak damage
934 ac_flak_dam(int guns, int def, int pl_flags)
938 /* <-7 -7 -6 -5 -4 */
939 static float flaktable[18] = { 0.132f, 0.20f, 0.20f, 0.25f, 0.30f,
940 /* -3 -2 -1 0 +1 +2 +3 +4 */
941 0.35f, 0.40f, 0.45f, 0.50f, 0.50f, 0.55f, 0.60f, 0.65f,
942 /* +5 +6 +7 +8 >+8 */
943 0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
944 enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
947 if ((pl_flags & P_T) == 0)
955 mult = flaktable[FLAK_MAX];
960 mult = flaktable[flak];
963 dam = (int)((roll(8) + 2) * mult);
970 * Get a list of planes available for interception duties.
973 getilist(struct emp_qelem *list, natid own)
975 struct plchrstr *pcp;
981 snxtitem_all(&ni, EF_PLANE);
982 while (nxtitem(&ni, &plane)) {
983 if (plane.pln_own != own)
985 pcp = &plchr[(int)plane.pln_type];
986 if ((pcp->pl_flags & P_F) == 0)
988 if (plane.pln_flags & PLN_LAUNCHED)
990 if (plane.pln_mission != 0)
992 if (plane.pln_mobil <= 0)
994 if (plane.pln_effic < 40)
996 if (!pln_airbase_ok(&plane, 0, 0))
999 ip = malloc(sizeof(*ip));
1002 ip->pcp = &plchr[(int)plane.pln_type];
1004 emp_insque(&ip->queue, list);
1009 do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
1011 struct emp_qelem *qp;
1016 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
1017 plp = (struct plist *)qp;
1018 if (evade > plp->pcp->pl_stealth / 100.0)
1019 evade = plp->pcp->pl_stealth / 100.0;
1021 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) {
1022 plp = (struct plist *)qp;
1023 if (evade > plp->pcp->pl_stealth / 100.0)
1024 evade = plp->pcp->pl_stealth / 100.0;