2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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
52 #include "prototypes.h"
55 extern int update_pending;
58 #define MIN(x,y) ((x) < (y) ? (x) : (y))
61 #define MAX(x,y) ((x) < (y) ? (y) : (x))
64 static void getilist(struct emp_qelem *list, natid own,
65 struct emp_qelem *a, struct emp_qelem *b,
66 struct emp_qelem *c, struct emp_qelem *d);
67 static void ac_dog(register struct plist *ap, register struct plist *dp);
72 /* -7 -6 -5 -4 -3 -2 -1 0 */
73 float flaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
74 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
78 ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
79 coord x, coord y, s_char *path, int mission_flags,
80 int no_air_defense, struct emp_qelem *obomb,
81 struct emp_qelem *oesc)
83 int val, non_missiles;
89 int unfriendly[MAXNOC];
91 struct emp_qelem ilist[MAXNOC], *qp;
101 struct natstr *over, *mynatp;
104 struct shiplook head;
105 struct shiplook *s, *s2;
107 int intx, inty; /* Last sector planes intercepted over */
108 int intown = 0; /* Last owner to intercept */
109 /* We want to only intercept once per sector per owner. So, if we overfly
110 a sector, and then overfly some land units or ships, we don't want to
111 potentially intercept 3 times. */
113 bzero((s_char *)&head, sizeof(struct shiplook));
116 plp = (struct plist *)bomb_list->q_forw;
117 plane_owner = plp->plane.pln_own;
119 bzero((s_char *)mypath, 1024);
120 bcopy(path, mypath, strlen(path));
123 bzero((s_char *)overfly, sizeof(overfly));
124 bzero((s_char *)gotilist, sizeof(gotilist));
125 bzero((s_char *)unfriendly, sizeof(unfriendly));
126 for (cn = 1; cn < MAXNOC; cn++) {
127 if ((mynatp = getnatp(cn)) == 0)
129 rel = getrel(mynatp, plane_owner);
132 if (plane_owner == cn)
136 if (mission_flags & PM_R) {
137 if (mission_flags & P_S) {
138 PR(plane_owner, "\nSPY Plane report\n");
141 } else if (mission_flags & P_A) {
142 PR(plane_owner, "\nAnti-Sub Patrol report\n");
144 PR(plane_owner, "\nReconnaissance report\n");
149 pln_removedupes(bomb_list, esc_list);
150 while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) {
151 if ((val = chkdir(dir, DIR_STOP, DIR_LAST)) == 0)
153 /* XXX using xnorm is probably bad */
154 x = xnorm(x + diroff[val][0]);
155 y = ynorm(y + diroff[val][1]);
156 getsect(x, y, §);
157 over = getnatp(sect.sct_own);
159 setcont(plane_owner, sect.sct_own, FOUND_FLY);
162 if (mission_flags & PM_R) {
163 if (sect.sct_type == SCT_WATER) {
164 PR(plane_owner, "flying over %s at %s\n",
165 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
166 if (mission_flags & PM_S)
167 plane_sweep(bomb_list, x, y);
168 if (mission_flags & P_A) {
169 plane_sona(bomb_list, x, y, &head);
171 changed += map_set(plane_owner,
172 sect.sct_x, sect.sct_y,
173 dchr[sect.sct_type].d_mnem, 0);
174 } else if (mission_flags & P_S) {
175 satdisp(§, (mission_flags & P_I) ? 10 : 50, 1);
177 /* This is borrowed from lookout */
178 if (sect.sct_own == plane_owner)
179 PR(plane_owner, "Your ");
182 "%s (#%d) ", cname(sect.sct_own), sect.sct_own);
183 PR(plane_owner, dchr[sect.sct_type].d_name);
184 changed += map_set(plane_owner,
185 sect.sct_x, sect.sct_y,
186 dchr[sect.sct_type].d_mnem, 0);
187 PR(plane_owner, " %d%% efficient ",
188 (sect.sct_own == plane_owner) ?
189 sect.sct_effic : roundintby((int)sect.sct_effic, 25));
190 civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
191 mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR);
193 PR(plane_owner, "with %s%d civ ",
194 (sect.sct_own == plane_owner) ?
196 (sect.sct_own == plane_owner) ?
197 civ : roundintby(civ, 25));
199 PR(plane_owner, "with %s%d mil ",
200 (sect.sct_own == plane_owner) ?
202 (sect.sct_own == plane_owner) ?
203 mil : roundintby(mil, 25));
204 PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner));
207 PR(plane_owner, "flying over %s at %s\n",
208 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
209 changed += map_set(plane_owner, sect.sct_x,
210 sect.sct_y, dchr[sect.sct_type].d_mnem, 0);
212 if ((rel = getrel(over, plane_owner)) == ALLIED)
215 evaded = do_evade(bomb_list, esc_list);
217 if (sect.sct_own != 0 && sect.sct_own != plane_owner && (!evaded)) {
218 /* We only show planes overhead if they didn't
220 overfly[sect.sct_own]++;
221 PR(sect.sct_own, "%s planes spotted over %s\n",
222 cname(plane_owner), xyas(x, y, sect.sct_own));
227 if (unfriendly[sect.sct_own])
228 ac_doflak(bomb_list, §);
229 /* If bombers left, fire flak from units and ships */
230 if (!QEMPTY(bomb_list))
231 ac_landflak(bomb_list, x, y);
232 if (!QEMPTY(bomb_list))
233 ac_shipflak(bomb_list, x, y);
235 /* mission planes aborted due to flak -- don't send escorts */
236 if (QEMPTY(bomb_list))
238 if ((!no_air_defense) && (!evaded))
239 air_defense(x, y, plane_owner, bomb_list, esc_list);
241 if (sect.sct_own == 0 || sect.sct_own == plane_owner)
248 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
249 struct plist *ip = (struct plist *)qp;
250 if (!(plchr[(int)ip->plane.pln_type].pl_flags & P_M))
257 if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) {
258 getilist(&ilist[sect.sct_own], sect.sct_own,
259 bomb_list, esc_list, obomb, oesc);
260 gotilist[sect.sct_own]++;
264 ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
268 intown = sect.sct_own;
271 /* Let's report all of the overflights even if aborted */
272 for (cn = 1; cn < MAXNOC; cn++) {
273 if (plane_owner == cn)
276 nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]);
278 /* If the map changed, update it */
280 if (!update_pending && plane_owner == player->cnum)
281 writemap(player->cnum);
282 /* Now, if the bomber and escort lists are empty, we are done */
283 if (QEMPTY(bomb_list) && QEMPTY(esc_list)) {
284 if (mission_flags & P_A) {
286 while (s != (struct shiplook *)0) {
295 /* Something made it through */
296 /* Go figure out if there are ships in this sector, and who's they are */
297 bzero((s_char *)nats, sizeof(nats));
298 snxtitem_xy(&ni, EF_SHIP, x, y);
299 while (nxtitem(&ni, (s_char *)&ship)) {
300 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
302 nats[ship.shp_own]++;
304 /* Go figure out if there are units in this sector, and who's they are */
305 bzero((s_char *)lnats, sizeof(lnats));
306 snxtitem_xy(&ni, EF_LAND, x, y);
307 while (nxtitem(&ni, (s_char *)&land)) {
308 lnats[land.lnd_own]++;
311 /* Now, let's make life a little rougher. */
312 for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
313 if (plane_owner == cn)
316 /* Are there ships owned by this country? */
320 PR(cn, "%s planes spotted over ships in %s\n",
321 cname(plane_owner), xyas(x, y, cn));
322 if (unfriendly[cn]) {
323 /* They are unfriendly too */
325 getilist(&ilist[cn], cn, bomb_list, esc_list, obomb,
329 PR(plane_owner, "Flying over %s ships in %s\n", cname(cn),
330 xyas(x, y, plane_owner));
331 /* This makes going for ships in harbors tough */
333 /* We already fired flak up above. Now we intercept again if we haven't already */
334 /* Flag that we intercepted */
336 /* And now intercept again */
337 ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x,
342 /* Are there units owned by this country? */
343 if (lnats[cn] != 0) {
346 PR(cn, "%s planes spotted over land units in %s\n",
347 cname(plane_owner), xyas(x, y, cn));
348 if (unfriendly[cn]) {
349 /* They are unfriendly too */
351 getilist(&ilist[cn], cn, bomb_list, esc_list, obomb,
355 PR(plane_owner, "Flying over %s land units in %s\n",
356 cname(cn), xyas(x, y, plane_owner));
359 /* We haven't intercepted yet, so intercept */
360 ac_intercept(bomb_list, esc_list, &ilist[cn], cn,
368 if ((mission_flags & P_A) && (head.uid != -1)) {
370 while (s != (struct shiplook *)0) {
379 count_non_missiles(struct emp_qelem *list)
381 struct emp_qelem *qp;
385 /* don't intercept missiles */
386 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
387 plp = (struct plist *)qp;
388 if (!(plp->pcp->pl_flags & P_M))
395 sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
396 natid def_own, natid plane_owner, coord x, coord y,
399 struct emp_qelem *aqp;
400 struct emp_qelem *anext;
401 struct emp_qelem *dqp;
402 struct emp_qelem *dnext;
407 for (aqp = att_list->q_forw,
408 dqp = def_list->q_forw;
409 aqp != att_list && dqp != def_list; aqp = anext) {
411 aplp = (struct plist *)aqp;
412 if (aplp->pcp->pl_flags & P_M)
414 if (aplp->pcp->pl_cost < 1000)
416 for (; dqp != def_list; dqp = dnext) {
418 dplp = (struct plist *)dqp;
419 if (!(dplp->pcp->pl_flags & P_M))
422 if (dplp->plane.pln_range <
423 mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) {
428 if (mission_pln_equip(dplp, 0, P_F, 0) < 0) {
435 PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
436 PR(def_own, "Launching SAMs at %s planes!\n",
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)
466 register struct plnstr *pp;
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 (mission_pln_equip(plp, 0, P_F, 0) < 0) {
503 /* got one; delete from def_list, add to int_list */
505 emp_insque(qp, &int_list);
506 pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
507 putplane(pp->pln_uid, pp);
509 if (icount > att_count)
514 PR(plane_owner, "%d %s fighter%s rising to intercept!\n", icount,
515 cname(def_own), icount == 1 ? " is" : "s are");
516 PR(def_own, "%d fighter%s intercepting %s planes!\n", icount,
517 icount == 1 ? " is" : "s are", cname(plane_owner));
518 ac_combat_headers(plane_owner, def_own);
519 ac_airtoair(esc_list, &int_list, def_own);
520 ac_airtoair(bomb_list, &int_list, def_own);
521 PR(plane_owner, "\n");
526 ac_combat_headers(natid plane_owner, natid def_own)
529 " %-10.10s %-10.10s strength int odds damage results\n",
530 cname(plane_owner), cname(def_own));
532 " %-10.10s %-10.10s strength int odds damage results\n",
533 cname(def_own), cname(plane_owner));
540 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list,
543 register struct plist *attacker;
544 register struct plist *interceptor;
545 struct emp_qelem *att;
546 struct emp_qelem *in;
550 struct emp_qelem *att_next;
551 struct emp_qelem *in_next;
554 att = att_list->q_forw;
555 in = int_list->q_forw;
558 if (QEMPTY(att_list) || QEMPTY(int_list)) {
562 while (more_att || more_int) {
563 in_next = in->q_forw;
564 att_next = att->q_forw;
565 attacker = (struct plist *)att;
567 /* skip missiles. If only missiles left, we're done */
568 if (plchr[(int)attacker->plane.pln_type].pl_flags & P_M) {
570 if (att == att_list) {
572 if (QEMPTY(att_list))
577 if (all_missiles(att_list))
581 interceptor = (struct plist *)in;
582 att_own = attacker->plane.pln_own;
583 def_own = interceptor->plane.pln_own;
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(register struct plist *ap, register 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 if (ap->plane.pln_att == 0) {
646 att = ap->plane.pln_def * ap->plane.pln_effic / 100;
647 att = MAX(att, ap->pcp->pl_def / 2);
649 att = ap->plane.pln_att * ap->plane.pln_effic / 100;
650 att = MAX(att, ap->pcp->pl_att / 2);
653 def = dp->plane.pln_def * dp->plane.pln_effic / 100;
654 def = MAX(def, dp->pcp->pl_def / 2);
656 if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
658 if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
660 att += ((float)ap->pcp->pl_stealth / 25.0);
661 def += ((float)dp->pcp->pl_stealth / 25.0);
670 odds = ((double)att / ((double)def + (double)att));
673 intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1;
675 PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds);
676 PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds);
680 while ((intensity--) > 0) {
684 if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF)
688 if ((ap->plane.pln_effic - adam) < PLANE_MINEFF)
693 if (dp->pcp->pl_flags & P_M)
696 PR(att_own, "%3d/%-3d", adam, ddam);
697 PR(def_own, "%3d/%-3d", ddam, adam);
698 ac_planedamage(ap, dp->plane.pln_own, adam, def_own, 1, 0, mesg);
699 strncpy(temp, mesg, 14);
700 ac_planedamage(dp, ap->plane.pln_own, ddam, att_own, 1, 0, mesg);
701 PR(att_own, "%-13.13s %-13.13s\n", temp, mesg);
702 PR(def_own, "%-13.13s %-13.13s\n", mesg, temp);
706 * zap plane associated with plp.
707 * Damaging country is "from", damage is "dam".
708 * def_own is the country on the other side of the conflict from the plane
709 * owner. The only time def_own != from is when the interceptor is getting
712 * NOTE: This routine removes the appropriate plane element from the
713 * queue if it gets destroyed. That means that the caller must assume
714 * that the current queue pointer is invalid on return from the ac_planedamage
715 * call. (this has caused bugs in the past)
718 ac_planedamage(struct plist *plp, natid from, int dam, natid other,
719 int checkabort, int show, s_char *mesg)
721 register struct plnstr *pp;
727 /* s_char *sprintf(); already in misc.h [JFW] */
732 plane_owner = pp->pln_own;
734 sprintf(dmess, " no damage");
743 if (eff < PLANE_MINEFF) {
744 sprintf(dmess, " shot down");
746 } else if (eff < 80 && chance((100 - 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 (from != 0 && (plp->pcp->pl_flags & P_M) == 0)
772 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
773 if (pp->pln_ship >= 0) {
774 getship(pp->pln_ship, &ship);
775 take_plane_off_ship(pp, &ship);
777 if (pp->pln_land >= 0) {
778 getland(pp->pln_land, &land);
779 take_plane_off_land(pp, &land);
781 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
783 putplane(pp->pln_uid, pp);
784 emp_remque(&plp->queue);
786 } else if (disp == 2) {
787 putplane(pp->pln_uid, pp);
788 emp_remque(&plp->queue);
791 putplane(pp->pln_uid, pp);
796 ac_doflak(struct emp_qelem *list, struct sctstr *from)
803 plp = (struct plist *)list->q_forw;
804 plane_owner = plp->plane.pln_own;
806 gun = getvar(V_GUN, (s_char *)from, EF_SECTOR);
807 shell = getvar(V_SHELL, (s_char *)from, EF_SECTOR);
809 if (shell < (gun / 2))
810 add = supply_commod(from->sct_own, from->sct_x, from->sct_y,
811 I_SHELL, ldround(((double)gun / 2.0),
814 if (gun == 0 || shell == 0)
821 putvar(V_SHELL, shell, (s_char *)from, EF_SECTOR);
823 gun = 2.0 * tfact(from->sct_own, (double)gun);
825 PR(plane_owner, "firing %d flak guns in %s...\n",
826 gun, xyas(from->sct_x, from->sct_y, plane_owner));
827 if (from->sct_own != 0)
828 PR(from->sct_own, "firing %d flak guns in %s...\n",
829 gun, xyas(from->sct_x, from->sct_y, from->sct_own));
830 ac_fireflak(list, from->sct_own, 0, gun);
835 ac_shipflak(struct emp_qelem *list, coord x, coord y)
850 plp = (struct plist *)list->q_forw;
851 plane_owner = plp->plane.pln_own;
853 bzero((s_char *)nats, sizeof(nats));
855 snxtitem_xy(&ni, EF_SHIP, x, y);
856 while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&ship)) {
857 if (ship.shp_own == 0 || ship.shp_own == plane_owner)
861 mcp = &mchr[(int)ship.shp_type];
862 if (mcp->m_flags & M_SUB)
864 rel = getrel(getnatp(ship.shp_own), plane_owner);
868 gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim);
870 shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP);
872 shell = supply_commod(ship.shp_own, ship.shp_x,
873 ship.shp_y, I_SHELL, 1);
875 if (gun == 0 || shell == 0)
877 firing = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
880 if (!nats[ship.shp_own]) {
881 /* First time here, print the message */
882 PR(ship.shp_own, "%s planes spotted over ships in %s\n",
883 cname(plane_owner), xyas(x, y, ship.shp_own));
884 PR(plane_owner, "Flying over %s ships in %s\n",
885 cname(ship.shp_own), xyas(x, y, plane_owner));
886 nats[ship.shp_own] = 1;
888 PR(ship.shp_own, "firing %d flak guns from %s...\n",
889 firing, prship(&ship));
890 putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP);
891 putship(ship.shp_uid, &ship);
897 guns = 2.0 * tfact(from, (double)guns);
898 PR(plane_owner, "Flak! Ships firing %d flak guns...\n", guns);
899 ac_fireflak(list, from, 0, guns);
904 ac_landflak(struct emp_qelem *list, coord x, coord y)
917 plp = (struct plist *)list->q_forw;
918 plane_owner = plp->plane.pln_own;
920 bzero((s_char *)nats, sizeof(nats));
922 snxtitem_xy(&ni, EF_LAND, x, y);
923 while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&land)) {
924 if (land.lnd_own == 0 || land.lnd_own == plane_owner)
928 lcp = &lchr[(int)land.lnd_type];
930 if ((lcp->l_flags & L_FLAK) == 0)
933 if (land.lnd_aaf == 0)
936 rel = getrel(getnatp(land.lnd_own), plane_owner);
940 (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
943 if (!nats[land.lnd_own]) {
944 /* First time here, print the message */
945 PR(land.lnd_own, "%s planes spotted over land units in %s\n",
946 cname(plane_owner), xyas(x, y, land.lnd_own));
947 PR(plane_owner, "Flying over %s land units in %s\n",
948 cname(land.lnd_own), xyas(x, y, plane_owner));
949 nats[land.lnd_own] = 1;
951 PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
952 prland(&land), land.lnd_aaf);
954 from = land.lnd_own; /* We always use the last owner as the from */
959 guns = 2.0 * tfact(from, (double)guns);
960 PR(plane_owner, "Flak! Land units firing %d flak guns...\n",
962 ac_fireflak(list, from, 0, guns);
967 * Called from shipflak, landflak, and doflak.
970 ac_fireflak(struct emp_qelem *list, natid from, natid other, int guns)
972 extern double flakscale;
973 register struct plnstr *pp;
978 struct emp_qelem *qp;
979 struct emp_qelem *next;
982 plp = (struct plist *)list->q_forw;
984 for (qp = list->q_forw; qp != list; qp = next) {
986 * fighters don't get shot at by flak
987 * non-tactical bombers are harder to hit with flak.
988 * ('Cause they're not dive-bombing?)
991 plp = (struct plist *)qp;
993 diff = guns - pp->pln_def;
994 if ((plp->pcp->pl_flags & P_T) == 0)
996 if (plp->pcp->pl_flags & P_X)
998 if (plp->pcp->pl_flags & P_H)
1001 mult = flaktable[FLAK_MAX] * 1.33;
1003 mult = flaktable[0] * 0.66;
1006 mult = flaktable[diff];
1009 n = (int)((roll(8) + 2) * mult);
1012 ac_planedamage(plp, from, n, other, 2, 1, msg);
1017 * See if this plane is flying in this list
1020 ac_isflying(struct plnstr *plane, struct emp_qelem *list)
1022 struct emp_qelem *qp;
1023 struct emp_qelem *next;
1029 for (qp = list->q_forw; qp != list; qp = next) {
1031 plp = (struct plist *)qp;
1033 if (plane->pln_uid == pp->pln_uid)
1041 * Get a list of planes available for interception duties.
1044 getilist(struct emp_qelem *list, natid own, struct emp_qelem *a,
1045 struct emp_qelem *b, struct emp_qelem *c, struct emp_qelem *d)
1047 register struct plchrstr *pcp;
1048 struct plnstr plane;
1052 struct nstr_item ni;
1058 snxtitem_all(&ni, EF_PLANE);
1059 while (nxtitem(&ni, (s_char *)&plane)) {
1060 if (plane.pln_own != own)
1062 pcp = &plchr[(int)plane.pln_type];
1063 if ((pcp->pl_flags & P_F) == 0)
1065 if (plane.pln_mission != 0)
1067 if (plane.pln_mobil <= 0)
1069 if (plane.pln_effic < 40)
1071 if (plane.pln_ship >= 0) {
1072 if (!can_fly(plane.pln_uid))
1074 getship(plane.pln_ship, &ship);
1075 ptr = (s_char *)&ship;
1077 } else if (plane.pln_land >= 0) {
1078 if (!can_fly(plane.pln_uid))
1080 getland(plane.pln_land, &land);
1081 ptr = (s_char *)&land;
1084 getsect(plane.pln_x, plane.pln_y, §);
1085 ptr = (s_char *)§
1088 if (sect.sct_effic < 60 && (pcp->pl_flags & P_V) == 0)
1091 if ((sect.sct_effic < 60 || sect.sct_type != SCT_AIRPT)
1092 && (pcp->pl_flags & P_V) == 0)
1096 if (((float)getvar(V_PETROL, ptr, type)) <
1097 (((float)pcp->pl_fuel) / 2.0))
1099 /* Finally, is it in the list of planes already in
1101 if (ac_isflying(&plane, a))
1103 if (ac_isflying(&plane, b))
1105 if (ac_isflying(&plane, c))
1107 if (ac_isflying(&plane, d))
1110 ip = (struct plist *)malloc(sizeof(*ip));
1114 ip->pcp = &plchr[(int)plane.pln_type];
1115 bcopy((s_char *)&plane, (s_char *)&ip->plane, sizeof(plane));
1116 emp_insque(&ip->queue, list);
1124 { /* Can this plane fly from the ship or land unit it is on? */
1125 struct plnstr plane;
1128 struct plchrstr *pcp;
1129 struct mchrstr *scp;
1130 struct lchrstr *lcp;
1132 getplane(p, &plane);
1133 pcp = &plchr[(int)plane.pln_type];
1135 if (plane.pln_ship >= 0) {
1136 if (!(pcp->pl_flags & P_L) && !(pcp->pl_flags & P_M)
1137 && !(pcp->pl_flags & P_K)
1138 && !(pcp->pl_flags & P_E)
1142 getship(plane.pln_ship, &ship);
1143 scp = &mchr[(int)ship.shp_type];
1145 if ((pcp->pl_flags & P_L) && (scp->m_flags & M_FLY)) {
1149 if ((pcp->pl_flags & P_M) && (scp->m_flags & M_MSL)) {
1153 if ((pcp->pl_flags & P_K) && (scp->m_flags & M_CHOPPER)) {
1157 if ((pcp->pl_flags & P_E) && (scp->m_flags & M_XLIGHT)) {
1162 if (plane.pln_land >= 0) {
1163 if (!(pcp->pl_flags & P_E))
1166 getland(plane.pln_land, &land);
1167 lcp = &lchr[(int)land.lnd_type];
1169 if ((pcp->pl_flags & P_E) && (lcp->l_flags & L_XLIGHT)) {
1178 do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
1180 struct emp_qelem *qp;
1185 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
1186 plp = (struct plist *)qp;
1187 if (evade > ((float)plp->pcp->pl_stealth / 100.0))
1188 evade = (plp->pcp->pl_stealth / 100.0);
1190 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) {
1191 plp = (struct plist *)qp;
1192 if (evade > plp->pcp->pl_stealth / 100.0)
1193 evade = (plp->pcp->pl_stealth / 100.0);