]> git.pond.sub.org Git - empserver/blob - src/lib/commands/bomb.c
retreat: Fix group retreat after failed board sinks ship
[empserver] / src / lib / commands / bomb.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 of the License, or
9  *  (at your option) any later version.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  bomb.c: Fly bombing missions
28  *
29  *  Known contributors to this file:
30  *     Dave Pare, 1986
31  *     Ken Stevens, 1995
32  *     Steve McClure, 1998-2000
33  *     Markus Armbruster, 2004-2015
34  */
35
36 #include <config.h>
37
38 #include <ctype.h>
39 #include "chance.h"
40 #include "commands.h"
41 #include "damage.h"
42 #include "item.h"
43 #include "land.h"
44 #include "news.h"
45 #include "nuke.h"
46 #include "optlist.h"
47 #include "path.h"
48 #include "plane.h"
49 #include "retreat.h"
50 #include "ship.h"
51
52 static void pin_bomb(struct emp_qelem *, struct sctstr *);
53 static void eff_bomb(struct emp_qelem *, struct sctstr *);
54 static void comm_bomb(struct emp_qelem *, struct sctstr *);
55 static void ship_bomb(struct emp_qelem *, struct sctstr *);
56 static void plane_bomb(struct emp_qelem *, struct sctstr *);
57 static void land_bomb(struct emp_qelem *, struct sctstr *);
58 static void strat_bomb(struct emp_qelem *, struct sctstr *);
59 static int changed_plane_aborts(struct plist *);
60 static int pinflak_planedamage(struct plnstr *, struct plchrstr *,
61                                natid, int);
62
63 static i_type bombcomm[] = {
64     I_CIVIL,
65     I_MILIT,
66     I_SHELL,
67     I_GUN,
68     I_PETROL,
69     I_IRON,
70     I_DUST,
71     I_BAR,
72     I_FOOD,
73     I_OIL,
74     I_LCM,
75     I_HCM,
76     I_UW,
77     I_RAD
78 };
79 static int nbomb = sizeof(bombcomm) / sizeof(*bombcomm);
80
81 int
82 bomb(void)
83 {
84     char *p;
85     coord tx, ty;
86     coord ax, ay;
87     int ap_to_target;
88     char flightpath[MAX_PATH_LEN];
89     struct nstr_item ni_bomb;
90     struct nstr_item ni_esc;
91     struct sctstr target;
92     struct emp_qelem bomb_list;
93     struct emp_qelem esc_list;
94     struct sctstr ap_sect;
95     char mission;
96     struct plist *plp;
97     struct emp_qelem *qp, *next;
98     char buf[1024];
99
100     if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0)
101         return RET_SYN;
102     p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
103     if (!p || !*p)
104         return RET_SYN;
105     mission = *p;
106     if (!strchr("ps", mission))
107         return RET_SYN;
108     if (!get_assembly_point(player->argp[4], &ap_sect, buf))
109         return RET_SYN;
110     ax = ap_sect.sct_x;
111     ay = ap_sect.sct_y;
112     if (!getpath(flightpath, player->argp[5], ax, ay, 0, 0, MOB_FLY))
113         return RET_SYN;
114     tx = ax;
115     ty = ay;
116     (void)pathtoxy(flightpath, &tx, &ty, fcost);
117     pr("target sector is %s\n", xyas(tx, ty, player->cnum));
118     getsect(tx, ty, &target);
119     ap_to_target = strlen(flightpath);
120     if (flightpath[ap_to_target - 1] == 'h')
121         ap_to_target--;
122     pr("range to target is %d\n", ap_to_target);
123     /*
124      * select planes within range
125      */
126     pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, 2,
127             P_B | P_T, P_M | P_O);
128     pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, 2,
129             P_ESC | P_F, P_M | P_O);
130     /*
131      * now arm and equip the bombers, transports, whatever.
132      */
133     pln_arm(&bomb_list, 2 * ap_to_target, mission, NULL);
134     if (QEMPTY(&bomb_list)) {
135         pr("No planes could be equipped for the mission.\n");
136         return RET_FAIL;
137     }
138     pln_arm(&esc_list, 2 * ap_to_target, 'e', NULL);
139     ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0);
140     if (QEMPTY(&bomb_list)) {
141         pr("No planes got through fighter defenses\n");
142     } else if (target.sct_type == SCT_SANCT) {
143         pr("You can't bomb that sector!\n");
144     } else {
145         switch (mission) {
146         case 'p':
147             pin_bomb(&bomb_list, &target);
148             for (qp = bomb_list.q_forw; qp != &bomb_list; qp = next) {
149                 next = qp->q_forw;
150                 plp = (struct plist *)qp;
151                 changed_plane_aborts(plp);
152             }
153             for (qp = esc_list.q_forw; qp != &esc_list; qp = next) {
154                 next = qp->q_forw;
155                 plp = (struct plist *)qp;
156                 changed_plane_aborts(plp);
157             }
158             break;
159         case 's':
160             nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
161             strat_bomb(&bomb_list, &target);
162             break;
163         default:
164             CANT_REACH();
165         }
166     }
167     pln_put(&bomb_list);
168     pln_put(&esc_list);
169     return RET_OK;
170 }
171
172 static void
173 pin_bomb(struct emp_qelem *list, struct sctstr *target)
174 {
175     struct dchrstr *dcp;
176     int nplanes;
177     int nships;
178     int type;
179     int bad;
180     char *p;
181     int nsubs;
182     int nunits;
183     char buf[1024];
184     int i;
185
186     bad = 0;
187     type = target->sct_type;
188     dcp = &dchr[type];
189     pr("Target sector is a %s constructed %s\n",
190        effadv((int)target->sct_effic), dcp->d_name);
191     nsubs = 0;
192     nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
193     if (pln_caps(list) & P_A) {
194         nsubs = shipsatxy(target->sct_x, target->sct_y, M_SUB, 0, 1);
195         if (nsubs > 0)
196             pr("Some subs are present in the sector.\n");
197     }
198     nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
199     nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0, 0);
200   retry:
201     p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
202                   buf);
203     if (!p)
204        return;
205     if (!*p) {
206         bad++;
207         if (bad > 2)
208             return;
209         goto retry;
210     }
211     switch (*p) {
212     case 'l':
213         if (nunits == 0) {
214             pr("no units there\n");
215             goto retry;
216         }
217         land_bomb(list, target);
218         break;
219     case 'p':
220         if (nplanes == 0) {
221             pr("no planes there\n");
222             goto retry;
223         }
224         plane_bomb(list, target);
225         break;
226     case 's':
227         if (nships == 0) {
228             if (pln_caps(list) & P_A) {
229                 if (nsubs == 0) {
230                     pr("no ships there\n");
231                     goto retry;
232                 }
233             } else {
234                 pr("no ships there\n");
235                 goto retry;
236             }
237         }
238         ship_bomb(list, target);
239         break;
240     case 'c':
241         for (i = 0; i < nbomb; i++) {
242             if (!target->sct_item[bombcomm[i]])
243                 continue;
244             break;
245         }
246         if (i >= nbomb) {
247             pr("No bombable commodities in %s\n",
248                xyas(target->sct_x, target->sct_y, player->cnum));
249             goto retry;
250         }
251         comm_bomb(list, target);
252         break;
253     case 'e':
254         eff_bomb(list, target);
255         break;
256     case 'q':
257         pr("Aborting mission.\n");
258         return;
259     default:
260         pr("Bad target type.\n");
261         goto retry;
262     }
263 }
264
265 static void
266 eff_bomb(struct emp_qelem *list, struct sctstr *target)
267 {
268     struct plist *plp;
269     struct emp_qelem *qp, *next;
270     struct sctstr sect;
271     int oldeff, dam = 0;
272
273     for (qp = list->q_forw; qp != list; qp = next) {
274         next = qp->q_forw;
275         plp = (struct plist *)qp;
276         if (changed_plane_aborts(plp))
277             continue;
278         dam += pln_damage(&plp->plane, 'p', "");
279     }
280     getsect(target->sct_x, target->sct_y, &sect);
281     target = &sect;
282     oldeff = target->sct_effic;
283     target->sct_effic = effdamage(target->sct_effic, dam);
284     target->sct_avail = effdamage(target->sct_avail, dam);
285     target->sct_road = effdamage(target->sct_road, dam);
286     target->sct_rail = effdamage(target->sct_rail, dam);
287     target->sct_defense = effdamage(target->sct_defense, dam);
288     pr("did %d%% damage to efficiency in %s\n",
289        oldeff - target->sct_effic,
290        xyas(target->sct_x, target->sct_y, player->cnum));
291     if (target->sct_own != player->cnum)
292         mpr(target->sct_own,
293             "%s bombing raid did %d%% damage in %s\n",
294             cname(player->cnum), oldeff - target->sct_effic,
295             xyas(target->sct_x, target->sct_y, target->sct_own));
296     bridge_damaged(target);
297     putsect(&sect);
298     collateral_damage(target->sct_x, target->sct_y, dam);
299 }
300
301 static void
302 comm_bomb(struct emp_qelem *list, struct sctstr *target)
303 {
304     struct plist *plp;
305     double b;
306     int i;
307     int amt, before;
308     struct ichrstr *ip;
309     struct emp_qelem *qp, *next;
310     struct sctstr sect;
311     int dam = 0;
312
313     for (i = 0; i < nbomb; i++) {
314         if (target->sct_item[bombcomm[i]] == 0)
315             continue;
316         if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
317             continue;
318         ip = &ichr[bombcomm[i]];
319         pr("some %s\n", ip->i_name);
320     }
321     for (;;) {
322         ip = whatitem(NULL, "commodity to bomb? ");
323         if (player->aborted)
324             return;
325         if (!ip)
326             continue;
327
328         for (i = 0; i < nbomb; i++) {
329             if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
330                 continue;
331             if (&ichr[bombcomm[i]] == ip)
332                 break;
333         }
334         if (i == nbomb) {
335             pr("You can't bomb %s!\n", ip->i_name);
336             for (i = 0; i < nbomb; i++) {
337                 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
338                     continue;
339                 pr("%s%s", i == 0 ? "Bombable: " : ", ",
340                    ichr[bombcomm[i]].i_name);
341             }
342             pr("\n");
343         } else
344             break;
345     }
346     for (qp = list->q_forw; qp != list; qp = next) {
347         next = qp->q_forw;
348         plp = (struct plist *)qp;
349         if (changed_plane_aborts(plp))
350             continue;
351         dam += pln_damage(&plp->plane, 'p', "");
352     }
353     getsect(target->sct_x, target->sct_y, &sect);
354     target = &sect;
355     before = target->sct_item[ip->i_uid];
356     target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
357     if (before > 0.0)
358         b = 100.0 * (1.0 - (double)amt / (double)before);
359     else
360         b = 0.0;
361     pr("did %.2f%% damage to %s in %s\n",
362        b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
363     nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
364     if (target->sct_own != player->cnum)
365         mpr(target->sct_own,
366             "%s precision bombing raid did %.2f%% damage to %s in %s\n",
367             cname(player->cnum), b, ip->i_name,
368             xyas(target->sct_x, target->sct_y, target->sct_own));
369     putsect(&sect);
370     collateral_damage(target->sct_x, target->sct_y, dam);
371 }
372
373 static void
374 ship_bomb(struct emp_qelem *list, struct sctstr *target)
375 {
376     struct plist *plp;
377     struct mchrstr *mcp;
378     int dam;
379     char *q;
380     int n;
381     struct emp_qelem *qp, *next;
382     int shipno;
383     struct shpstr ship;
384     int nships = 0;
385     struct shiplist *head = NULL;
386     char buf[1024];
387     char prompt[128];
388     int hitchance;
389     int flak;
390     int gun;
391
392     for (qp = list->q_forw; qp != list; qp = next) {
393         next = qp->q_forw;
394         free_shiplist(&head);
395         plp = (struct plist *)qp;
396         if (changed_plane_aborts(plp))
397             continue;
398         if (plp->pcp->pl_flags & P_A)
399             nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
400                                    &plp->plane, &head);
401         else
402             nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
403         if (nships == 0) {
404             pr("%s could not find any ships!\n", prplane(&plp->plane));
405             continue;
406         }
407         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
408                       prplane(&plp->plane), plp->load);
409         shipno = -1;
410         while (shipno < 0) {
411             if (!(q = getstring(prompt, buf)))
412                 goto out;
413             if (*q == 0)
414                 continue;
415             if (*q == '~')
416                 break;
417             if (*q == '?') {
418                 if (plp->pcp->pl_flags & P_A)
419                     print_shiplist(head);
420                 else
421                     shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
422                 continue;
423             }
424             n = atoi(q);
425             if (n < 0)
426                 continue;
427             if ((!(plp->pcp->pl_flags & P_A) || on_shiplist(n, head)) &&
428                 getship(n, &ship) && ship.shp_own &&
429                 ship.shp_x == target->sct_x && ship.shp_y == target->sct_y)
430                 shipno = n;
431             else
432                 pr("Ship #%d not spotted\n", n);
433         }
434         if (shipno < 0)
435             continue;
436         if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
437             continue;
438         if (changed_plane_aborts(plp))
439             continue;
440
441         gun = shp_usable_guns(&ship);
442         mcp = &mchr[(int)ship.shp_type];
443         if (gun > 0 && !(mcp->m_flags & M_SUB)) {
444             flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
445             mpr(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
446                 flak, prship(&ship));
447             if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
448                 continue;
449         }
450
451         if (nuk_on_plane(&plp->plane) >= 0)
452             hitchance = 100;
453         else {
454             hitchance = pln_hitchance(&plp->plane,
455                                       shp_hardtarget(&ship), EF_SHIP);
456             pr("%d%% hitchance...", hitchance);
457         }
458         if (pct_chance(hitchance)) {
459             /* pinbombing is more accurate than normal bombing */
460             dam = 2 * pln_damage(&plp->plane, 'p', "");
461         } else {
462             pr("splash\n");
463             /* Bombs that miss have to land somewhere! */
464             dam = pln_damage(&plp->plane, 'p', 0);
465             collateral_damage(target->sct_x, target->sct_y, dam);
466             continue;
467         }
468         if (mcp->m_flags & M_SUB)
469             nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
470         else
471             nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
472         if (ship.shp_own != player->cnum) {
473             mpr(ship.shp_own, "%s bombs did %d damage to %s at %s\n",
474                 cname(player->cnum), dam,
475                 prship(&ship),
476                 xyas(target->sct_x, target->sct_y, ship.shp_own));
477         }
478         shipdamage(&ship, dam);
479         if (ship.shp_effic < SHIP_MINEFF)
480             pr("%s at %s sunk!\n",
481                prship(&ship),
482                xyas(target->sct_x, target->sct_y, player->cnum));
483         if (dam && (ship.shp_rflags & RET_INJURED))
484             retreat_ship(&ship, ship.shp_own, 'i');
485         else if (ship.shp_rflags & RET_BOMBED)
486             retreat_ship(&ship, ship.shp_own, 'b');
487         putship(ship.shp_uid, &ship);
488         collateral_damage(target->sct_x, target->sct_y, dam / 2);
489     }
490 out:
491     free_shiplist(&head);
492 }
493
494 static void
495 plane_bomb(struct emp_qelem *list, struct sctstr *target)
496 {
497     int dam;
498     char *q;
499     int n;
500     natid own;
501     struct plnstr plane;
502     struct emp_qelem *qp, *next;
503     int planeno;
504     struct plist *plp;
505     char prompt[128];
506     char buf[1024];
507     int hitchance;
508     int nplanes;
509
510     for (qp = list->q_forw; qp != list; qp = next) {
511         next = qp->q_forw;
512         plp = (struct plist *)qp;
513         if (changed_plane_aborts(plp))
514             continue;
515         nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
516         if (nplanes == 0) {
517             pr("%s could not find any planes!\n", prplane(&plp->plane));
518             continue;
519         }
520         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
521                       prplane(&plp->plane), plp->load);
522         planeno = -1;
523         while (planeno < 0) {
524             if (!(q = getstring(prompt, buf)))
525                 return;
526             if (*q == 0)
527                 continue;
528             if (*q == '~')
529                 break;
530             if (*q == '?') {
531                 planesatxy(target->sct_x, target->sct_y, 0, 0);
532                 continue;
533             }
534             n = atoi(q);
535             if (n < 0)
536                 continue;
537             if (getplane(n, &plane) && plane.pln_own &&
538                 plane.pln_x == target->sct_x &&
539                 plane.pln_y == target->sct_y &&
540                 plane.pln_ship < 0 && plane.pln_land < 0 &&
541                 !(plane.pln_flags & PLN_LAUNCHED))
542                 planeno = n;
543             else
544                 pr("Plane #%d not spotted\n", n);
545         }
546         if (planeno < 0)
547             continue;
548         if (changed_plane_aborts(plp))
549             continue;
550         if (nuk_on_plane(&plp->plane) >= 0)
551             hitchance = 100;
552         else {
553             hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
554             pr("%d%% hitchance...", hitchance);
555         }
556         if (pct_chance(hitchance)) {
557             /* pinbombing is more accurate than normal bombing */
558             dam = 2 * pln_damage(&plp->plane, 'p', "");
559         } else {
560             pr("thud\n");
561             /* Bombs that miss have to land somewhere! */
562             dam = pln_damage(&plp->plane, 'p', 0);
563             collateral_damage(target->sct_x, target->sct_y, dam);
564             continue;
565         }
566         if (dam > 100)
567             dam = 100;
568         own = plane.pln_own;
569         if (dam > plane.pln_effic)
570             plane.pln_effic = 0;
571         else
572             plane.pln_effic -= dam;
573         plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
574         mpr(own, "%s bombs did %d%% damage to %s at %s\n",
575                cname(player->cnum), dam, prplane(&plane),
576                xyas(target->sct_x, target->sct_y, own));
577         nreport(player->cnum, N_DOWN_PLANE, own, 1);
578         putplane(plane.pln_uid, &plane);
579         collateral_damage(target->sct_x, target->sct_y, dam);
580     }
581 }
582
583 static void
584 land_bomb(struct emp_qelem *list, struct sctstr *target)
585 {
586     int dam;
587     char *q;
588     int n;
589     natid own;
590     char prompt[128];
591     char buf[1024];
592     struct lndstr land;
593     struct emp_qelem *qp, *next;
594     int unitno;
595     int aaf, flak, hitchance;
596     struct plist *plp;
597     int nunits;
598
599     for (qp = list->q_forw; qp != list; qp = next) {
600         next = qp->q_forw;
601         plp = (struct plist *)qp;
602         if (changed_plane_aborts(plp))
603             continue;
604         nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0, 0);
605         if (nunits == 0) {
606             pr("%s could not find any units!\n", prplane(&plp->plane));
607             continue;
608         }
609         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
610                       prplane(&plp->plane), plp->load);
611         unitno = -1;
612         while (unitno < 0) {
613             if (!(q = getstring(prompt, buf)))
614                 return;
615             if (*q == 0)
616                 continue;
617             if (*q == '~')
618                 break;
619             if (*q == '?') {
620                 unitsatxy(target->sct_x, target->sct_y, 0, 0, 0);
621                 continue;
622             }
623             n = atoi(q);
624             if (n < 0)
625                 continue;
626             if (getland(n, &land) && land.lnd_own &&
627                 land.lnd_ship < 0 && land.lnd_land < 0 &&
628                 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
629                 unitno = n;
630             else
631                 pr("Unit #%d not spotted\n", n);
632         }
633         if (unitno < 0)
634             continue;
635         if (changed_plane_aborts(plp))
636             continue;
637
638         aaf = lnd_aaf(&land);
639         if (aaf) {
640             flak = roundavg(techfact(land.lnd_tech,
641                                      aaf * 3.0 * land.lnd_effic / 100.0));
642             mpr(land.lnd_own,
643                 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
644                 prland(&land), aaf);
645             if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
646                 continue;
647         }
648
649         if (nuk_on_plane(&plp->plane) >= 0)
650             hitchance = 100;
651         else {
652             hitchance = pln_hitchance(&plp->plane,
653                                       lnd_hardtarget(&land), EF_LAND);
654             pr("%d%% hitchance...", hitchance);
655         }
656         if (pct_chance(hitchance)) {
657             dam = 2 * pln_damage(&plp->plane, 'p', "");
658         } else {
659             pr("thud\n");
660             /* Bombs that miss have to land somewhere! */
661             dam = pln_damage(&plp->plane, 'p', 0);
662             collateral_damage(target->sct_x, target->sct_y, dam);
663             continue;
664         }
665         if (dam > 100)
666             dam = 100;
667         own = land.lnd_own;
668         if (own != player->cnum)
669             mpr(own, "%s bombs did %d%% damage to %s at %s\n",
670                 cname(player->cnum), dam, prland(&land),
671                 xyas(target->sct_x, target->sct_y, own));
672         landdamage(&land, dam);
673         if (dam && (land.lnd_rflags & RET_INJURED))
674             retreat_land(&land, own, 'i');
675         else if (land.lnd_rflags & RET_BOMBED)
676             retreat_land(&land, own, 'b');
677         nreport(player->cnum, N_UNIT_BOMB, own, 1);
678         putland(land.lnd_uid, &land);
679         collateral_damage(target->sct_x, target->sct_y, dam);
680     }
681 }
682
683 static void
684 strat_bomb(struct emp_qelem *list, struct sctstr *target)
685 {
686     struct plist *plp;
687     int dam = 0;
688     struct emp_qelem *qp;
689     struct sctstr sect;
690     struct nukstr nuke;
691
692     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
693         plp = (struct plist *)qp;
694         if (getnuke(nuk_on_plane(&plp->plane), &nuke))
695             detonate(&nuke, target->sct_x, target->sct_y,
696                      plp->plane.pln_flags & PLN_AIRBURST);
697         else
698             dam += pln_damage(&plp->plane, 's', "");
699     }
700     if (dam <= 0)
701         return;
702     getsect(target->sct_x, target->sct_y, &sect);
703     target = &sect;
704     if (target->sct_own != player->cnum)
705         mpr(target->sct_own, "%s bombing raid did %d damage in %s\n",
706             cname(player->cnum), PERCENT_DAMAGE(dam),
707             xyas(target->sct_x, target->sct_y, target->sct_own));
708
709     sectdamage(target, dam);
710
711     pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
712        xyas(target->sct_x, target->sct_y, player->cnum));
713     putsect(&sect);
714 }
715
716 static int
717 changed_plane_aborts(struct plist *plp)
718 {
719     if (check_plane_ok(&plp->plane))
720         return 0;
721     getplane(plp->plane.pln_uid, &plp->plane);
722     pln_put1(plp);
723     return 1;
724 }
725
726 static int
727 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
728                     int flak)
729 {
730     int disp;
731     char dmess[14];
732     int dam;
733
734     dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
735     if (dam <= 0)
736         return 0;
737     disp = ac_damage_plane(pp, from, dam, 1, dmess);
738     mpr(pp->pln_own, "    Flak! %s takes %d%s%s.\n",
739         prplane(pp), dam, *dmess ? " --" : "", dmess);
740
741     putplane(pp->pln_uid, pp);
742     return disp > 0;
743 }