2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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 * aircombat.c: Deal with air to air combat
30 * Known contributors to this file:
32 * Thomas Ruschak, 1992
50 #include "prototypes.h"
56 #define MAX(x,y) ((x) < (y) ? (y) : (x))
59 static void getilist(struct emp_qelem *list, natid own,
60 struct emp_qelem *a, struct emp_qelem *b,
61 struct emp_qelem *c, struct emp_qelem *d);
62 static void ac_dog(struct plist *ap, struct plist *dp);
66 /* -7 -6 -5 -4 -3 -2 -1 0 */
67 float flaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
68 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
72 ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
73 coord x, coord y, s_char *path, int mission_flags,
74 int no_air_defense, struct emp_qelem *obomb,
75 struct emp_qelem *oesc)
77 int val, non_missiles;
83 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 if (mission_flags & P_S) {
126 PR(plane_owner, "\nSPY Plane report\n");
129 } else if (mission_flags & P_A) {
130 PR(plane_owner, "\nAnti-Sub Patrol report\n");
132 PR(plane_owner, "\nReconnaissance report\n");
137 pln_removedupes(bomb_list, esc_list);
138 while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) {
139 if ((val = chkdir(dir, DIR_STOP, DIR_LAST)) == 0)
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 setcont(plane_owner, sect.sct_own, FOUND_FLY);
150 if (mission_flags & PM_R) {
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);
156 if (mission_flags & P_A) {
157 plane_sona(bomb_list, x, y, &head);
159 changed += map_set(plane_owner,
160 sect.sct_x, sect.sct_y,
161 dchr[sect.sct_type].d_mnem, 0);
162 } else if (mission_flags & P_S) {
163 satdisp(§, (mission_flags & P_I) ? 10 : 50, 1);
165 /* This is borrowed from lookout */
166 if (sect.sct_own == plane_owner)
167 PR(plane_owner, "Your ");
170 "%s (#%d) ", cname(sect.sct_own), sect.sct_own);
171 PR(plane_owner, dchr[sect.sct_type].d_name);
172 changed += map_set(plane_owner,
173 sect.sct_x, sect.sct_y,
174 dchr[sect.sct_type].d_mnem, 0);
175 PR(plane_owner, " %d%% efficient ",
176 (sect.sct_own == plane_owner) ?
177 sect.sct_effic : roundintby((int)sect.sct_effic, 25));
178 civ = sect.sct_item[I_CIVIL];
179 mil = sect.sct_item[I_MILIT];
181 PR(plane_owner, "with %s%d civ ",
182 (sect.sct_own == plane_owner) ?
184 (sect.sct_own == plane_owner) ?
185 civ : roundintby(civ, 25));
187 PR(plane_owner, "with %s%d mil ",
188 (sect.sct_own == plane_owner) ?
190 (sect.sct_own == plane_owner) ?
191 mil : roundintby(mil, 25));
192 PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner));
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,
198 sect.sct_y, 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));
215 if (unfriendly[sect.sct_own])
216 ac_doflak(bomb_list, §);
217 /* If bombers left, fire flak from units and ships */
218 if (!QEMPTY(bomb_list))
219 ac_landflak(bomb_list, x, y);
220 if (!QEMPTY(bomb_list))
221 ac_shipflak(bomb_list, x, y);
223 /* mission planes aborted due to flak -- don't send escorts */
224 if (QEMPTY(bomb_list))
226 if ((!no_air_defense) && (!evaded))
227 air_defense(x, y, plane_owner, bomb_list, esc_list);
229 if (sect.sct_own == 0 || sect.sct_own == plane_owner)
236 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
237 struct plist *ip = (struct plist *)qp;
238 if (!(plchr[(int)ip->plane.pln_type].pl_flags & P_M))
245 if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) {
246 getilist(&ilist[sect.sct_own], sect.sct_own,
247 bomb_list, esc_list, obomb, oesc);
248 gotilist[sect.sct_own]++;
252 ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
254 intown = 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 if (!update_pending && plane_owner == player->cnum)
267 writemap(player->cnum);
268 /* Now, if the bomber and escort lists are empty, we are done */
269 if (QEMPTY(bomb_list) && QEMPTY(esc_list)) {
270 if (mission_flags & P_A)
271 free_shiplist(&head);
275 /* Something made it through */
276 /* Go figure out if there are ships in this sector, and who's they are */
277 memset(nats, 0, sizeof(nats));
278 snxtitem_xy(&ni, EF_SHIP, x, y);
279 while (nxtitem(&ni, (s_char *)&ship)) {
280 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
282 nats[ship.shp_own]++;
284 /* Go figure out if there are units in this sector, and who's they are */
285 memset(lnats, 0, sizeof(lnats));
286 snxtitem_xy(&ni, EF_LAND, x, y);
287 while (nxtitem(&ni, (s_char *)&land)) {
288 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
290 lnats[land.lnd_own]++;
293 /* Now, let's make life a little rougher. */
294 for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
295 if (plane_owner == cn)
298 /* Are there ships owned by this country? */
302 PR(cn, "%s planes spotted over ships in %s\n",
303 cname(plane_owner), xyas(x, y, cn));
304 if (unfriendly[cn]) {
305 /* They are unfriendly too */
307 getilist(&ilist[cn], cn, bomb_list, esc_list, obomb,
311 PR(plane_owner, "Flying over %s ships in %s\n", cname(cn),
312 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], cn, x,
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));
330 if (unfriendly[cn]) {
331 /* They are unfriendly too */
333 getilist(&ilist[cn], cn, bomb_list, esc_list, obomb,
337 PR(plane_owner, "Flying over %s land units in %s\n",
338 cname(cn), xyas(x, y, plane_owner));
341 /* We haven't intercepted yet, so intercept */
342 ac_intercept(bomb_list, esc_list, &ilist[cn], cn,
349 if (mission_flags & P_A)
350 free_shiplist(&head);
354 count_non_missiles(struct emp_qelem *list)
356 struct emp_qelem *qp;
360 /* don't intercept missiles */
361 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
362 plp = (struct plist *)qp;
363 if (!(plp->pcp->pl_flags & P_M))
370 sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
371 natid def_own, natid plane_owner, coord x, coord y,
374 struct emp_qelem *aqp;
375 struct emp_qelem *anext;
376 struct emp_qelem *dqp;
377 struct emp_qelem *dnext;
382 for (aqp = att_list->q_forw,
383 dqp = def_list->q_forw;
384 aqp != att_list && dqp != def_list; aqp = anext) {
386 aplp = (struct plist *)aqp;
387 if (aplp->pcp->pl_flags & P_M)
389 if (aplp->pcp->pl_cost < 1000)
391 for (; dqp != def_list; dqp = dnext) {
393 dplp = (struct plist *)dqp;
394 if (!(dplp->pcp->pl_flags & P_M))
397 if (dplp->plane.pln_range <
398 mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) {
403 if (mission_pln_equip(dplp, 0, P_F, 0) < 0) {
410 PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
411 PR(def_own, "Launching SAMs at %s planes!\n",
413 ac_combat_headers(plane_owner, def_own);
421 PR(plane_owner, "\n");
424 if (delete_missiles) {
425 for (; dqp != def_list; dqp = dnext) {
427 dplp = (struct plist *)dqp;
428 if (!(dplp->pcp->pl_flags & P_M))
438 ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
439 struct emp_qelem *def_list, natid def_own, coord x, coord y)
444 struct emp_qelem *next;
445 struct emp_qelem *qp;
446 struct emp_qelem int_list;
451 plp = (struct plist *)bomb_list->q_forw;
452 plane_owner = plp->plane.pln_own;
456 sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0);
457 sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 1);
458 if (!(att_count = count_non_missiles(bomb_list) +
459 count_non_missiles(esc_list)))
462 emp_initque(&int_list);
463 for (qp = def_list->q_forw; qp != def_list; qp = next) {
465 plp = (struct plist *)qp;
467 /* SAMs interdict separately */
468 if (plp->pcp->pl_flags & P_M)
470 dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2;
471 if (pp->pln_range < dist)
473 if (mission_pln_equip(plp, 0, P_F, 0) < 0) {
478 /* got one; delete from def_list, add to int_list */
480 emp_insque(qp, &int_list);
481 pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
482 putplane(pp->pln_uid, pp);
484 if (icount > att_count)
489 PR(plane_owner, "%d %s fighter%s rising to intercept!\n", icount,
490 cname(def_own), icount == 1 ? " is" : "s are");
491 PR(def_own, "%d fighter%s intercepting %s planes!\n", icount,
492 icount == 1 ? " is" : "s are", cname(plane_owner));
493 ac_combat_headers(plane_owner, def_own);
494 ac_airtoair(esc_list, &int_list);
495 ac_airtoair(bomb_list, &int_list);
496 PR(plane_owner, "\n");
501 ac_combat_headers(natid plane_owner, natid def_own)
504 " %-10.10s %-10.10s strength int odds damage results\n",
505 cname(plane_owner), cname(def_own));
507 " %-10.10s %-10.10s strength int odds damage results\n",
508 cname(def_own), cname(plane_owner));
515 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list)
517 struct plist *attacker;
518 struct plist *interceptor;
519 struct emp_qelem *att;
520 struct emp_qelem *in;
524 struct emp_qelem *att_next;
525 struct emp_qelem *in_next;
527 att = att_list->q_forw;
528 in = int_list->q_forw;
531 if (QEMPTY(att_list) || QEMPTY(int_list)) {
535 while (more_att || more_int) {
536 in_next = in->q_forw;
537 att_next = att->q_forw;
538 attacker = (struct plist *)att;
540 /* skip missiles. If only missiles left, we're done */
541 if (plchr[(int)attacker->plane.pln_type].pl_flags & P_M) {
543 if (att == att_list) {
545 if (QEMPTY(att_list))
550 if (all_missiles(att_list))
554 interceptor = (struct plist *)in;
555 nplanes = attacker->plane.pln_effic;
556 if (nplanes > interceptor->plane.pln_effic)
557 nplanes = interceptor->plane.pln_effic;
558 ac_dog(attacker, interceptor);
561 if (att == att_list) {
563 if (QEMPTY(att_list))
568 if (in == int_list) {
570 if (QEMPTY(int_list))
579 all_missiles(struct emp_qelem *att_list)
581 struct emp_qelem *qp;
584 qp = att_list->q_forw;
585 while (qp != att_list) {
586 p = (struct plist *)qp;
587 if (!(plchr[(int)p->plane.pln_type].pl_flags & P_M))
596 ac_dog(struct plist *ap, struct plist *dp)
601 natid att_own, def_own;
606 att_own = ap->plane.pln_own;
607 def_own = dp->plane.pln_own;
609 PR(att_own, " %3.3s #%-4d %3.3s #%-4d",
611 ap->plane.pln_uid, dp->pcp->pl_name, dp->plane.pln_uid);
613 PR(def_own, " %3.3s #%-4d %3.3s #%-4d",
615 dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid);
616 if (ap->plane.pln_att == 0) {
617 att = ap->plane.pln_def * ap->plane.pln_effic / 100;
618 att = MAX(att, ap->pcp->pl_def / 2);
620 att = ap->plane.pln_att * ap->plane.pln_effic / 100;
621 att = MAX(att, ap->pcp->pl_att / 2);
624 def = dp->plane.pln_def * dp->plane.pln_effic / 100;
625 def = MAX(def, dp->pcp->pl_def / 2);
627 if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
629 if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
631 att += ((float)ap->pcp->pl_stealth / 25.0);
632 def += ((float)dp->pcp->pl_stealth / 25.0);
641 odds = ((double)att / ((double)def + (double)att));
644 intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1;
646 PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds);
647 PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds);
651 while ((intensity--) > 0) {
655 if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF)
659 if ((ap->plane.pln_effic - adam) < PLANE_MINEFF)
664 if (dp->pcp->pl_flags & P_M)
667 PR(att_own, "%3d/%-3d", adam, ddam);
668 PR(def_own, "%3d/%-3d", ddam, adam);
669 ac_planedamage(ap, dp->plane.pln_own, adam, def_own, 1, 0, mesg);
670 strncpy(temp, mesg, 14);
671 ac_planedamage(dp, ap->plane.pln_own, ddam, att_own, 1, 0, mesg);
672 PR(att_own, "%-13.13s %-13.13s\n", temp, mesg);
673 PR(def_own, "%-13.13s %-13.13s\n", mesg, temp);
677 * zap plane associated with plp.
678 * Damaging country is "from", damage is "dam".
679 * def_own is the country on the other side of the conflict from the plane
680 * owner. The only time def_own != from is when the interceptor is getting
683 * NOTE: This routine removes the appropriate plane element from the
684 * queue if it gets destroyed. That means that the caller must assume
685 * that the current queue pointer is invalid on return from the ac_planedamage
686 * call. (this has caused bugs in the past)
689 ac_planedamage(struct plist *plp, natid from, int dam, natid other,
690 int checkabort, int show, s_char *mesg)
698 /* s_char *sprintf(); already in misc.h [JFW] */
703 plane_owner = pp->pln_own;
705 sprintf(dmess, " no damage");
710 memset(dmess, 0, sizeof(dmess));
714 if (eff < PLANE_MINEFF) {
715 sprintf(dmess, " shot down");
717 } else if (eff < 80 && chance((100 - eff) / 100.0) && checkabort) {
718 sprintf(dmess, " aborted @%2d%%", eff);
720 } else if (show == 0) {
721 sprintf(dmess, " cleared");
724 if ((plp->pcp->pl_flags & P_M) == 0) {
726 PR(plane_owner, " %s %s takes %d%s.\n",
727 cname(pp->pln_own), prplane(pp), dam, dmess);
729 PR(other, " %s %s takes %d%s.\n",
730 cname(pp->pln_own), prplane(pp), dam, dmess);
733 if (show && checkabort == 1) {
734 PR(plane_owner, "\n");
740 pp->pln_mobil -= min(32 + pp->pln_mobil, dam / 2);
742 if (from != 0 && (plp->pcp->pl_flags & P_M) == 0)
743 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
744 if (pp->pln_ship >= 0) {
745 getship(pp->pln_ship, &ship);
746 take_plane_off_ship(pp, &ship);
748 if (pp->pln_land >= 0) {
749 getland(pp->pln_land, &land);
750 take_plane_off_land(pp, &land);
752 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
754 putplane(pp->pln_uid, pp);
755 emp_remque(&plp->queue);
757 } else if (disp == 2) {
758 putplane(pp->pln_uid, pp);
759 emp_remque(&plp->queue);
762 putplane(pp->pln_uid, pp);
767 ac_doflak(struct emp_qelem *list, struct sctstr *from)
774 plp = (struct plist *)list->q_forw;
775 plane_owner = plp->plane.pln_own;
777 gun = from->sct_item[I_GUN];
778 shell = from->sct_item[I_SHELL];
781 if (gun > shell * 2) {
782 shell += supply_commod(from->sct_own, from->sct_x, from->sct_y,
783 I_SHELL, (gun + 1) / 2 - shell);
784 from->sct_item[I_SHELL] = shell;
790 gun = 2.0 * tfact(from->sct_own, gun);
792 PR(plane_owner, "firing %d flak guns in %s...\n",
793 gun, xyas(from->sct_x, from->sct_y, plane_owner));
794 if (from->sct_own != 0)
795 PR(from->sct_own, "firing %d flak guns in %s...\n",
796 gun, xyas(from->sct_x, from->sct_y, from->sct_own));
797 ac_fireflak(list, from->sct_own, 0, gun);
802 ac_shipflak(struct emp_qelem *list, coord x, coord y)
817 plp = (struct plist *)list->q_forw;
818 plane_owner = plp->plane.pln_own;
820 memset(nats, 0, sizeof(nats));
822 snxtitem_xy(&ni, EF_SHIP, x, y);
823 while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&ship)) {
824 if (ship.shp_own == 0 || ship.shp_own == plane_owner)
828 mcp = &mchr[(int)ship.shp_type];
829 if (mcp->m_flags & M_SUB)
831 rel = getrel(getnatp(ship.shp_own), plane_owner);
835 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
837 shell = ship.shp_item[I_SHELL];
839 shell = supply_commod(ship.shp_own, ship.shp_x,
840 ship.shp_y, I_SHELL, 1);
841 ship.shp_item[I_SHELL] = shell;
842 putship(ship.shp_uid, &ship);
845 if (gun == 0 || shell == 0)
847 firing = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
850 if (!nats[ship.shp_own]) {
851 /* First time here, print the message */
852 PR(ship.shp_own, "%s planes spotted over ships in %s\n",
853 cname(plane_owner), xyas(x, y, ship.shp_own));
854 PR(plane_owner, "Flying over %s ships in %s\n",
855 cname(ship.shp_own), xyas(x, y, plane_owner));
856 nats[ship.shp_own] = 1;
858 PR(ship.shp_own, "firing %d flak guns from %s...\n",
859 firing, prship(&ship));
865 guns = 2.0 * tfact(from, (double)guns);
866 PR(plane_owner, "Flak! Ships firing %d flak guns...\n", guns);
867 ac_fireflak(list, from, 0, guns);
872 ac_landflak(struct emp_qelem *list, coord x, coord y)
885 plp = (struct plist *)list->q_forw;
886 plane_owner = plp->plane.pln_own;
888 memset(nats, 0, sizeof(nats));
890 snxtitem_xy(&ni, EF_LAND, x, y);
891 while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&land)) {
892 if (land.lnd_own == 0 || land.lnd_own == plane_owner)
896 lcp = &lchr[(int)land.lnd_type];
898 if ((lcp->l_flags & L_FLAK) == 0)
901 if (land.lnd_aaf == 0)
904 rel = getrel(getnatp(land.lnd_own), plane_owner);
908 (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
911 if (!nats[land.lnd_own]) {
912 /* First time here, print the message */
913 PR(land.lnd_own, "%s planes spotted over land units in %s\n",
914 cname(plane_owner), xyas(x, y, land.lnd_own));
915 PR(plane_owner, "Flying over %s land units in %s\n",
916 cname(land.lnd_own), xyas(x, y, plane_owner));
917 nats[land.lnd_own] = 1;
919 PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
920 prland(&land), land.lnd_aaf);
922 from = land.lnd_own; /* We always use the last owner as the from */
927 guns = 2.0 * tfact(from, (double)guns);
928 PR(plane_owner, "Flak! Land units firing %d flak guns...\n",
930 ac_fireflak(list, from, 0, guns);
935 * Called from shipflak, landflak, and doflak.
938 ac_fireflak(struct emp_qelem *list, natid from, natid other, int guns)
945 struct emp_qelem *qp;
946 struct emp_qelem *next;
949 plp = (struct plist *)list->q_forw;
951 for (qp = list->q_forw; qp != list; qp = next) {
953 * fighters don't get shot at by flak
954 * non-tactical bombers are harder to hit with flak.
955 * ('Cause they're not dive-bombing?)
958 plp = (struct plist *)qp;
960 diff = guns - pp->pln_def;
961 if ((plp->pcp->pl_flags & P_T) == 0)
963 if (plp->pcp->pl_flags & P_X)
965 if (plp->pcp->pl_flags & P_H)
968 mult = flaktable[FLAK_MAX] * 1.33;
970 mult = flaktable[0] * 0.66;
973 mult = flaktable[diff];
976 n = (int)((roll(8) + 2) * mult);
979 ac_planedamage(plp, from, n, other, 2, 1, msg);
984 * See if this plane is flying in this list
987 ac_isflying(struct plnstr *plane, struct emp_qelem *list)
989 struct emp_qelem *qp;
990 struct emp_qelem *next;
996 for (qp = list->q_forw; qp != list; qp = next) {
998 plp = (struct plist *)qp;
1000 if (plane->pln_uid == pp->pln_uid)
1008 * Get a list of planes available for interception duties.
1011 getilist(struct emp_qelem *list, natid own, struct emp_qelem *a,
1012 struct emp_qelem *b, struct emp_qelem *c, struct emp_qelem *d)
1014 struct plchrstr *pcp;
1015 struct plnstr plane;
1019 struct nstr_item ni;
1024 snxtitem_all(&ni, EF_PLANE);
1025 while (nxtitem(&ni, (s_char *)&plane)) {
1026 if (plane.pln_own != own)
1028 pcp = &plchr[(int)plane.pln_type];
1029 if ((pcp->pl_flags & P_F) == 0)
1031 if (plane.pln_mission != 0)
1033 if (plane.pln_mobil <= 0)
1035 if (plane.pln_effic < 40)
1037 if (plane.pln_ship >= 0) {
1038 if (!can_fly(plane.pln_uid))
1040 getship(plane.pln_ship, &ship);
1041 petrol = ship.shp_item[I_PETROL];
1042 } else if (plane.pln_land >= 0) {
1043 if (!can_fly(plane.pln_uid))
1045 getland(plane.pln_land, &land);
1046 petrol = land.lnd_item[I_PETROL];
1048 getsect(plane.pln_x, plane.pln_y, §);
1049 petrol = sect.sct_item[I_PETROL];
1050 if ((sect.sct_effic < 60 || sect.sct_type != SCT_AIRPT)
1051 && (pcp->pl_flags & P_V) == 0)
1054 if ((float)petrol < (float)pcp->pl_fuel / 2.0)
1056 /* Finally, is it in the list of planes already in
1058 if (ac_isflying(&plane, a))
1060 if (ac_isflying(&plane, b))
1062 if (ac_isflying(&plane, c))
1064 if (ac_isflying(&plane, d))
1067 ip = (struct plist *)malloc(sizeof(*ip));
1071 ip->pcp = &plchr[(int)plane.pln_type];
1073 emp_insque(&ip->queue, list);
1081 { /* Can this plane fly from the ship or land unit it is on? */
1082 struct plnstr plane;
1085 struct plchrstr *pcp;
1086 struct mchrstr *scp;
1087 struct lchrstr *lcp;
1089 getplane(p, &plane);
1090 pcp = &plchr[(int)plane.pln_type];
1092 if (plane.pln_ship >= 0) {
1093 if (!(pcp->pl_flags & P_L) && !(pcp->pl_flags & P_M)
1094 && !(pcp->pl_flags & P_K)
1095 && !(pcp->pl_flags & P_E)
1099 getship(plane.pln_ship, &ship);
1100 scp = &mchr[(int)ship.shp_type];
1102 if ((pcp->pl_flags & P_L) && (scp->m_flags & M_FLY)) {
1106 if ((pcp->pl_flags & P_M) && (scp->m_flags & M_MSL)) {
1110 if ((pcp->pl_flags & P_K) && (scp->m_flags & M_CHOPPER)) {
1114 if ((pcp->pl_flags & P_E) && (scp->m_flags & M_XLIGHT)) {
1119 if (plane.pln_land >= 0) {
1120 if (!(pcp->pl_flags & P_E))
1123 getland(plane.pln_land, &land);
1124 lcp = &lchr[(int)land.lnd_type];
1126 if ((pcp->pl_flags & P_E) && (lcp->l_flags & L_XLIGHT)) {
1135 do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
1137 struct emp_qelem *qp;
1142 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
1143 plp = (struct plist *)qp;
1144 if (evade > ((float)plp->pcp->pl_stealth / 100.0))
1145 evade = (plp->pcp->pl_stealth / 100.0);
1147 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) {
1148 plp = (struct plist *)qp;
1149 if (evade > plp->pcp->pl_stealth / 100.0)
1150 evade = (plp->pcp->pl_stealth / 100.0);