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