]> git.pond.sub.org Git - empserver/blob - src/lib/commands/bomb.c
Fix pin bomb not to report subs when there are none
[empserver] / src / lib / commands / bomb.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2008, 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  */
35
36 #include <config.h>
37
38 #include <ctype.h>
39 #include "commands.h"
40 #include "damage.h"
41 #include "item.h"
42 #include "land.h"
43 #include "news.h"
44 #include "optlist.h"
45 #include "path.h"
46 #include "plane.h"
47 #include "retreat.h"
48 #include "ship.h"
49
50 static void pin_bomb(struct emp_qelem *list, struct sctstr *target);
51 static void strat_bomb(struct emp_qelem *list, struct sctstr *target);
52 static void comm_bomb(struct emp_qelem *list, struct sctstr *target);
53 static void eff_bomb(struct emp_qelem *list, struct sctstr *target);
54 static int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp,
55                                natid from, int flak);
56 static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
57 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
58 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
59
60 static i_type bombcomm[] = {
61     I_CIVIL,
62     I_MILIT,
63     I_SHELL,
64     I_GUN,
65     I_PETROL,
66     I_IRON,
67     I_DUST,
68     I_BAR,
69     I_FOOD,
70     I_OIL,
71     I_LCM,
72     I_HCM,
73     I_UW,
74     I_RAD
75 };
76 static int nbomb = sizeof(bombcomm) / sizeof(*bombcomm);
77
78 int
79 bomb(void)
80 {
81     char *p;
82     int mission_flags;
83     coord tx, ty;
84     coord ax, ay;
85     int ap_to_target;
86     struct ichrstr *ip;
87     char flightpath[MAX_PATH_LEN];
88     struct nstr_item ni_bomb;
89     struct nstr_item ni_esc;
90     struct sctstr target;
91     struct emp_qelem bomb_list;
92     struct emp_qelem esc_list;
93     int wantflags;
94     struct sctstr ap_sect;
95     char mission;
96     int rel;
97     struct natstr *natp;
98     char buf[1024];
99
100     wantflags = 0;
101     if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
102         return RET_SYN;
103     if (!snxtitem(&ni_esc, EF_PLANE,
104                   getstarg(player->argp[2], "escort(s)? ", buf)))
105         pr("No escorts...\n");
106     p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
107     if (!p)
108         return RET_SYN;
109     mission = *p;
110     if (strchr("ps", mission) == 0)
111         return RET_SYN;
112     if (!get_assembly_point(player->argp[4], &ap_sect, buf))
113         return RET_SYN;
114     ax = ap_sect.sct_x;
115     ay = ap_sect.sct_y;
116     if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING) == 0
117         || *flightpath == 0)
118         return RET_SYN;
119     tx = ax;
120     ty = ay;
121     (void)pathtoxy(flightpath, &tx, &ty, fcost);
122     pr("target sector is %s\n", xyas(tx, ty, player->cnum));
123     getsect(tx, ty, &target);
124     ip = 0;
125     ap_to_target = strlen(flightpath);
126     if (flightpath[ap_to_target - 1] == 'h')
127         ap_to_target--;
128     pr("range to target is %d\n", ap_to_target);
129     /*
130      * select planes within range
131      */
132     mission_flags = 0;
133     pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
134             2, wantflags, P_M | P_O);
135     pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
136             2, wantflags | P_F | P_ESC, P_M | P_O);
137     /*
138      * now arm and equip the bombers, transports, whatever.
139      */
140     mission_flags |= P_X;       /* stealth (shhh) */
141     mission_flags |= P_H;       /* gets turned off if not all choppers */
142     mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
143                             ip, 0, mission_flags);
144     if (QEMPTY(&bomb_list)) {
145         pr("No planes could be equipped for the mission.\n");
146         return RET_FAIL;
147     }
148     mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
149                             ip, P_F | P_ESC, mission_flags);
150     ac_encounter(&bomb_list, &esc_list, ax, ay,
151                  flightpath, mission_flags, 0);
152     if (QEMPTY(&bomb_list)) {
153         pr("No planes got through fighter defenses\n");
154     } else if (target.sct_type == SCT_SANCT) {
155         pr("You can't bomb that sector!\n");
156     } else {
157         switch (mission) {
158         case 'p':
159             pin_bomb(&bomb_list, &target);
160             break;
161         case 's':
162             if (opt_SLOW_WAR) {
163                 natp = getnatp(player->cnum);
164                 if (target.sct_own) {
165                     rel = getrel(natp, target.sct_own);
166                     if ((rel != AT_WAR) && (player->cnum != target.sct_own)
167                         && (target.sct_own) &&
168                         (target.sct_oldown != player->cnum)) {
169                         pr("You're not at war with them!\n");
170                         pln_put(&bomb_list);
171                         pln_put(&esc_list);
172                         return RET_FAIL;
173                     }
174                 }
175             }
176             nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
177             strat_bomb(&bomb_list, &target);
178             break;
179         default:
180             CANT_REACH();
181         }
182     }
183     pln_put(&bomb_list);
184     pln_put(&esc_list);
185     return RET_OK;
186 }
187
188 static void
189 pin_bomb(struct emp_qelem *list, struct sctstr *target)
190 {
191     struct dchrstr *dcp;
192     int nplanes;
193     int nships;
194     int type;
195     int bad;
196     char *p;
197     struct plist *plp;
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     plp = (struct plist *)list->q_forw;
212     nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
213     if (plp->pcp->pl_flags & P_A) {
214         nsubs = shipsatxy(target->sct_x, target->sct_y, M_SUB, 0, 1);
215         if (nsubs > 0)
216             pr("Some subs are present in the sector.\n");
217     }
218     nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
219     nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
220   retry:
221     p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
222                   buf);
223     if (p == 0 || *p == 0) {
224         if (player->aborted)
225             return;
226         bad++;
227         if (bad > 2)
228             return;
229         goto retry;
230     }
231     switch (*p) {
232     case 'l':
233         if (opt_SLOW_WAR) {
234             natp = getnatp(player->cnum);
235             if (target->sct_own) {
236                 rel = getrel(natp, target->sct_own);
237                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
238                     && (target->sct_own) &&
239                     (target->sct_oldown != player->cnum)) {
240                     pr("You're not at war with them!\n");
241                     goto retry;
242                 }
243             }
244         }
245         if (nunits == 0) {
246             pr("no units there\n");
247             goto retry;
248         }
249         land_bomb(list, target);
250         break;
251     case 'p':
252         if (opt_SLOW_WAR) {
253             natp = getnatp(player->cnum);
254             if (target->sct_own) {
255                 rel = getrel(natp, target->sct_own);
256                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
257                     && (target->sct_own) &&
258                     (target->sct_oldown != player->cnum)) {
259                     pr("You're not at war with them!\n");
260                     goto retry;
261                 }
262             }
263         }
264         if (nplanes == 0) {
265             pr("no planes there\n");
266             goto retry;
267         }
268         plane_bomb(list, target);
269         break;
270     case 's':
271         if (nships == 0) {
272             if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
273                 if (nsubs == 0) {
274                     pr("no ships there\n");
275                     goto retry;
276                 }
277             } else {
278                 pr("no ships there\n");
279                 goto retry;
280             }
281         }
282         ship_bomb(list, target);
283         break;
284     case 'c':
285         if (opt_SLOW_WAR) {
286             natp = getnatp(player->cnum);
287             if (target->sct_own) {
288                 rel = getrel(natp, target->sct_own);
289                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
290                     && (target->sct_own) &&
291                     (target->sct_oldown != player->cnum)) {
292                     pr("You're not at war with them!\n");
293                     goto retry;
294                 }
295             }
296         }
297
298         for (i = 0; i < nbomb; i++) {
299             if (!target->sct_item[bombcomm[i]])
300                 continue;
301             break;
302         }
303         if (i >= nbomb) {
304             pr("No bombable commodities in %s\n",
305                xyas(target->sct_x, target->sct_y, player->cnum));
306             goto retry;
307         }
308         comm_bomb(list, target);
309         break;
310     case 'e':
311         if (opt_SLOW_WAR) {
312             natp = getnatp(player->cnum);
313             if (target->sct_own) {
314                 rel = getrel(natp, target->sct_own);
315                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
316                     && (target->sct_own) &&
317                     (target->sct_oldown != player->cnum)) {
318                     pr("You're not at war with them!\n");
319                     goto retry;
320                 }
321             }
322         }
323         eff_bomb(list, target);
324         break;
325     case 'q':
326         pr("Aborting mission.\n");
327         return;
328     default:
329         pr("Bad target type.\n");
330         goto retry;
331     }
332 }
333
334 static void
335 eff_bomb(struct emp_qelem *list, struct sctstr *target)
336 {
337     struct plist *plp;
338     struct emp_qelem *qp;
339     struct sctstr sect;
340     int oldeff, dam = 0;
341     int nukedam;
342
343     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
344         plp = (struct plist *)qp;
345         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
346             continue;
347         if (plp->bombs || plp->plane.pln_nuketype != -1)
348             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
349                               'p', &nukedam, 1);
350     }
351     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
352         return;
353     getsect(target->sct_x, target->sct_y, &sect);
354     target = &sect;
355     oldeff = target->sct_effic;
356     target->sct_effic = effdamage(target->sct_effic, dam);
357     target->sct_avail = effdamage(target->sct_avail, dam);
358     target->sct_road = effdamage(target->sct_road, dam);
359     target->sct_rail = effdamage(target->sct_rail, dam);
360     target->sct_defense = effdamage(target->sct_defense, dam);
361     pr("did %d%% damage to efficiency in %s\n",
362        oldeff - target->sct_effic,
363        xyas(target->sct_x, target->sct_y, player->cnum));
364     if (target->sct_own)
365         wu(0, target->sct_own,
366            "%s bombing raid did %d%% damage in %s\n",
367            cname(player->cnum), oldeff - target->sct_effic,
368            xyas(target->sct_x, target->sct_y, target->sct_own));
369     bridge_damaged(target);
370     putsect(&sect);
371     collateral_damage(target->sct_x, target->sct_y, dam);
372 }
373
374 static void
375 comm_bomb(struct emp_qelem *list, struct sctstr *target)
376 {
377     struct plist *plp;
378     double b;
379     int i;
380     int amt, before;
381     struct ichrstr *ip;
382     struct emp_qelem *qp;
383     struct sctstr sect;
384     int dam = 0;
385     int nukedam;
386
387     for (i = 0; i < nbomb; i++) {
388         if (target->sct_item[bombcomm[i]] == 0)
389             continue;
390         if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
391             continue;
392         ip = &ichr[bombcomm[i]];
393         pr("some %s\n", ip->i_name);
394     }
395     for (;;) {
396         ip = whatitem(NULL, "commodity to bomb? ");
397         if (player->aborted)
398             return;
399         if (!ip)
400             continue;
401
402         for (i = 0; i < nbomb; i++) {
403             if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
404                 continue;
405             if (&ichr[bombcomm[i]] == ip)
406                 break;
407         }
408         if (i == nbomb) {
409             pr("You can't bomb %s!\n", ip->i_name);
410             for (i = 0; i < nbomb; i++) {
411                 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
412                     continue;
413                 pr("%s%s", i == 0 ? "Bombable: " : ", ",
414                    ichr[bombcomm[i]].i_name);
415             }
416             pr("\n");
417         } else
418             break;
419     }
420     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
421         plp = (struct plist *)qp;
422         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
423             continue;
424         if (plp->bombs || plp->plane.pln_nuketype != -1)
425             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
426                               'p', &nukedam, 1);
427     }
428     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
429         return;
430     getsect(target->sct_x, target->sct_y, &sect);
431     target = &sect;
432     before = target->sct_item[ip->i_uid];
433     target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
434     if (before > 0.0)
435         b = 100.0 * (1.0 - (double)amt / (double)before);
436     else
437         b = 0.0;
438     pr("did %.2f%% damage to %s in %s\n",
439        b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
440     nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
441     if (target->sct_own != 0)
442         wu(0, target->sct_own,
443            "%s precision bombing raid did %.2f%% damage to %s in %s\n",
444            cname(player->cnum), b, ip->i_name,
445            xyas(target->sct_x, target->sct_y, target->sct_own));
446     putsect(&sect);
447     collateral_damage(target->sct_x, target->sct_y, dam);
448 }
449
450 static void
451 ship_bomb(struct emp_qelem *list, struct sctstr *target)
452 {
453     struct plist *plp;
454     struct mchrstr *mcp;
455     int dam;
456     char *q;
457     int n;
458     struct emp_qelem *qp;
459     int shipno;
460     int ignore;
461     struct shpstr ship;
462     int nships = 0;
463     struct shiplist *head = NULL;
464     char buf[1024];
465     char prompt[128];
466     int hitchance;
467     int nukedam;
468     int flak;
469     int gun;
470     int shell;
471
472     for (qp = list->q_forw; qp != list && !player->aborted;
473          qp = qp->q_forw) {
474         free_shiplist(&head);
475         plp = (struct plist *)qp;
476         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
477             continue;
478         if (plp->pcp->pl_flags & P_A)
479             nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
480                                    &plp->plane, &head);
481         else
482             nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
483         if (nships == 0) {
484             pr("%s could not find any ships!\n", prplane(&plp->plane));
485             continue;
486         }
487         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
488                       prplane(&plp->plane), plp->bombs);
489         ignore = 0;
490         shipno = -1;
491         while (shipno < 0 && !player->aborted && !ignore) {
492             if ((q = getstring(prompt, buf)) == 0 || *q == 0)
493                 continue;
494             if (*q == '~') {
495                 ignore = 1;
496                 continue;
497             }
498             if (*q == '?') {
499                 if (plp->pcp->pl_flags & P_A)
500                     print_shiplist(head);
501                 else
502                     shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
503                 continue;
504             }
505             if (*q == 'd')
506                 goto next;
507             if (!isdigit(*q))
508                 continue;
509             n = atoi(q);
510             if (n < 0)
511                 continue;
512             if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
513                 continue;
514             if (getship(n, &ship) && ship.shp_x == target->sct_x &&
515                 ship.shp_y == target->sct_y)
516                 shipno = n;
517         }
518         if (shipno < 0)
519             continue;
520         if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
521             continue;
522
523         shell = 0;
524         gun = shp_usable_guns(&ship);
525         if (gun > 0) {
526             shell = ship.shp_item[I_SHELL];
527             if (shell <= 0)
528                 shell = supply_commod(ship.shp_own,
529                                       ship.shp_x, ship.shp_y, I_SHELL, 1);
530         }
531         mcp = &mchr[(int)ship.shp_type];
532         if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
533             flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
534             ship.shp_item[I_SHELL] = shell;
535             putship(ship.shp_uid, &ship);
536             PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
537                flak, prship(&ship));
538             if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
539                 continue;
540         }
541
542         dam = 0;
543         if (plp->plane.pln_nuketype != -1)
544             hitchance = 100;
545         else {
546             hitchance = pln_hitchance(&plp->plane,
547                                       shp_hardtarget(&ship), EF_SHIP);
548             pr("%d%% hitchance...", hitchance);
549         }
550         if (roll(100) <= hitchance) {
551             /* pinbombing is more accurate than normal bombing */
552             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
553                                  'p', &nukedam, 1);
554         } else {
555             pr("splash\n");
556             /* Bombs that miss have to land somewhere! */
557             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
558                              'p', &nukedam, 0);
559             collateral_damage(target->sct_x, target->sct_y, dam);
560             dam = 0;
561         }
562         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
563             continue;
564         if (mcp->m_flags & M_SUB)
565             nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
566         else
567             nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
568         if (ship.shp_own) {
569             wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
570                cname(player->cnum), dam,
571                prship(&ship),
572                xyas(target->sct_x, target->sct_y, ship.shp_own));
573         }
574         pr("\n");
575         check_retreat_and_do_shipdamage(&ship, dam);
576         if (ship.shp_rflags & RET_BOMBED)
577             if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
578                 retreat_ship(&ship, 'b');
579         putship(ship.shp_uid, &ship);
580         getship(ship.shp_uid, &ship);
581         if (!ship.shp_own) {
582             pr("%s at %s sunk!\n",
583                prship(&ship),
584                xyas(target->sct_x, target->sct_y, player->cnum));
585         }
586         collateral_damage(target->sct_x, target->sct_y, dam / 2);
587       next:
588         ;
589     }
590     free_shiplist(&head);
591 }
592
593 static void
594 plane_bomb(struct emp_qelem *list, struct sctstr *target)
595 {
596     int dam;
597     char *q;
598     int n;
599     natid own;
600     struct plnstr plane;
601     struct emp_qelem *qp;
602     int planeno;
603     int ignore;
604     struct plist *plp;
605     char prompt[128];
606     char buf[1024];
607     int hitchance;
608     int nukedam;
609     int nplanes;
610
611     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
612         plp = (struct plist *)qp;
613         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
614             continue;
615         nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
616         if (nplanes == 0) {
617             pr("%s could not find any planes!\n", prplane(&plp->plane));
618             continue;
619         }
620         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
621                       prplane(&plp->plane), plp->bombs);
622         planeno = -1;
623         ignore = 0;
624         while (planeno < 0 && !player->aborted && !ignore) {
625             if ((q = getstring(prompt, buf)) == 0 || *q == 0)
626                 continue;
627             if (*q == '~') {
628                 ignore = 1;
629                 continue;
630             }
631             if (*q == '?') {
632                 planesatxy(target->sct_x, target->sct_y, 0, 0);
633                 continue;
634             }
635             if (*q == 'd')
636                 goto next;
637             n = atoi(q);
638             if (n < 0)
639                 continue;
640             if (getplane(n, &plane) &&
641                 plane.pln_x == target->sct_x &&
642                 plane.pln_y == target->sct_y &&
643                 !(plane.pln_flags & PLN_LAUNCHED))
644                 planeno = n;
645             else
646                 pr("Plane #%d not spotted\n", n);
647         }
648         if (planeno < 0)
649             continue;
650         dam = 0;
651         if (plp->plane.pln_nuketype != -1)
652             hitchance = 100;
653         else {
654             hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
655             pr("%d%% hitchance...", hitchance);
656         }
657         if (roll(100) <= hitchance) {
658             /* pinbombing is more accurate than normal bombing */
659             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
660                                  'p', &nukedam, 1);
661         } else {
662             pr("thud\n");
663             /* Bombs that miss have to land somewhere! */
664             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
665                              'p', &nukedam, 0);
666             collateral_damage(target->sct_x, target->sct_y, dam);
667             dam = 0;
668         }
669         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
670             continue;
671         if (dam > 100)
672             dam = 100;
673         own = plane.pln_own;
674         if (dam > plane.pln_effic)
675             plane.pln_effic = 0;
676         else
677             plane.pln_effic -= dam;
678         plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
679         if (own == player->cnum) {
680             pr("%s reports %d%% damage\n", prplane(&plane), dam);
681         } else {
682             if (own != 0)
683                 wu(0, own,
684                    "%s pinpoint bombing raid did %d%% damage to %s\n",
685                    cname(player->cnum), dam, prplane(&plane));
686         }
687         nreport(player->cnum, N_DOWN_PLANE, own, 1);
688         if (own != 0)
689             wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
690                cname(player->cnum), dam, prplane(&plane),
691                xyas(target->sct_x, target->sct_y, own));
692         putplane(plane.pln_uid, &plane);
693         collateral_damage(target->sct_x, target->sct_y, dam);
694       next:
695         ;
696     }
697 }
698
699 static void
700 land_bomb(struct emp_qelem *list, struct sctstr *target)
701 {
702     int dam;
703     char *q;
704     int n;
705     natid own;
706     char prompt[128];
707     char buf[1024];
708     struct lndstr land;
709     struct emp_qelem *qp;
710     int unitno;
711     int ignore, aaf, flak, hitchance;
712     struct plist *plp;
713     int nukedam;
714     int nunits;
715
716     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
717         plp = (struct plist *)qp;
718         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
719             continue;
720         nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
721         if (nunits == 0) {
722             pr("%s could not find any units!\n", prplane(&plp->plane));
723             continue;
724         }
725         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
726                       prplane(&plp->plane), plp->bombs);
727         unitno = -1;
728         ignore = 0;
729         while (unitno < 0 && !player->aborted && !ignore) {
730             if ((q = getstring(prompt, buf)) == 0 || *q == 0)
731                 continue;
732             if (*q == '~') {
733                 ignore = 1;
734                 continue;
735             }
736             if (*q == '?') {
737                 unitsatxy(target->sct_x, target->sct_y, 0, 0);
738                 continue;
739             }
740             if (*q == 'd')
741                 goto next;
742             n = atoi(q);
743             if (n < 0)
744                 continue;
745             if (getland(n, &land) &&
746                 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
747                 unitno = n;
748             else
749                 pr("Unit #%d not spotted\n", n);
750         }
751         if (unitno < 0)
752             continue;
753
754         aaf = lnd_aaf(&land);
755         flak = (int)(techfact(land.lnd_tech, aaf) * 3.0);
756         if (flak) {
757             PR(land.lnd_own,
758                "Flak! Firing flak guns from unit %s (aa rating %d)\n",
759                prland(&land), aaf);
760             if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
761                 continue;
762         }
763
764         dam = 0;
765         if (plp->plane.pln_nuketype != -1)
766             hitchance = 100;
767         else {
768             hitchance = pln_hitchance(&plp->plane,
769                                       lnd_hardtarget(&land), EF_LAND);
770             pr("%d%% hitchance...", hitchance);
771         }
772         if (roll(100) <= hitchance) {
773             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
774                                  'p', &nukedam, 1);
775         } else {
776             pr("thud\n");
777             /* Bombs that miss have to land somewhere! */
778             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
779                              'p', &nukedam, 0);
780             collateral_damage(target->sct_x, target->sct_y, dam);
781             dam = 0;
782         }
783         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
784             continue;
785         if (dam > 100)
786             dam = 100;
787         own = land.lnd_own;
788         mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
789             cname(player->cnum), dam, prland(&land));
790         check_retreat_and_do_landdamage(&land, dam);
791
792         if (land.lnd_rflags & RET_BOMBED)
793             if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
794                 retreat_land(&land, 'b');
795         nreport(player->cnum, N_UNIT_BOMB, own, 1);
796         putland(land.lnd_uid, &land);
797         collateral_damage(target->sct_x, target->sct_y, dam);
798       next:
799         ;
800     }
801 }
802
803 static void
804 strat_bomb(struct emp_qelem *list, struct sctstr *target)
805 {
806     struct plist *plp;
807     int dam = 0;
808     struct emp_qelem *qp;
809     struct sctstr sect;
810     int nukedam;
811
812     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
813         plp = (struct plist *)qp;
814         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
815             continue;
816         if (plp->bombs || plp->plane.pln_nuketype != -1)
817             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
818                               's', &nukedam, 1);
819     }
820     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
821         return;
822     getsect(target->sct_x, target->sct_y, &sect);
823     target = &sect;
824     if (target->sct_own)
825         wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
826            cname(player->cnum), PERCENT_DAMAGE(dam),
827            xyas(target->sct_x, target->sct_y, target->sct_own));
828
829     sectdamage(target, dam);
830
831     pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
832        xyas(target->sct_x, target->sct_y, player->cnum));
833     putsect(&sect);
834 }
835
836 static int
837 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
838                     int flak)
839 {
840     int disp;
841     char dmess[255];
842     int eff;
843     natid plane_owner;
844     int dam;
845
846     dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
847     disp = 0;
848     plane_owner = pp->pln_own;
849     eff = pp->pln_effic;
850     if (dam <= 0)
851         return 0;
852     memset(dmess, 0, sizeof(dmess));
853     eff -= dam;
854     if (eff < 0)
855         eff = 0;
856     if (eff < PLANE_MINEFF) {
857         sprintf(dmess, " -- shot down");
858         disp = 1;
859     } else if (chance((100 - eff) / 100.0)) {
860         sprintf(dmess, " -- aborted with %d%% damage", 100 - eff);
861         disp = 2;
862     }
863     PR(plane_owner, "    Flak! %s %s takes %d%s.\n",
864        cname(pp->pln_own), prplane(pp), dam, dmess);
865
866     pp->pln_effic = eff;
867     if (disp == 1) {
868         if (from != 0)
869             nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
870     }
871     putplane(pp->pln_uid, pp);
872
873     if (disp > 0)
874         return 1;
875     return 0;
876 }