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 int intown = 0; /* Last owner to intercept */
101 /* We want to only intercept once per sector per owner. So, if we overfly
102 a sector, and then overfly some land units or ships, we don't want to
103 potentially intercept 3 times. */
105 plp = (struct plist *)bomb_list->q_forw;
106 plane_owner = plp->plane.pln_own;
108 strncpy(mypath, path, sizeof(mypath));
111 memset(overfly, 0, sizeof(overfly));
112 memset(gotilist, 0, sizeof(gotilist));
113 memset(unfriendly, 0, sizeof(unfriendly));
114 for (cn = 1; cn < MAXNOC; cn++) {
115 if ((mynatp = getnatp(cn)) == 0)
117 rel = getrel(mynatp, plane_owner);
120 if (plane_owner == cn)
124 if (mission_flags & PM_R) {
125 flags = plane_caps(bomb_list);
127 PR(plane_owner, "\nSPY Plane report\n");
130 } else if (flags & P_A) {
131 PR(plane_owner, "\nAnti-Sub Patrol report\n");
133 PR(plane_owner, "\nReconnaissance report\n");
138 while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) {
139 if ((val = diridx(dir)) == DIR_STOP)
141 /* XXX using xnorm is probably bad */
142 x = xnorm(x + diroff[val][0]);
143 y = ynorm(y + diroff[val][1]);
144 getsect(x, y, §);
145 over = getnatp(sect.sct_own);
147 if (mission_flags & PM_R) {
148 flags = plane_caps(bomb_list);
150 setcont(plane_owner, sect.sct_own, FOUND_FLY);
151 if (sect.sct_type == SCT_WATER) {
152 PR(plane_owner, "flying over %s at %s\n",
153 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
154 if (mission_flags & PM_S)
155 plane_sweep(bomb_list, x, y);
157 plane_sona(bomb_list, x, y, &head);
158 changed += map_set(plane_owner,
159 sect.sct_x, sect.sct_y,
160 dchr[sect.sct_type].d_mnem, 0);
161 } else if (flags & P_S) {
162 satdisp_sect(§, flags & P_I ? 10 : 50);
164 /* This is borrowed from lookout */
165 if (sect.sct_own == plane_owner)
166 PR(plane_owner, "Your ");
168 PR(plane_owner, "%s (#%d) ",
169 cname(sect.sct_own), sect.sct_own);
170 PR(plane_owner, "%s", dchr[sect.sct_type].d_name);
171 changed += map_set(plane_owner,
172 sect.sct_x, sect.sct_y,
173 dchr[sect.sct_type].d_mnem, 0);
174 PR(plane_owner, " %d%% efficient ",
175 (sect.sct_own == plane_owner) ?
176 sect.sct_effic : roundintby((int)sect.sct_effic, 25));
177 civ = sect.sct_item[I_CIVIL];
178 mil = sect.sct_item[I_MILIT];
180 PR(plane_owner, "with %s%d civ ",
181 (sect.sct_own == plane_owner) ?
183 (sect.sct_own == plane_owner) ?
184 civ : roundintby(civ, 25));
186 PR(plane_owner, "with %s%d mil ",
187 (sect.sct_own == plane_owner) ?
189 (sect.sct_own == plane_owner) ?
190 mil : roundintby(mil, 25));
191 PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner));
194 satdisp_units(sect.sct_x, sect.sct_y);
196 PR(plane_owner, "flying over %s at %s\n",
197 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
198 changed += map_set(plane_owner, sect.sct_x, sect.sct_y,
199 dchr[sect.sct_type].d_mnem, 0);
201 if ((rel = getrel(over, plane_owner)) == ALLIED)
204 evaded = do_evade(bomb_list, esc_list);
206 if (sect.sct_own != 0 && sect.sct_own != plane_owner && !evaded) {
207 /* We only show planes overhead if they didn't
209 overfly[sect.sct_own]++;
210 PR(sect.sct_own, "%s planes spotted over %s\n",
211 cname(plane_owner), xyas(x, y, sect.sct_own));
213 setcont(cn, plane_owner, FOUND_FLY);
218 if (unfriendly[sect.sct_own])
219 ac_doflak(bomb_list, §);
220 /* If bombers left, fire flak from units and ships */
221 if (!QEMPTY(bomb_list))
222 ac_landflak(bomb_list, x, y);
223 if (!QEMPTY(bomb_list))
224 ac_shipflak(bomb_list, x, y);
226 /* mission planes aborted due to flak -- don't send escorts */
227 if (QEMPTY(bomb_list))
229 if (!no_air_defense && !evaded)
230 air_defense(x, y, plane_owner, bomb_list, esc_list);
232 if (sect.sct_own == 0 || sect.sct_own == plane_owner)
239 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
240 struct plist *ip = (struct plist *)qp;
241 if (!(plchr[(int)ip->plane.pln_type].pl_flags & P_M))
248 if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) {
249 getilist(&ilist[sect.sct_own], sect.sct_own);
250 gotilist[sect.sct_own]++;
254 ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
256 intown = sect.sct_own;
259 /* Let's report all of the overflights even if aborted */
260 for (cn = 1; cn < MAXNOC; cn++) {
261 if (plane_owner == cn)
264 nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]);
266 /* If the map changed, update it */
268 writemap(player->cnum);
269 /* Now, if the bomber and escort lists are empty, we are done */
270 if (QEMPTY(bomb_list) && QEMPTY(esc_list))
273 /* Something made it through */
274 /* Go figure out if there are ships in this sector, and who's they are */
275 memset(nats, 0, sizeof(nats));
276 snxtitem_xy(&ni, EF_SHIP, x, y);
277 while (nxtitem(&ni, &ship)) {
278 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
280 nats[ship.shp_own]++;
282 /* Go figure out if there are units in this sector, and who's they are */
283 memset(lnats, 0, sizeof(lnats));
284 snxtitem_xy(&ni, EF_LAND, x, y);
285 while (nxtitem(&ni, &land)) {
286 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
288 lnats[land.lnd_own]++;
291 /* Now, let's make life a little rougher. */
292 for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
293 if (plane_owner == cn)
296 /* Are there ships owned by this country? */
300 PR(cn, "%s planes spotted over ships in %s\n",
301 cname(plane_owner), xyas(x, y, cn));
303 setcont(cn, plane_owner, FOUND_FLY);
305 if (unfriendly[cn]) {
306 /* They are unfriendly too */
308 getilist(&ilist[cn], cn);
311 PR(plane_owner, "Flying over %s ships in %s\n",
312 cname(cn), xyas(x, y, plane_owner));
313 /* This makes going for ships in harbors tough */
315 /* We already fired flak up above. Now we intercept again if we haven't already */
316 /* Flag that we intercepted */
318 /* And now intercept again */
319 ac_intercept(bomb_list, esc_list, &ilist[cn],
324 /* Are there units owned by this country? */
325 if (lnats[cn] != 0) {
328 PR(cn, "%s planes spotted over land units in %s\n",
329 cname(plane_owner), xyas(x, y, cn));
331 setcont(cn, plane_owner, FOUND_FLY);
333 if (unfriendly[cn]) {
334 /* They are unfriendly too */
336 getilist(&ilist[cn], cn);
339 PR(plane_owner, "Flying over %s land units in %s\n",
340 cname(cn), xyas(x, y, plane_owner));
343 /* We haven't intercepted yet, so intercept */
344 ac_intercept(bomb_list, esc_list, &ilist[cn],
352 free_shiplist(&head);
353 for (cn = 1; cn < MAXNOC; cn++) {
360 plane_caps(struct emp_qelem *list)
362 struct emp_qelem *qp;
367 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
368 plp = (struct plist *)qp;
369 fl |= plp->pcp->pl_flags;
376 count_non_missiles(struct emp_qelem *list)
378 struct emp_qelem *qp;
382 /* don't intercept missiles */
383 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
384 plp = (struct plist *)qp;
385 if (!(plp->pcp->pl_flags & P_M))
392 sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
393 natid def_own, natid plane_owner, coord x, coord y,
396 struct emp_qelem *aqp;
397 struct emp_qelem *anext;
398 struct emp_qelem *dqp;
399 struct emp_qelem *dnext;
404 for (aqp = att_list->q_forw,
405 dqp = def_list->q_forw;
406 aqp != att_list && dqp != def_list; aqp = anext) {
408 aplp = (struct plist *)aqp;
409 if (aplp->pcp->pl_flags & P_M)
411 if (aplp->pcp->pl_cost < 1000)
413 for (; dqp != def_list; dqp = dnext) {
415 dplp = (struct plist *)dqp;
416 if (!(dplp->pcp->pl_flags & P_M))
419 if (dplp->plane.pln_range <
420 mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) {
425 if (CANT_HAPPEN(dplp->plane.pln_flags & PLN_LAUNCHED)
426 || mission_pln_equip(dplp, 0, P_F, 0) < 0) {
431 dplp->plane.pln_flags |= PLN_LAUNCHED;
432 putplane(dplp->plane.pln_uid, &dplp->plane);
435 PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
436 PR(def_own, "Launching SAMs at %s planes over %s!\n",
437 cname(plane_owner), xyas(x, y, def_own));
438 ac_combat_headers(plane_owner, def_own);
446 PR(plane_owner, "\n");
449 if (delete_missiles) {
450 for (; dqp != def_list; dqp = dnext) {
452 dplp = (struct plist *)dqp;
453 if (!(dplp->pcp->pl_flags & P_M))
463 ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
464 struct emp_qelem *def_list, natid def_own, coord x, coord y)
469 struct emp_qelem *next;
470 struct emp_qelem *qp;
471 struct emp_qelem int_list;
476 plp = (struct plist *)bomb_list->q_forw;
477 plane_owner = plp->plane.pln_own;
481 sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0);
482 sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 1);
483 if (!(att_count = count_non_missiles(bomb_list) +
484 count_non_missiles(esc_list)))
487 emp_initque(&int_list);
488 for (qp = def_list->q_forw; qp != def_list; qp = next) {
490 plp = (struct plist *)qp;
492 /* SAMs interdict separately */
493 if (plp->pcp->pl_flags & P_M)
495 dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2;
496 if (pp->pln_range < dist)
498 if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED)
499 || mission_pln_equip(plp, 0, P_F, 0) < 0) {
504 /* got one; delete from def_list, add to int_list */
506 emp_insque(qp, &int_list);
507 pp->pln_flags |= PLN_LAUNCHED;
508 pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
509 putplane(pp->pln_uid, pp);
511 if (icount > att_count)
516 PR(plane_owner, "%d %s fighter%s rising to intercept!\n",
517 icount, cname(def_own), icount == 1 ? " is" : "s are");
518 PR(def_own, "%d fighter%s intercepting %s planes over %s!\n",
519 icount, icount == 1 ? " is" : "s are", cname(plane_owner),
520 xyas(x, y, def_own));
521 ac_combat_headers(plane_owner, def_own);
522 ac_airtoair(esc_list, &int_list);
523 ac_airtoair(bomb_list, &int_list);
524 PR(plane_owner, "\n");
530 ac_combat_headers(natid plane_owner, natid def_own)
533 " %-10.10s %-10.10s strength int odds damage results\n",
534 cname(plane_owner), cname(def_own));
536 " %-10.10s %-10.10s strength int odds damage results\n",
537 cname(def_own), cname(plane_owner));
544 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list)
546 struct plist *attacker;
547 struct plist *interceptor;
548 struct emp_qelem *att;
549 struct emp_qelem *in;
553 struct emp_qelem *att_next;
554 struct emp_qelem *in_next;
556 att = att_list->q_forw;
557 in = int_list->q_forw;
560 if (QEMPTY(att_list) || QEMPTY(int_list)) {
564 while (more_att || more_int) {
565 in_next = in->q_forw;
566 att_next = att->q_forw;
567 attacker = (struct plist *)att;
569 /* skip missiles. If only missiles left, we're done */
570 if (plchr[(int)attacker->plane.pln_type].pl_flags & P_M) {
572 if (att == att_list) {
574 if (QEMPTY(att_list))
579 if (all_missiles(att_list))
583 interceptor = (struct plist *)in;
584 nplanes = attacker->plane.pln_effic;
585 if (nplanes > interceptor->plane.pln_effic)
586 nplanes = interceptor->plane.pln_effic;
587 ac_dog(attacker, interceptor);
590 if (att == att_list) {
592 if (QEMPTY(att_list))
597 if (in == int_list) {
599 if (QEMPTY(int_list))
608 all_missiles(struct emp_qelem *att_list)
610 struct emp_qelem *qp;
613 qp = att_list->q_forw;
614 while (qp != att_list) {
615 p = (struct plist *)qp;
616 if (!(plchr[(int)p->plane.pln_type].pl_flags & P_M))
625 ac_dog(struct plist *ap, struct plist *dp)
630 natid att_own, def_own;
635 att_own = ap->plane.pln_own;
636 def_own = dp->plane.pln_own;
638 PR(att_own, " %3.3s #%-4d %3.3s #%-4d",
640 ap->plane.pln_uid, dp->pcp->pl_name, dp->plane.pln_uid);
642 PR(def_own, " %3.3s #%-4d %3.3s #%-4d",
644 dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid);
645 att = pln_att(&ap->plane);
647 att = pln_def(&ap->plane);
648 att = att * ap->plane.pln_effic / 100;
649 att = MAX(att, ap->pcp->pl_def / 2);
651 def = pln_def(&dp->plane) * dp->plane.pln_effic / 100;
652 def = MAX(def, dp->pcp->pl_def / 2);
654 if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
656 if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
658 att += ap->pcp->pl_stealth / 25.0;
659 def += dp->pcp->pl_stealth / 25.0;
668 odds = ((double)att / ((double)def + (double)att));
671 intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1;
673 PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds);
674 PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds);
678 while ((intensity--) > 0) {
682 if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF)
686 if ((ap->plane.pln_effic - adam) < PLANE_MINEFF)
691 if (dp->pcp->pl_flags & P_M)
694 PR(att_own, "%3d/%-3d", adam, ddam);
695 PR(def_own, "%3d/%-3d", ddam, adam);
696 ac_planedamage(ap, def_own, adam, def_own, 1, 0, mesg);
697 strncpy(temp, mesg, 14);
698 ac_planedamage(dp, att_own, ddam, att_own, 1, 0, mesg);
699 PR(att_own, "%-13.13s %-13.13s\n", temp, mesg);
700 PR(def_own, "%-13.13s %-13.13s\n", mesg, temp);
703 setcont(att_own, def_own, FOUND_FLY);
704 setcont(def_own, att_own, FOUND_FLY);
709 * zap plane associated with plp.
710 * Damaging country is "from", damage is "dam".
711 * def_own is the country on the other side of the conflict from the plane
712 * owner. The only time def_own != from is when the interceptor is getting
715 * NOTE: This routine removes the appropriate plane element from the
716 * queue if it gets destroyed. That means that the caller must assume
717 * that the current queue pointer is invalid on return from the ac_planedamage
718 * call. (this has caused bugs in the past)
721 ac_planedamage(struct plist *plp, natid from, int dam, natid other,
722 int checkabort, int show, char *mesg)
732 plane_owner = pp->pln_own;
734 sprintf(dmess, " no damage");
739 memset(dmess, 0, sizeof(dmess));
743 if (eff < PLANE_MINEFF) {
744 sprintf(dmess, " shot down");
746 } else if (eff < 80 && chance((80 - eff) / 100.0) && checkabort) {
747 sprintf(dmess, " aborted @%2d%%", eff);
749 } else if (show == 0) {
750 sprintf(dmess, " cleared");
753 if ((plp->pcp->pl_flags & P_M) == 0) {
755 PR(plane_owner, " %s %s takes %d%s.\n",
756 cname(pp->pln_own), prplane(pp), dam, dmess);
758 PR(other, " %s %s takes %d%s.\n",
759 cname(pp->pln_own), prplane(pp), dam, dmess);
762 if (show && checkabort == 1) {
763 PR(plane_owner, "\n");
769 pp->pln_mobil -= MIN(32 + pp->pln_mobil, dam / 2);
771 if (disp == 1 && from != 0 && (plp->pcp->pl_flags & P_M) == 0)
772 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
775 putplane(pp->pln_uid, pp);
780 ac_doflak(struct emp_qelem *list, struct sctstr *from)
787 plp = (struct plist *)list->q_forw;
788 plane_owner = plp->plane.pln_own;
790 gun = MIN(FLAK_GUN_MAX, from->sct_item[I_GUN]);
791 shell = from->sct_item[I_SHELL];
792 if (gun > shell * 2) {
793 shell += supply_commod(from->sct_own, from->sct_x, from->sct_y,
794 I_SHELL, (gun + 1) / 2 - shell);
795 from->sct_item[I_SHELL] = shell;
801 gun = roundavg(tfact(from->sct_own, 2.0 * gun));
803 PR(plane_owner, "firing %d flak guns in %s...\n",
804 gun, xyas(from->sct_x, from->sct_y, plane_owner));
805 if (from->sct_own != 0)
806 PR(from->sct_own, "firing %d flak guns in %s...\n",
807 gun, xyas(from->sct_x, from->sct_y, from->sct_own));
808 ac_fireflak(list, from->sct_own, gun);
813 ac_shipflak(struct emp_qelem *list, coord x, coord y)
818 double flak, total, ngun;
826 plp = (struct plist *)list->q_forw;
827 plane_owner = plp->plane.pln_own;
829 memset(nats, 0, sizeof(nats));
831 snxtitem_xy(&ni, EF_SHIP, x, y);
832 while (!QEMPTY(list) && nxtitem(&ni, &ship)) {
833 if (ship.shp_own == 0 || ship.shp_own == plane_owner)
835 mcp = &mchr[(int)ship.shp_type];
836 if (mcp->m_flags & M_SUB)
838 rel = getrel(getnatp(ship.shp_own), plane_owner);
842 gun = shp_usable_guns(&ship);
844 shell = ship.shp_item[I_SHELL];
846 shell = supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
848 ship.shp_item[I_SHELL] = shell;
849 putship(ship.shp_uid, &ship);
852 if (gun == 0 || shell == 0)
854 flak = gun * (ship.shp_effic / 100.0);
856 total += techfact(ship.shp_tech, flak * 2.0);
858 if (!nats[ship.shp_own]) {
859 /* First time here, print the message */
860 PR(ship.shp_own, "%s planes spotted over ships in %s\n",
861 cname(plane_owner), xyas(x, y, ship.shp_own));
862 PR(plane_owner, "Flying over %s ships in %s\n",
863 cname(ship.shp_own), xyas(x, y, plane_owner));
864 nats[ship.shp_own] = 1;
866 PR(ship.shp_own, "firing %.0f flak guns from %s...\n",
867 flak, prship(&ship));
871 /* Limit to FLAK_GUN_MAX guns of average tech factor */
872 if (ngun > FLAK_GUN_MAX)
873 total *= FLAK_GUN_MAX / ngun;
875 gun = roundavg(total);
877 PR(plane_owner, "Flak! Ships firing %d flak guns...\n", gun);
878 ac_fireflak(list, from, gun);
883 ac_landflak(struct emp_qelem *list, coord x, coord y)
888 double flak, total, ngun;
896 plp = (struct plist *)list->q_forw;
897 plane_owner = plp->plane.pln_own;
899 memset(nats, 0, sizeof(nats));
901 snxtitem_xy(&ni, EF_LAND, x, y);
902 while (!QEMPTY(list) && nxtitem(&ni, &land)) {
903 if (land.lnd_own == 0 || land.lnd_own == plane_owner)
905 lcp = &lchr[(int)land.lnd_type];
906 aaf = lnd_aaf(&land);
907 if ((lcp->l_flags & L_FLAK) == 0 || aaf == 0)
909 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
911 rel = getrel(getnatp(land.lnd_own), plane_owner);
914 flak = aaf * 1.5 * land.lnd_effic / 100.0;
916 total += techfact(land.lnd_tech, flak * 2.0);
918 if (!nats[land.lnd_own]) {
919 /* First time here, print the message */
920 PR(land.lnd_own, "%s planes spotted over land units in %s\n",
921 cname(plane_owner), xyas(x, y, land.lnd_own));
922 PR(plane_owner, "Flying over %s land units in %s\n",
923 cname(land.lnd_own), xyas(x, y, plane_owner));
924 nats[land.lnd_own] = 1;
926 PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
931 /* Limit to FLAK_GUN_MAX guns of average tech factor */
932 if (ngun > FLAK_GUN_MAX)
933 total *= FLAK_GUN_MAX / ngun;
935 gun = roundavg(total);
937 PR(plane_owner, "Flak! Land units firing %d flak guns...\n", gun);
938 ac_fireflak(list, from, gun);
943 * Called from shipflak, landflak, and doflak.
946 ac_fireflak(struct emp_qelem *list, natid from, int guns)
950 struct emp_qelem *qp;
951 struct emp_qelem *next;
954 plp = (struct plist *)list->q_forw;
956 for (qp = list->q_forw; qp != list; qp = next) {
958 plp = (struct plist *)qp;
959 n = ac_flak_dam(guns, pln_def(&plp->plane), plp->pcp->pl_flags);
960 ac_planedamage(plp, from, n, 0, 2, 1, msg);
965 * Calculate flak damage
968 ac_flak_dam(int guns, int def, int pl_flags)
972 /* <-7 -7 -6 -5 -4 */
973 static float flaktable[18] = { 0.132f, 0.20f, 0.20f, 0.25f, 0.30f,
974 /* -3 -2 -1 0 +1 +2 +3 +4 */
975 0.35f, 0.40f, 0.45f, 0.50f, 0.50f, 0.55f, 0.60f, 0.65f,
976 /* +5 +6 +7 +8 >+8 */
977 0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
978 enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
981 if ((pl_flags & P_T) == 0)
989 mult = flaktable[FLAK_MAX];
994 mult = flaktable[flak];
997 dam = (int)((roll(8) + 2) * mult);
1004 * Get a list of planes available for interception duties.
1007 getilist(struct emp_qelem *list, natid own)
1009 struct plchrstr *pcp;
1010 struct plnstr plane;
1011 struct nstr_item ni;
1015 snxtitem_all(&ni, EF_PLANE);
1016 while (nxtitem(&ni, &plane)) {
1017 if (plane.pln_own != own)
1019 pcp = &plchr[(int)plane.pln_type];
1020 if ((pcp->pl_flags & P_F) == 0)
1022 if (plane.pln_flags & PLN_LAUNCHED)
1024 if (plane.pln_mission != 0)
1026 if (plane.pln_mobil <= 0)
1028 if (plane.pln_effic < 40)
1030 if (!pln_airbase_ok(&plane, 0, 0))
1033 ip = malloc(sizeof(*ip));
1036 ip->pcp = &plchr[(int)plane.pln_type];
1038 emp_insque(&ip->queue, list);
1043 do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
1045 struct emp_qelem *qp;
1050 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
1051 plp = (struct plist *)qp;
1052 if (evade > plp->pcp->pl_stealth / 100.0)
1053 evade = plp->pcp->pl_stealth / 100.0;
1055 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) {
1056 plp = (struct plist *)qp;
1057 if (evade > plp->pcp->pl_stealth / 100.0)
1058 evade = plp->pcp->pl_stealth / 100.0;