]> git.pond.sub.org Git - empserver/blob - src/lib/commands/bomb.c
Make bomb require capability bomber or tactical
[empserver] / src / lib / commands / bomb.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2009, 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,
130             2, P_B | P_T, P_M | P_O);
131     pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
132             2, 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     int nukedam;
341
342     for (qp = list->q_forw; qp != list; qp = next) {
343         next = qp->q_forw;
344         plp = (struct plist *)qp;
345         if (changed_plane_aborts(plp))
346             continue;
347         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
348             continue;
349         if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
350             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
351                               'p', &nukedam, 1);
352     }
353     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
354         return;
355     getsect(target->sct_x, target->sct_y, &sect);
356     target = &sect;
357     oldeff = target->sct_effic;
358     target->sct_effic = effdamage(target->sct_effic, dam);
359     target->sct_avail = effdamage(target->sct_avail, dam);
360     target->sct_road = effdamage(target->sct_road, dam);
361     target->sct_rail = effdamage(target->sct_rail, dam);
362     target->sct_defense = effdamage(target->sct_defense, dam);
363     pr("did %d%% damage to efficiency in %s\n",
364        oldeff - target->sct_effic,
365        xyas(target->sct_x, target->sct_y, player->cnum));
366     if (target->sct_own)
367         wu(0, target->sct_own,
368            "%s bombing raid did %d%% damage in %s\n",
369            cname(player->cnum), oldeff - target->sct_effic,
370            xyas(target->sct_x, target->sct_y, target->sct_own));
371     bridge_damaged(target);
372     putsect(&sect);
373     collateral_damage(target->sct_x, target->sct_y, dam);
374 }
375
376 static void
377 comm_bomb(struct emp_qelem *list, struct sctstr *target)
378 {
379     struct plist *plp;
380     double b;
381     int i;
382     int amt, before;
383     struct ichrstr *ip;
384     struct emp_qelem *qp, *next;
385     struct sctstr sect;
386     int dam = 0;
387     int nukedam;
388
389     for (i = 0; i < nbomb; i++) {
390         if (target->sct_item[bombcomm[i]] == 0)
391             continue;
392         if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
393             continue;
394         ip = &ichr[bombcomm[i]];
395         pr("some %s\n", ip->i_name);
396     }
397     for (;;) {
398         ip = whatitem(NULL, "commodity to bomb? ");
399         if (player->aborted)
400             return;
401         if (!ip)
402             continue;
403
404         for (i = 0; i < nbomb; i++) {
405             if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
406                 continue;
407             if (&ichr[bombcomm[i]] == ip)
408                 break;
409         }
410         if (i == nbomb) {
411             pr("You can't bomb %s!\n", ip->i_name);
412             for (i = 0; i < nbomb; i++) {
413                 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
414                     continue;
415                 pr("%s%s", i == 0 ? "Bombable: " : ", ",
416                    ichr[bombcomm[i]].i_name);
417             }
418             pr("\n");
419         } else
420             break;
421     }
422     for (qp = list->q_forw; qp != list; qp = next) {
423         next = qp->q_forw;
424         plp = (struct plist *)qp;
425         if (changed_plane_aborts(plp))
426             continue;
427         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
428             continue;
429         if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
430             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
431                               'p', &nukedam, 1);
432     }
433     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
434         return;
435     getsect(target->sct_x, target->sct_y, &sect);
436     target = &sect;
437     before = target->sct_item[ip->i_uid];
438     target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
439     if (before > 0.0)
440         b = 100.0 * (1.0 - (double)amt / (double)before);
441     else
442         b = 0.0;
443     pr("did %.2f%% damage to %s in %s\n",
444        b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
445     nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
446     if (target->sct_own != 0)
447         wu(0, target->sct_own,
448            "%s precision bombing raid did %.2f%% damage to %s in %s\n",
449            cname(player->cnum), b, ip->i_name,
450            xyas(target->sct_x, target->sct_y, target->sct_own));
451     putsect(&sect);
452     collateral_damage(target->sct_x, target->sct_y, dam);
453 }
454
455 static void
456 ship_bomb(struct emp_qelem *list, struct sctstr *target)
457 {
458     struct plist *plp;
459     struct mchrstr *mcp;
460     int dam;
461     char *q;
462     int n;
463     struct emp_qelem *qp, *next;
464     int shipno;
465     struct shpstr ship;
466     int nships = 0;
467     struct shiplist *head = NULL;
468     char buf[1024];
469     char prompt[128];
470     int hitchance;
471     int nukedam;
472     int flak;
473     int gun;
474
475     for (qp = list->q_forw; qp != list; qp = next) {
476         next = qp->q_forw;
477         free_shiplist(&head);
478         plp = (struct plist *)qp;
479         if (changed_plane_aborts(plp))
480             continue;
481         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
482             continue;
483         if (plp->pcp->pl_flags & P_A)
484             nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
485                                    &plp->plane, &head);
486         else
487             nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
488         if (nships == 0) {
489             pr("%s could not find any ships!\n", prplane(&plp->plane));
490             continue;
491         }
492         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
493                       prplane(&plp->plane), plp->bombs);
494         shipno = -1;
495         while (shipno < 0) {
496             if (!(q = getstring(prompt, buf)))
497                 goto out;
498             if (*q == 0)
499                 continue;
500             if (*q == '~')
501                 break;
502             if (*q == '?') {
503                 if (plp->pcp->pl_flags & P_A)
504                     print_shiplist(head);
505                 else
506                     shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
507                 continue;
508             }
509             n = atoi(q);
510             if (n < 0)
511                 continue;
512             if ((!(plp->pcp->pl_flags & P_A) || on_shiplist(n, head)) &&
513                 getship(n, &ship) && ship.shp_own &&
514                 ship.shp_x == target->sct_x && ship.shp_y == target->sct_y)
515                 shipno = n;
516             else
517                 pr("Ship #%d not spotted\n", n);
518         }
519         if (shipno < 0)
520             continue;
521         if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
522             continue;
523         if (changed_plane_aborts(plp))
524             continue;
525
526         gun = shp_usable_guns(&ship);
527         mcp = &mchr[(int)ship.shp_type];
528         if (gun > 0 && !(mcp->m_flags & M_SUB)) {
529             flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
530             PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
531                flak, prship(&ship));
532             if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
533                 continue;
534         }
535
536         dam = 0;
537         if (nuk_on_plane(&plp->plane) >= 0)
538             hitchance = 100;
539         else {
540             hitchance = pln_hitchance(&plp->plane,
541                                       shp_hardtarget(&ship), EF_SHIP);
542             pr("%d%% hitchance...", hitchance);
543         }
544         if (roll(100) <= hitchance) {
545             /* pinbombing is more accurate than normal bombing */
546             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
547                                  'p', &nukedam, 1);
548         } else {
549             pr("splash\n");
550             /* Bombs that miss have to land somewhere! */
551             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
552                              'p', &nukedam, 0);
553             collateral_damage(target->sct_x, target->sct_y, dam);
554             dam = 0;
555         }
556         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
557             continue;
558         if (mcp->m_flags & M_SUB)
559             nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
560         else
561             nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
562         if (ship.shp_own) {
563             wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
564                cname(player->cnum), dam,
565                prship(&ship),
566                xyas(target->sct_x, target->sct_y, ship.shp_own));
567         }
568         pr("\n");
569         check_retreat_and_do_shipdamage(&ship, dam);
570         if (ship.shp_rflags & RET_BOMBED)
571             if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
572                 retreat_ship(&ship, 'b');
573         putship(ship.shp_uid, &ship);
574         getship(ship.shp_uid, &ship);
575         if (!ship.shp_own) {
576             pr("%s at %s sunk!\n",
577                prship(&ship),
578                xyas(target->sct_x, target->sct_y, player->cnum));
579         }
580         collateral_damage(target->sct_x, target->sct_y, dam / 2);
581     }
582 out:
583     free_shiplist(&head);
584 }
585
586 static void
587 plane_bomb(struct emp_qelem *list, struct sctstr *target)
588 {
589     int dam;
590     char *q;
591     int n;
592     natid own;
593     struct plnstr plane;
594     struct emp_qelem *qp, *next;
595     int planeno;
596     struct plist *plp;
597     char prompt[128];
598     char buf[1024];
599     int hitchance;
600     int nukedam;
601     int nplanes;
602
603     for (qp = list->q_forw; qp != list; qp = next) {
604         next = qp->q_forw;
605         plp = (struct plist *)qp;
606         if (changed_plane_aborts(plp))
607             continue;
608         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
609             continue;
610         nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
611         if (nplanes == 0) {
612             pr("%s could not find any planes!\n", prplane(&plp->plane));
613             continue;
614         }
615         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
616                       prplane(&plp->plane), plp->bombs);
617         planeno = -1;
618         while (planeno < 0) {
619             if (!(q = getstring(prompt, buf)))
620                 return;
621             if (*q == 0)
622                 continue;
623             if (*q == '~')
624                 break;
625             if (*q == '?') {
626                 planesatxy(target->sct_x, target->sct_y, 0, 0);
627                 continue;
628             }
629             n = atoi(q);
630             if (n < 0)
631                 continue;
632             if (getplane(n, &plane) &&
633                 plane.pln_x == target->sct_x &&
634                 plane.pln_y == target->sct_y &&
635                 plane.pln_ship < 0 && plane.pln_land < 0 &&
636                 !(plane.pln_flags & PLN_LAUNCHED))
637                 planeno = n;
638             else
639                 pr("Plane #%d not spotted\n", n);
640         }
641         if (planeno < 0)
642             continue;
643         if (changed_plane_aborts(plp))
644             continue;
645         dam = 0;
646         if (nuk_on_plane(&plp->plane) >= 0)
647             hitchance = 100;
648         else {
649             hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
650             pr("%d%% hitchance...", hitchance);
651         }
652         if (roll(100) <= hitchance) {
653             /* pinbombing is more accurate than normal bombing */
654             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
655                                  'p', &nukedam, 1);
656         } else {
657             pr("thud\n");
658             /* Bombs that miss have to land somewhere! */
659             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
660                              'p', &nukedam, 0);
661             collateral_damage(target->sct_x, target->sct_y, dam);
662             dam = 0;
663         }
664         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
665             continue;
666         if (dam > 100)
667             dam = 100;
668         own = plane.pln_own;
669         if (dam > plane.pln_effic)
670             plane.pln_effic = 0;
671         else
672             plane.pln_effic -= dam;
673         plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
674         if (own == player->cnum) {
675             pr("%s reports %d%% damage\n", prplane(&plane), dam);
676         } else {
677             if (own != 0)
678                 wu(0, own,
679                    "%s pinpoint bombing raid did %d%% damage to %s\n",
680                    cname(player->cnum), dam, prplane(&plane));
681         }
682         nreport(player->cnum, N_DOWN_PLANE, own, 1);
683         if (own != 0)
684             wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
685                cname(player->cnum), dam, prplane(&plane),
686                xyas(target->sct_x, target->sct_y, own));
687         putplane(plane.pln_uid, &plane);
688         collateral_damage(target->sct_x, target->sct_y, dam);
689     }
690 }
691
692 static void
693 land_bomb(struct emp_qelem *list, struct sctstr *target)
694 {
695     int dam;
696     char *q;
697     int n;
698     natid own;
699     char prompt[128];
700     char buf[1024];
701     struct lndstr land;
702     struct emp_qelem *qp, *next;
703     int unitno;
704     int aaf, flak, hitchance;
705     struct plist *plp;
706     int nukedam;
707     int nunits;
708
709     for (qp = list->q_forw; qp != list; qp = next) {
710         next = qp->q_forw;
711         plp = (struct plist *)qp;
712         if (changed_plane_aborts(plp))
713             continue;
714         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
715             continue;
716         nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
717         if (nunits == 0) {
718             pr("%s could not find any units!\n", prplane(&plp->plane));
719             continue;
720         }
721         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
722                       prplane(&plp->plane), plp->bombs);
723         unitno = -1;
724         while (unitno < 0) {
725             if (!(q = getstring(prompt, buf)))
726                 return;
727             if (*q == 0)
728                 continue;
729             if (*q == '~')
730                 break;
731             if (*q == '?') {
732                 unitsatxy(target->sct_x, target->sct_y, 0, 0);
733                 continue;
734             }
735             n = atoi(q);
736             if (n < 0)
737                 continue;
738             if (getland(n, &land) && land.lnd_own &&
739                 land.lnd_ship < 0 && land.lnd_land < 0 &&
740                 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
741                 unitno = n;
742             else
743                 pr("Unit #%d not spotted\n", n);
744         }
745         if (unitno < 0)
746             continue;
747         if (changed_plane_aborts(plp))
748             continue;
749
750         aaf = lnd_aaf(&land);
751         if (aaf) {
752             flak = roundavg(techfact(land.lnd_tech,
753                                      aaf * 3.0 * land.lnd_effic / 100.0));
754             PR(land.lnd_own,
755                "Flak! Firing flak guns from unit %s (aa rating %d)\n",
756                prland(&land), aaf);
757             if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
758                 continue;
759         }
760
761         dam = 0;
762         if (nuk_on_plane(&plp->plane) >= 0)
763             hitchance = 100;
764         else {
765             hitchance = pln_hitchance(&plp->plane,
766                                       lnd_hardtarget(&land), EF_LAND);
767             pr("%d%% hitchance...", hitchance);
768         }
769         if (roll(100) <= hitchance) {
770             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
771                                  'p', &nukedam, 1);
772         } else {
773             pr("thud\n");
774             /* Bombs that miss have to land somewhere! */
775             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
776                              'p', &nukedam, 0);
777             collateral_damage(target->sct_x, target->sct_y, dam);
778             dam = 0;
779         }
780         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
781             continue;
782         if (dam > 100)
783             dam = 100;
784         own = land.lnd_own;
785         mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
786             cname(player->cnum), dam, prland(&land));
787         check_retreat_and_do_landdamage(&land, dam);
788
789         if (land.lnd_rflags & RET_BOMBED)
790             if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
791                 retreat_land(&land, 'b');
792         nreport(player->cnum, N_UNIT_BOMB, own, 1);
793         putland(land.lnd_uid, &land);
794         collateral_damage(target->sct_x, target->sct_y, dam);
795     }
796 }
797
798 static void
799 strat_bomb(struct emp_qelem *list, struct sctstr *target)
800 {
801     struct plist *plp;
802     int dam = 0;
803     struct emp_qelem *qp;
804     struct sctstr sect;
805     int nukedam;
806
807     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
808         plp = (struct plist *)qp;
809         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
810             continue;
811         if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
812             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
813                               's', &nukedam, 1);
814     }
815     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
816         return;
817     getsect(target->sct_x, target->sct_y, &sect);
818     target = &sect;
819     if (target->sct_own)
820         wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
821            cname(player->cnum), PERCENT_DAMAGE(dam),
822            xyas(target->sct_x, target->sct_y, target->sct_own));
823
824     sectdamage(target, dam);
825
826     pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
827        xyas(target->sct_x, target->sct_y, player->cnum));
828     putsect(&sect);
829 }
830
831 static int
832 changed_plane_aborts(struct plist *plp)
833 {
834     if (check_plane_ok(&plp->plane))
835         return 0;
836     getplane(plp->plane.pln_uid, &plp->plane);
837     pln_put1(plp);
838     return 1;
839 }
840
841 static int
842 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
843                     int flak)
844 {
845     int disp;
846     char dmess[255];
847     int eff;
848     natid plane_owner;
849     int dam;
850
851     dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
852     disp = 0;
853     plane_owner = pp->pln_own;
854     eff = pp->pln_effic;
855     if (dam <= 0)
856         return 0;
857     memset(dmess, 0, sizeof(dmess));
858     eff -= dam;
859     if (eff < 0)
860         eff = 0;
861     if (eff < PLANE_MINEFF) {
862         sprintf(dmess, " -- shot down");
863         disp = 1;
864     } else if (chance((100 - eff) / 100.0)) {
865         sprintf(dmess, " -- aborted with %d%% damage", 100 - eff);
866         disp = 2;
867     }
868     PR(plane_owner, "    Flak! %s %s takes %d%s.\n",
869        cname(pp->pln_own), prplane(pp), dam, dmess);
870
871     pp->pln_effic = eff;
872     if (disp == 1) {
873         if (from != 0)
874             nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
875     }
876     putplane(pp->pln_uid, pp);
877
878     if (disp > 0)
879         return 1;
880     return 0;
881 }