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 memset(&head, 0, sizeof(struct shiplook));
116 plp = (struct plist *)bomb_list->q_forw;
117 plane_owner = plp->plane.pln_own;
119 strncpy(mypath, path, sizeof(mypath));
122 memset(overfly, 0, sizeof(overfly));
123 memset(gotilist, 0, sizeof(gotilist));
124 memset(unfriendly, 0, sizeof(unfriendly));
125 for (cn = 1; cn < MAXNOC; cn++) {
126 if ((mynatp = getnatp(cn)) == 0)
128 rel = getrel(mynatp, plane_owner);
131 if (plane_owner == cn)
135 if (mission_flags & PM_R) {
136 if (mission_flags & P_S) {
137 PR(plane_owner, "\nSPY Plane report\n");
140 } else if (mission_flags & P_A) {
141 PR(plane_owner, "\nAnti-Sub Patrol report\n");
143 PR(plane_owner, "\nReconnaissance report\n");
148 pln_removedupes(bomb_list, esc_list);
149 while ((dir = mypath[myp++]) && !QEMPTY(bomb_list)) {
150 if ((val = chkdir(dir, DIR_STOP, DIR_LAST)) == 0)
152 /* XXX using xnorm is probably bad */
153 x = xnorm(x + diroff[val][0]);
154 y = ynorm(y + diroff[val][1]);
155 getsect(x, y, §);
156 over = getnatp(sect.sct_own);
158 setcont(plane_owner, sect.sct_own, FOUND_FLY);
161 if (mission_flags & PM_R) {
162 if (sect.sct_type == SCT_WATER) {
163 PR(plane_owner, "flying over %s at %s\n",
164 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
165 if (mission_flags & PM_S)
166 plane_sweep(bomb_list, x, y);
167 if (mission_flags & P_A) {
168 plane_sona(bomb_list, x, y, &head);
170 changed += map_set(plane_owner,
171 sect.sct_x, sect.sct_y,
172 dchr[sect.sct_type].d_mnem, 0);
173 } else if (mission_flags & P_S) {
174 satdisp(§, (mission_flags & P_I) ? 10 : 50, 1);
176 /* This is borrowed from lookout */
177 if (sect.sct_own == plane_owner)
178 PR(plane_owner, "Your ");
181 "%s (#%d) ", cname(sect.sct_own), sect.sct_own);
182 PR(plane_owner, dchr[sect.sct_type].d_name);
183 changed += map_set(plane_owner,
184 sect.sct_x, sect.sct_y,
185 dchr[sect.sct_type].d_mnem, 0);
186 PR(plane_owner, " %d%% efficient ",
187 (sect.sct_own == plane_owner) ?
188 sect.sct_effic : roundintby((int)sect.sct_effic, 25));
189 civ = getvar(V_CIVIL, (s_char *)§, EF_SECTOR);
190 mil = getvar(V_MILIT, (s_char *)§, EF_SECTOR);
192 PR(plane_owner, "with %s%d civ ",
193 (sect.sct_own == plane_owner) ?
195 (sect.sct_own == plane_owner) ?
196 civ : roundintby(civ, 25));
198 PR(plane_owner, "with %s%d mil ",
199 (sect.sct_own == plane_owner) ?
201 (sect.sct_own == plane_owner) ?
202 mil : roundintby(mil, 25));
203 PR(plane_owner, "@ %s\n", xyas(x, y, plane_owner));
206 PR(plane_owner, "flying over %s at %s\n",
207 dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
208 changed += map_set(plane_owner, sect.sct_x,
209 sect.sct_y, dchr[sect.sct_type].d_mnem, 0);
211 if ((rel = getrel(over, plane_owner)) == ALLIED)
214 evaded = do_evade(bomb_list, esc_list);
216 if (sect.sct_own != 0 && sect.sct_own != plane_owner && (!evaded)) {
217 /* We only show planes overhead if they didn't
219 overfly[sect.sct_own]++;
220 PR(sect.sct_own, "%s planes spotted over %s\n",
221 cname(plane_owner), xyas(x, y, sect.sct_own));
226 if (unfriendly[sect.sct_own])
227 ac_doflak(bomb_list, §);
228 /* If bombers left, fire flak from units and ships */
229 if (!QEMPTY(bomb_list))
230 ac_landflak(bomb_list, x, y);
231 if (!QEMPTY(bomb_list))
232 ac_shipflak(bomb_list, x, y);
234 /* mission planes aborted due to flak -- don't send escorts */
235 if (QEMPTY(bomb_list))
237 if ((!no_air_defense) && (!evaded))
238 air_defense(x, y, plane_owner, bomb_list, esc_list);
240 if (sect.sct_own == 0 || sect.sct_own == plane_owner)
247 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
248 struct plist *ip = (struct plist *)qp;
249 if (!(plchr[(int)ip->plane.pln_type].pl_flags & P_M))
256 if (unfriendly[sect.sct_own] && !gotilist[sect.sct_own]) {
257 getilist(&ilist[sect.sct_own], sect.sct_own,
258 bomb_list, esc_list, obomb, oesc);
259 gotilist[sect.sct_own]++;
263 ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
267 intown = sect.sct_own;
270 /* Let's report all of the overflights even if aborted */
271 for (cn = 1; cn < MAXNOC; cn++) {
272 if (plane_owner == cn)
275 nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]);
277 /* If the map changed, update it */
279 if (!update_pending && plane_owner == player->cnum)
280 writemap(player->cnum);
281 /* Now, if the bomber and escort lists are empty, we are done */
282 if (QEMPTY(bomb_list) && QEMPTY(esc_list)) {
283 if (mission_flags & P_A) {
285 while (s != (struct shiplook *)0) {
294 /* Something made it through */
295 /* Go figure out if there are ships in this sector, and who's they are */
296 memset(nats, 0, sizeof(nats));
297 snxtitem_xy(&ni, EF_SHIP, x, y);
298 while (nxtitem(&ni, (s_char *)&ship)) {
299 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
301 nats[ship.shp_own]++;
303 /* Go figure out if there are units in this sector, and who's they are */
304 memset(lnats, 0, sizeof(lnats));
305 snxtitem_xy(&ni, EF_LAND, x, y);
306 while (nxtitem(&ni, (s_char *)&land)) {
307 lnats[land.lnd_own]++;
310 /* Now, let's make life a little rougher. */
311 for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
312 if (plane_owner == cn)
315 /* Are there ships owned by this country? */
319 PR(cn, "%s planes spotted over ships in %s\n",
320 cname(plane_owner), xyas(x, y, cn));
321 if (unfriendly[cn]) {
322 /* They are unfriendly too */
324 getilist(&ilist[cn], cn, bomb_list, esc_list, obomb,
328 PR(plane_owner, "Flying over %s ships in %s\n", cname(cn),
329 xyas(x, y, plane_owner));
330 /* This makes going for ships in harbors tough */
332 /* We already fired flak up above. Now we intercept again if we haven't already */
333 /* Flag that we intercepted */
335 /* And now intercept again */
336 ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x,
341 /* Are there units owned by this country? */
342 if (lnats[cn] != 0) {
345 PR(cn, "%s planes spotted over land units in %s\n",
346 cname(plane_owner), xyas(x, y, cn));
347 if (unfriendly[cn]) {
348 /* They are unfriendly too */
350 getilist(&ilist[cn], cn, bomb_list, esc_list, obomb,
354 PR(plane_owner, "Flying over %s land units in %s\n",
355 cname(cn), xyas(x, y, plane_owner));
358 /* We haven't intercepted yet, so intercept */
359 ac_intercept(bomb_list, esc_list, &ilist[cn], cn,
367 if ((mission_flags & P_A) && (head.uid != -1)) {
369 while (s != (struct shiplook *)0) {
378 count_non_missiles(struct emp_qelem *list)
380 struct emp_qelem *qp;
384 /* don't intercept missiles */
385 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
386 plp = (struct plist *)qp;
387 if (!(plp->pcp->pl_flags & P_M))
394 sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
395 natid def_own, natid plane_owner, coord x, coord y,
398 struct emp_qelem *aqp;
399 struct emp_qelem *anext;
400 struct emp_qelem *dqp;
401 struct emp_qelem *dnext;
406 for (aqp = att_list->q_forw,
407 dqp = def_list->q_forw;
408 aqp != att_list && dqp != def_list; aqp = anext) {
410 aplp = (struct plist *)aqp;
411 if (aplp->pcp->pl_flags & P_M)
413 if (aplp->pcp->pl_cost < 1000)
415 for (; dqp != def_list; dqp = dnext) {
417 dplp = (struct plist *)dqp;
418 if (!(dplp->pcp->pl_flags & P_M))
421 if (dplp->plane.pln_range <
422 mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) {
427 if (mission_pln_equip(dplp, 0, P_F, 0) < 0) {
434 PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
435 PR(def_own, "Launching SAMs at %s planes!\n",
437 ac_combat_headers(plane_owner, def_own);
445 PR(plane_owner, "\n");
448 if (delete_missiles) {
449 for (; dqp != def_list; dqp = dnext) {
451 dplp = (struct plist *)dqp;
452 if (!(dplp->pcp->pl_flags & P_M))
462 ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
463 struct emp_qelem *def_list, natid def_own, coord x, coord y)
465 register struct plnstr *pp;
468 struct emp_qelem *next;
469 struct emp_qelem *qp;
470 struct emp_qelem int_list;
475 plp = (struct plist *)bomb_list->q_forw;
476 plane_owner = plp->plane.pln_own;
480 sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0);
481 sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 1);
482 if (!(att_count = count_non_missiles(bomb_list) +
483 count_non_missiles(esc_list)))
486 emp_initque(&int_list);
487 for (qp = def_list->q_forw; qp != def_list; qp = next) {
489 plp = (struct plist *)qp;
491 /* SAMs interdict separately */
492 if (plp->pcp->pl_flags & P_M)
494 dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2;
495 if (pp->pln_range < dist)
497 if (mission_pln_equip(plp, 0, P_F, 0) < 0) {
502 /* got one; delete from def_list, add to int_list */
504 emp_insque(qp, &int_list);
505 pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
506 putplane(pp->pln_uid, pp);
508 if (icount > att_count)
513 PR(plane_owner, "%d %s fighter%s rising to intercept!\n", icount,
514 cname(def_own), icount == 1 ? " is" : "s are");
515 PR(def_own, "%d fighter%s intercepting %s planes!\n", icount,
516 icount == 1 ? " is" : "s are", cname(plane_owner));
517 ac_combat_headers(plane_owner, def_own);
518 ac_airtoair(esc_list, &int_list, def_own);
519 ac_airtoair(bomb_list, &int_list, def_own);
520 PR(plane_owner, "\n");
525 ac_combat_headers(natid plane_owner, natid def_own)
528 " %-10.10s %-10.10s strength int odds damage results\n",
529 cname(plane_owner), cname(def_own));
531 " %-10.10s %-10.10s strength int odds damage results\n",
532 cname(def_own), cname(plane_owner));
539 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list,
542 register struct plist *attacker;
543 register struct plist *interceptor;
544 struct emp_qelem *att;
545 struct emp_qelem *in;
549 struct emp_qelem *att_next;
550 struct emp_qelem *in_next;
553 att = att_list->q_forw;
554 in = int_list->q_forw;
557 if (QEMPTY(att_list) || QEMPTY(int_list)) {
561 while (more_att || more_int) {
562 in_next = in->q_forw;
563 att_next = att->q_forw;
564 attacker = (struct plist *)att;
566 /* skip missiles. If only missiles left, we're done */
567 if (plchr[(int)attacker->plane.pln_type].pl_flags & P_M) {
569 if (att == att_list) {
571 if (QEMPTY(att_list))
576 if (all_missiles(att_list))
580 interceptor = (struct plist *)in;
581 att_own = attacker->plane.pln_own;
582 def_own = interceptor->plane.pln_own;
583 nplanes = attacker->plane.pln_effic;
584 if (nplanes > interceptor->plane.pln_effic)
585 nplanes = interceptor->plane.pln_effic;
586 ac_dog(attacker, interceptor);
589 if (att == att_list) {
591 if (QEMPTY(att_list))
596 if (in == int_list) {
598 if (QEMPTY(int_list))
607 all_missiles(struct emp_qelem *att_list)
609 struct emp_qelem *qp;
612 qp = att_list->q_forw;
613 while (qp != att_list) {
614 p = (struct plist *)qp;
615 if (!(plchr[(int)p->plane.pln_type].pl_flags & P_M))
624 ac_dog(register struct plist *ap, register struct plist *dp)
629 natid att_own, def_own;
634 att_own = ap->plane.pln_own;
635 def_own = dp->plane.pln_own;
637 PR(att_own, " %3.3s #%-4d %3.3s #%-4d",
639 ap->plane.pln_uid, dp->pcp->pl_name, dp->plane.pln_uid);
641 PR(def_own, " %3.3s #%-4d %3.3s #%-4d",
643 dp->plane.pln_uid, ap->pcp->pl_name, ap->plane.pln_uid);
644 if (ap->plane.pln_att == 0) {
645 att = ap->plane.pln_def * ap->plane.pln_effic / 100;
646 att = MAX(att, ap->pcp->pl_def / 2);
648 att = ap->plane.pln_att * ap->plane.pln_effic / 100;
649 att = MAX(att, ap->pcp->pl_att / 2);
652 def = dp->plane.pln_def * dp->plane.pln_effic / 100;
653 def = MAX(def, dp->pcp->pl_def / 2);
655 if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
657 if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
659 att += ((float)ap->pcp->pl_stealth / 25.0);
660 def += ((float)dp->pcp->pl_stealth / 25.0);
669 odds = ((double)att / ((double)def + (double)att));
672 intensity = roll(20) + roll(20) + roll(20) + roll(20) + 1;
674 PR(att_own, " %3d/%-3d %3d %3.2f ", att, def, intensity, odds);
675 PR(def_own, " %3d/%-3d %3d %3.2f ", def, att, intensity, odds);
679 while ((intensity--) > 0) {
683 if ((dp->plane.pln_effic - ddam) < PLANE_MINEFF)
687 if ((ap->plane.pln_effic - adam) < PLANE_MINEFF)
692 if (dp->pcp->pl_flags & P_M)
695 PR(att_own, "%3d/%-3d", adam, ddam);
696 PR(def_own, "%3d/%-3d", ddam, adam);
697 ac_planedamage(ap, dp->plane.pln_own, adam, def_own, 1, 0, mesg);
698 strncpy(temp, mesg, 14);
699 ac_planedamage(dp, ap->plane.pln_own, ddam, att_own, 1, 0, mesg);
700 PR(att_own, "%-13.13s %-13.13s\n", temp, mesg);
701 PR(def_own, "%-13.13s %-13.13s\n", mesg, temp);
705 * zap plane associated with plp.
706 * Damaging country is "from", damage is "dam".
707 * def_own is the country on the other side of the conflict from the plane
708 * owner. The only time def_own != from is when the interceptor is getting
711 * NOTE: This routine removes the appropriate plane element from the
712 * queue if it gets destroyed. That means that the caller must assume
713 * that the current queue pointer is invalid on return from the ac_planedamage
714 * call. (this has caused bugs in the past)
717 ac_planedamage(struct plist *plp, natid from, int dam, natid other,
718 int checkabort, int show, s_char *mesg)
720 register struct plnstr *pp;
726 /* s_char *sprintf(); already in misc.h [JFW] */
731 plane_owner = pp->pln_own;
733 sprintf(dmess, " no damage");
738 memset(dmess, 0, sizeof(dmess));
742 if (eff < PLANE_MINEFF) {
743 sprintf(dmess, " shot down");
745 } else if (eff < 80 && chance((100 - eff) / 100.0) && checkabort) {
746 sprintf(dmess, " aborted @%2d%%", eff);
748 } else if (show == 0) {
749 sprintf(dmess, " cleared");
752 if ((plp->pcp->pl_flags & P_M) == 0) {
754 PR(plane_owner, " %s %s takes %d%s.\n",
755 cname(pp->pln_own), prplane(pp), dam, dmess);
757 PR(other, " %s %s takes %d%s.\n",
758 cname(pp->pln_own), prplane(pp), dam, dmess);
761 if (show && checkabort == 1) {
762 PR(plane_owner, "\n");
768 pp->pln_mobil -= min(32 + pp->pln_mobil, dam / 2);
770 if (from != 0 && (plp->pcp->pl_flags & P_M) == 0)
771 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
772 if (pp->pln_ship >= 0) {
773 getship(pp->pln_ship, &ship);
774 take_plane_off_ship(pp, &ship);
776 if (pp->pln_land >= 0) {
777 getland(pp->pln_land, &land);
778 take_plane_off_land(pp, &land);
780 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
782 putplane(pp->pln_uid, pp);
783 emp_remque(&plp->queue);
785 } else if (disp == 2) {
786 putplane(pp->pln_uid, pp);
787 emp_remque(&plp->queue);
790 putplane(pp->pln_uid, pp);
795 ac_doflak(struct emp_qelem *list, struct sctstr *from)
802 plp = (struct plist *)list->q_forw;
803 plane_owner = plp->plane.pln_own;
805 gun = getvar(V_GUN, (s_char *)from, EF_SECTOR);
806 shell = getvar(V_SHELL, (s_char *)from, EF_SECTOR);
808 if (shell < (gun / 2))
809 add = supply_commod(from->sct_own, from->sct_x, from->sct_y,
810 I_SHELL, ldround(((double)gun / 2.0),
813 if (gun == 0 || shell == 0)
820 putvar(V_SHELL, shell, (s_char *)from, EF_SECTOR);
822 gun = 2.0 * tfact(from->sct_own, (double)gun);
824 PR(plane_owner, "firing %d flak guns in %s...\n",
825 gun, xyas(from->sct_x, from->sct_y, plane_owner));
826 if (from->sct_own != 0)
827 PR(from->sct_own, "firing %d flak guns in %s...\n",
828 gun, xyas(from->sct_x, from->sct_y, from->sct_own));
829 ac_fireflak(list, from->sct_own, 0, gun);
834 ac_shipflak(struct emp_qelem *list, coord x, coord y)
849 plp = (struct plist *)list->q_forw;
850 plane_owner = plp->plane.pln_own;
852 memset(nats, 0, sizeof(nats));
854 snxtitem_xy(&ni, EF_SHIP, x, y);
855 while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&ship)) {
856 if (ship.shp_own == 0 || ship.shp_own == plane_owner)
860 mcp = &mchr[(int)ship.shp_type];
861 if (mcp->m_flags & M_SUB)
863 rel = getrel(getnatp(ship.shp_own), plane_owner);
867 gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim);
869 shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP);
871 shell = supply_commod(ship.shp_own, ship.shp_x,
872 ship.shp_y, I_SHELL, 1);
874 if (gun == 0 || shell == 0)
876 firing = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
879 if (!nats[ship.shp_own]) {
880 /* First time here, print the message */
881 PR(ship.shp_own, "%s planes spotted over ships in %s\n",
882 cname(plane_owner), xyas(x, y, ship.shp_own));
883 PR(plane_owner, "Flying over %s ships in %s\n",
884 cname(ship.shp_own), xyas(x, y, plane_owner));
885 nats[ship.shp_own] = 1;
887 PR(ship.shp_own, "firing %d flak guns from %s...\n",
888 firing, prship(&ship));
889 putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP);
890 putship(ship.shp_uid, &ship);
896 guns = 2.0 * tfact(from, (double)guns);
897 PR(plane_owner, "Flak! Ships firing %d flak guns...\n", guns);
898 ac_fireflak(list, from, 0, guns);
903 ac_landflak(struct emp_qelem *list, coord x, coord y)
916 plp = (struct plist *)list->q_forw;
917 plane_owner = plp->plane.pln_own;
919 memset(nats, 0, sizeof(nats));
921 snxtitem_xy(&ni, EF_LAND, x, y);
922 while (!QEMPTY(list) && nxtitem(&ni, (s_char *)&land)) {
923 if (land.lnd_own == 0 || land.lnd_own == plane_owner)
927 lcp = &lchr[(int)land.lnd_type];
929 if ((lcp->l_flags & L_FLAK) == 0)
932 if (land.lnd_aaf == 0)
935 rel = getrel(getnatp(land.lnd_own), plane_owner);
939 (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
942 if (!nats[land.lnd_own]) {
943 /* First time here, print the message */
944 PR(land.lnd_own, "%s planes spotted over land units in %s\n",
945 cname(plane_owner), xyas(x, y, land.lnd_own));
946 PR(plane_owner, "Flying over %s land units in %s\n",
947 cname(land.lnd_own), xyas(x, y, plane_owner));
948 nats[land.lnd_own] = 1;
950 PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
951 prland(&land), land.lnd_aaf);
953 from = land.lnd_own; /* We always use the last owner as the from */
958 guns = 2.0 * tfact(from, (double)guns);
959 PR(plane_owner, "Flak! Land units firing %d flak guns...\n",
961 ac_fireflak(list, from, 0, guns);
966 * Called from shipflak, landflak, and doflak.
969 ac_fireflak(struct emp_qelem *list, natid from, natid other, int guns)
971 register struct plnstr *pp;
976 struct emp_qelem *qp;
977 struct emp_qelem *next;
980 plp = (struct plist *)list->q_forw;
982 for (qp = list->q_forw; qp != list; qp = next) {
984 * fighters don't get shot at by flak
985 * non-tactical bombers are harder to hit with flak.
986 * ('Cause they're not dive-bombing?)
989 plp = (struct plist *)qp;
991 diff = guns - pp->pln_def;
992 if ((plp->pcp->pl_flags & P_T) == 0)
994 if (plp->pcp->pl_flags & P_X)
996 if (plp->pcp->pl_flags & P_H)
999 mult = flaktable[FLAK_MAX] * 1.33;
1001 mult = flaktable[0] * 0.66;
1004 mult = flaktable[diff];
1007 n = (int)((roll(8) + 2) * mult);
1010 ac_planedamage(plp, from, n, other, 2, 1, msg);
1015 * See if this plane is flying in this list
1018 ac_isflying(struct plnstr *plane, struct emp_qelem *list)
1020 struct emp_qelem *qp;
1021 struct emp_qelem *next;
1027 for (qp = list->q_forw; qp != list; qp = next) {
1029 plp = (struct plist *)qp;
1031 if (plane->pln_uid == pp->pln_uid)
1039 * Get a list of planes available for interception duties.
1042 getilist(struct emp_qelem *list, natid own, struct emp_qelem *a,
1043 struct emp_qelem *b, struct emp_qelem *c, struct emp_qelem *d)
1045 register struct plchrstr *pcp;
1046 struct plnstr plane;
1050 struct nstr_item ni;
1056 snxtitem_all(&ni, EF_PLANE);
1057 while (nxtitem(&ni, (s_char *)&plane)) {
1058 if (plane.pln_own != own)
1060 pcp = &plchr[(int)plane.pln_type];
1061 if ((pcp->pl_flags & P_F) == 0)
1063 if (plane.pln_mission != 0)
1065 if (plane.pln_mobil <= 0)
1067 if (plane.pln_effic < 40)
1069 if (plane.pln_ship >= 0) {
1070 if (!can_fly(plane.pln_uid))
1072 getship(plane.pln_ship, &ship);
1073 ptr = (s_char *)&ship;
1075 } else if (plane.pln_land >= 0) {
1076 if (!can_fly(plane.pln_uid))
1078 getland(plane.pln_land, &land);
1079 ptr = (s_char *)&land;
1082 getsect(plane.pln_x, plane.pln_y, §);
1083 ptr = (s_char *)§
1086 if (sect.sct_effic < 60 && (pcp->pl_flags & P_V) == 0)
1089 if ((sect.sct_effic < 60 || sect.sct_type != SCT_AIRPT)
1090 && (pcp->pl_flags & P_V) == 0)
1094 if (((float)getvar(V_PETROL, ptr, type)) <
1095 (((float)pcp->pl_fuel) / 2.0))
1097 /* Finally, is it in the list of planes already in
1099 if (ac_isflying(&plane, a))
1101 if (ac_isflying(&plane, b))
1103 if (ac_isflying(&plane, c))
1105 if (ac_isflying(&plane, d))
1108 ip = (struct plist *)malloc(sizeof(*ip));
1112 ip->pcp = &plchr[(int)plane.pln_type];
1114 emp_insque(&ip->queue, list);
1122 { /* Can this plane fly from the ship or land unit it is on? */
1123 struct plnstr plane;
1126 struct plchrstr *pcp;
1127 struct mchrstr *scp;
1128 struct lchrstr *lcp;
1130 getplane(p, &plane);
1131 pcp = &plchr[(int)plane.pln_type];
1133 if (plane.pln_ship >= 0) {
1134 if (!(pcp->pl_flags & P_L) && !(pcp->pl_flags & P_M)
1135 && !(pcp->pl_flags & P_K)
1136 && !(pcp->pl_flags & P_E)
1140 getship(plane.pln_ship, &ship);
1141 scp = &mchr[(int)ship.shp_type];
1143 if ((pcp->pl_flags & P_L) && (scp->m_flags & M_FLY)) {
1147 if ((pcp->pl_flags & P_M) && (scp->m_flags & M_MSL)) {
1151 if ((pcp->pl_flags & P_K) && (scp->m_flags & M_CHOPPER)) {
1155 if ((pcp->pl_flags & P_E) && (scp->m_flags & M_XLIGHT)) {
1160 if (plane.pln_land >= 0) {
1161 if (!(pcp->pl_flags & P_E))
1164 getland(plane.pln_land, &land);
1165 lcp = &lchr[(int)land.lnd_type];
1167 if ((pcp->pl_flags & P_E) && (lcp->l_flags & L_XLIGHT)) {
1176 do_evade(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
1178 struct emp_qelem *qp;
1183 for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw) {
1184 plp = (struct plist *)qp;
1185 if (evade > ((float)plp->pcp->pl_stealth / 100.0))
1186 evade = (plp->pcp->pl_stealth / 100.0);
1188 for (qp = esc_list->q_forw; qp != esc_list; qp = qp->q_forw) {
1189 plp = (struct plist *)qp;
1190 if (evade > plp->pcp->pl_stealth / 100.0)
1191 evade = (plp->pcp->pl_stealth / 100.0);