]> git.pond.sub.org Git - empserver/blob - src/lib/commands/bomb.c
Oops rather than complain to player on bad mission in bomb()
[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     if (plp->pcp->pl_flags & P_A) {
213         nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
214         nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
215         if (nsubs > 0)
216             pr("Some subs are present in the sector.\n");
217     } else {
218         nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
219     }
220     nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
221     nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
222   retry:
223     p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
224                   buf);
225     if (p == 0 || *p == 0) {
226         if (player->aborted)
227             return;
228         bad++;
229         if (bad > 2)
230             return;
231         goto retry;
232     }
233     switch (*p) {
234     case 'l':
235         if (opt_SLOW_WAR) {
236             natp = getnatp(player->cnum);
237             if (target->sct_own) {
238                 rel = getrel(natp, target->sct_own);
239                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
240                     && (target->sct_own) &&
241                     (target->sct_oldown != player->cnum)) {
242                     pr("You're not at war with them!\n");
243                     goto retry;
244                 }
245             }
246         }
247         if (nunits == 0) {
248             pr("no units there\n");
249             goto retry;
250         }
251         land_bomb(list, target);
252         break;
253     case 'p':
254         if (opt_SLOW_WAR) {
255             natp = getnatp(player->cnum);
256             if (target->sct_own) {
257                 rel = getrel(natp, target->sct_own);
258                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
259                     && (target->sct_own) &&
260                     (target->sct_oldown != player->cnum)) {
261                     pr("You're not at war with them!\n");
262                     goto retry;
263                 }
264             }
265         }
266         if (nplanes == 0) {
267             pr("no planes there\n");
268             goto retry;
269         }
270         plane_bomb(list, target);
271         break;
272     case 's':
273         if (nships == 0) {
274             if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
275                 if (nsubs == 0) {
276                     pr("no ships there\n");
277                     goto retry;
278                 }
279             } else {
280                 pr("no ships there\n");
281                 goto retry;
282             }
283         }
284         ship_bomb(list, target);
285         break;
286     case 'c':
287         if (opt_SLOW_WAR) {
288             natp = getnatp(player->cnum);
289             if (target->sct_own) {
290                 rel = getrel(natp, target->sct_own);
291                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
292                     && (target->sct_own) &&
293                     (target->sct_oldown != player->cnum)) {
294                     pr("You're not at war with them!\n");
295                     goto retry;
296                 }
297             }
298         }
299
300         for (i = 0; i < nbomb; i++) {
301             if (!target->sct_item[bombcomm[i]])
302                 continue;
303             break;
304         }
305         if (i >= nbomb) {
306             pr("No bombable commodities in %s\n",
307                xyas(target->sct_x, target->sct_y, player->cnum));
308             goto retry;
309         }
310         comm_bomb(list, target);
311         break;
312     case 'e':
313         if (opt_SLOW_WAR) {
314             natp = getnatp(player->cnum);
315             if (target->sct_own) {
316                 rel = getrel(natp, target->sct_own);
317                 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
318                     && (target->sct_own) &&
319                     (target->sct_oldown != player->cnum)) {
320                     pr("You're not at war with them!\n");
321                     goto retry;
322                 }
323             }
324         }
325         eff_bomb(list, target);
326         break;
327     case 'q':
328         pr("Aborting mission.\n");
329         return;
330     default:
331         pr("Bad target type.\n");
332         goto retry;
333     }
334 }
335
336 static void
337 eff_bomb(struct emp_qelem *list, struct sctstr *target)
338 {
339     struct plist *plp;
340     struct emp_qelem *qp;
341     struct sctstr sect;
342     int oldeff, dam = 0;
343     int nukedam;
344
345     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
346         plp = (struct plist *)qp;
347         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
348             continue;
349         if (plp->bombs || plp->plane.pln_nuketype != -1)
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;
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 = qp->q_forw) {
423         plp = (struct plist *)qp;
424         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
425             continue;
426         if (plp->bombs || plp->plane.pln_nuketype != -1)
427             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
428                               'p', &nukedam, 1);
429     }
430     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
431         return;
432     getsect(target->sct_x, target->sct_y, &sect);
433     target = &sect;
434     before = target->sct_item[ip->i_uid];
435     target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
436     if (before > 0.0)
437         b = 100.0 * (1.0 - (double)amt / (double)before);
438     else
439         b = 0.0;
440     pr("did %.2f%% damage to %s in %s\n",
441        b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
442     nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
443     if (target->sct_own != 0)
444         wu(0, target->sct_own,
445            "%s precision bombing raid did %.2f%% damage to %s in %s\n",
446            cname(player->cnum), b, ip->i_name,
447            xyas(target->sct_x, target->sct_y, target->sct_own));
448     putsect(&sect);
449     collateral_damage(target->sct_x, target->sct_y, dam);
450 }
451
452 static void
453 ship_bomb(struct emp_qelem *list, struct sctstr *target)
454 {
455     struct plist *plp;
456     struct mchrstr *mcp;
457     int dam;
458     char *q;
459     int n;
460     struct emp_qelem *qp;
461     int shipno;
462     int ignore;
463     struct shpstr ship;
464     int nships = 0;
465     struct shiplist *head = NULL;
466     char buf[1024];
467     char prompt[128];
468     int hitchance;
469     int nukedam;
470     int flak;
471     int gun;
472     int shell;
473
474     for (qp = list->q_forw; qp != list && !player->aborted;
475          qp = qp->q_forw) {
476         free_shiplist(&head);
477         plp = (struct plist *)qp;
478         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
479             continue;
480         if (plp->pcp->pl_flags & P_A)
481             nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
482                                    &plp->plane, &head);
483         else
484             nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
485         if (nships == 0) {
486             pr("%s could not find any ships!\n", prplane(&plp->plane));
487             continue;
488         }
489         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
490                       prplane(&plp->plane), plp->bombs);
491         ignore = 0;
492         shipno = -1;
493         while (shipno < 0 && !player->aborted && !ignore) {
494             if ((q = getstring(prompt, buf)) == 0 || *q == 0)
495                 continue;
496             if (*q == '~') {
497                 ignore = 1;
498                 continue;
499             }
500             if (*q == '?') {
501                 if (plp->pcp->pl_flags & P_A)
502                     print_shiplist(head);
503                 else
504                     shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
505                 continue;
506             }
507             if (*q == 'd')
508                 goto next;
509             if (!isdigit(*q))
510                 continue;
511             n = atoi(q);
512             if (n < 0)
513                 continue;
514             if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
515                 continue;
516             if (getship(n, &ship) && ship.shp_x == target->sct_x &&
517                 ship.shp_y == target->sct_y)
518                 shipno = n;
519         }
520         if (shipno < 0)
521             continue;
522         if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
523             continue;
524
525         shell = 0;
526         gun = shp_usable_guns(&ship);
527         if (gun > 0) {
528             shell = ship.shp_item[I_SHELL];
529             if (shell <= 0)
530                 shell = supply_commod(ship.shp_own,
531                                       ship.shp_x, ship.shp_y, I_SHELL, 1);
532         }
533         mcp = &mchr[(int)ship.shp_type];
534         if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
535             flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
536             ship.shp_item[I_SHELL] = shell;
537             putship(ship.shp_uid, &ship);
538             PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
539                flak, prship(&ship));
540             if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
541                 continue;
542         }
543
544         dam = 0;
545         if (plp->plane.pln_nuketype != -1)
546             hitchance = 100;
547         else {
548             hitchance = pln_hitchance(&plp->plane,
549                                       shp_hardtarget(&ship), EF_SHIP);
550             pr("%d%% hitchance...", hitchance);
551         }
552         if (roll(100) <= hitchance) {
553             /* pinbombing is more accurate than normal bombing */
554             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
555                                  'p', &nukedam, 1);
556         } else {
557             pr("splash\n");
558             /* Bombs that miss have to land somewhere! */
559             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
560                              'p', &nukedam, 0);
561             collateral_damage(target->sct_x, target->sct_y, dam);
562             dam = 0;
563         }
564         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
565             continue;
566         if (mcp->m_flags & M_SUB)
567             nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
568         else
569             nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
570         if (ship.shp_own) {
571             wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
572                cname(player->cnum), dam,
573                prship(&ship),
574                xyas(target->sct_x, target->sct_y, ship.shp_own));
575         }
576         pr("\n");
577         check_retreat_and_do_shipdamage(&ship, dam);
578         if (ship.shp_rflags & RET_BOMBED)
579             if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
580                 retreat_ship(&ship, 'b');
581         putship(ship.shp_uid, &ship);
582         getship(ship.shp_uid, &ship);
583         if (!ship.shp_own) {
584             pr("%s at %s sunk!\n",
585                prship(&ship),
586                xyas(target->sct_x, target->sct_y, player->cnum));
587         }
588         collateral_damage(target->sct_x, target->sct_y, dam / 2);
589       next:
590         ;
591     }
592     free_shiplist(&head);
593 }
594
595 static void
596 plane_bomb(struct emp_qelem *list, struct sctstr *target)
597 {
598     int dam;
599     char *q;
600     int n;
601     natid own;
602     struct plnstr plane;
603     struct emp_qelem *qp;
604     int planeno;
605     int ignore;
606     struct plist *plp;
607     char prompt[128];
608     char buf[1024];
609     int hitchance;
610     int nukedam;
611     int nplanes;
612
613     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
614         plp = (struct plist *)qp;
615         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
616             continue;
617         nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
618         if (nplanes == 0) {
619             pr("%s could not find any planes!\n", prplane(&plp->plane));
620             continue;
621         }
622         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
623                       prplane(&plp->plane), plp->bombs);
624         planeno = -1;
625         ignore = 0;
626         while (planeno < 0 && !player->aborted && !ignore) {
627             if ((q = getstring(prompt, buf)) == 0 || *q == 0)
628                 continue;
629             if (*q == '~') {
630                 ignore = 1;
631                 continue;
632             }
633             if (*q == '?') {
634                 planesatxy(target->sct_x, target->sct_y, 0, 0);
635                 continue;
636             }
637             if (*q == 'd')
638                 goto next;
639             n = atoi(q);
640             if (n < 0)
641                 continue;
642             if (getplane(n, &plane) &&
643                 plane.pln_x == target->sct_x &&
644                 plane.pln_y == target->sct_y &&
645                 !(plane.pln_flags & PLN_LAUNCHED))
646                 planeno = n;
647             else
648                 pr("Plane #%d not spotted\n", n);
649         }
650         if (planeno < 0)
651             continue;
652         dam = 0;
653         if (plp->plane.pln_nuketype != -1)
654             hitchance = 100;
655         else {
656             hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
657             pr("%d%% hitchance...", hitchance);
658         }
659         if (roll(100) <= hitchance) {
660             /* pinbombing is more accurate than normal bombing */
661             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
662                                  'p', &nukedam, 1);
663         } else {
664             pr("thud\n");
665             /* Bombs that miss have to land somewhere! */
666             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
667                              'p', &nukedam, 0);
668             collateral_damage(target->sct_x, target->sct_y, dam);
669             dam = 0;
670         }
671         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
672             continue;
673         if (dam > 100)
674             dam = 100;
675         own = plane.pln_own;
676         if (dam > plane.pln_effic)
677             plane.pln_effic = 0;
678         else
679             plane.pln_effic -= dam;
680         plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
681         if (own == player->cnum) {
682             pr("%s reports %d%% damage\n", prplane(&plane), dam);
683         } else {
684             if (own != 0)
685                 wu(0, own,
686                    "%s pinpoint bombing raid did %d%% damage to %s\n",
687                    cname(player->cnum), dam, prplane(&plane));
688         }
689         nreport(player->cnum, N_DOWN_PLANE, own, 1);
690         if (own != 0)
691             wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
692                cname(player->cnum), dam, prplane(&plane),
693                xyas(target->sct_x, target->sct_y, own));
694         putplane(plane.pln_uid, &plane);
695         collateral_damage(target->sct_x, target->sct_y, dam);
696       next:
697         ;
698     }
699 }
700
701 static void
702 land_bomb(struct emp_qelem *list, struct sctstr *target)
703 {
704     int dam;
705     char *q;
706     int n;
707     natid own;
708     char prompt[128];
709     char buf[1024];
710     struct lndstr land;
711     struct emp_qelem *qp;
712     int unitno;
713     int ignore, aaf, flak, hitchance;
714     struct plist *plp;
715     int nukedam;
716     int nunits;
717
718     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
719         plp = (struct plist *)qp;
720         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
721             continue;
722         nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
723         if (nunits == 0) {
724             pr("%s could not find any units!\n", prplane(&plp->plane));
725             continue;
726         }
727         (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
728                       prplane(&plp->plane), plp->bombs);
729         unitno = -1;
730         ignore = 0;
731         while (unitno < 0 && !player->aborted && !ignore) {
732             if ((q = getstring(prompt, buf)) == 0 || *q == 0)
733                 continue;
734             if (*q == '~') {
735                 ignore = 1;
736                 continue;
737             }
738             if (*q == '?') {
739                 unitsatxy(target->sct_x, target->sct_y, 0, 0);
740                 continue;
741             }
742             if (*q == 'd')
743                 goto next;
744             n = atoi(q);
745             if (n < 0)
746                 continue;
747             if (getland(n, &land) &&
748                 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
749                 unitno = n;
750             else
751                 pr("Unit #%d not spotted\n", n);
752         }
753         if (unitno < 0)
754             continue;
755
756         aaf = lnd_aaf(&land);
757         flak = (int)(techfact(land.lnd_tech, aaf) * 3.0);
758         if (flak) {
759             PR(land.lnd_own,
760                "Flak! Firing flak guns from unit %s (aa rating %d)\n",
761                prland(&land), aaf);
762             if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
763                 continue;
764         }
765
766         dam = 0;
767         if (plp->plane.pln_nuketype != -1)
768             hitchance = 100;
769         else {
770             hitchance = pln_hitchance(&plp->plane,
771                                       lnd_hardtarget(&land), EF_LAND);
772             pr("%d%% hitchance...", hitchance);
773         }
774         if (roll(100) <= hitchance) {
775             dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
776                                  'p', &nukedam, 1);
777         } else {
778             pr("thud\n");
779             /* Bombs that miss have to land somewhere! */
780             dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
781                              'p', &nukedam, 0);
782             collateral_damage(target->sct_x, target->sct_y, dam);
783             dam = 0;
784         }
785         if (dam <= 0)           /* dam == 0 if only nukes were delivered */
786             continue;
787         if (dam > 100)
788             dam = 100;
789         own = land.lnd_own;
790         mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
791             cname(player->cnum), dam, prland(&land));
792         check_retreat_and_do_landdamage(&land, dam);
793
794         if (land.lnd_rflags & RET_BOMBED)
795             if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
796                 retreat_land(&land, 'b');
797         nreport(player->cnum, N_UNIT_BOMB, own, 1);
798         putland(land.lnd_uid, &land);
799         collateral_damage(target->sct_x, target->sct_y, dam);
800       next:
801         ;
802     }
803 }
804
805 static void
806 strat_bomb(struct emp_qelem *list, struct sctstr *target)
807 {
808     struct plist *plp;
809     int dam = 0;
810     struct emp_qelem *qp;
811     struct sctstr sect;
812     int nukedam;
813
814     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
815         plp = (struct plist *)qp;
816         if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
817             continue;
818         if (plp->bombs || plp->plane.pln_nuketype != -1)
819             dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
820                               's', &nukedam, 1);
821     }
822     if (dam <= 0)               /* dam == 0 if only nukes were delivered */
823         return;
824     getsect(target->sct_x, target->sct_y, &sect);
825     target = &sect;
826     if (target->sct_own)
827         wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
828            cname(player->cnum), PERCENT_DAMAGE(dam),
829            xyas(target->sct_x, target->sct_y, target->sct_own));
830
831     sectdamage(target, dam);
832
833     pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
834        xyas(target->sct_x, target->sct_y, player->cnum));
835     putsect(&sect);
836 }
837
838 static int
839 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
840                     int flak)
841 {
842     int disp;
843     char dmess[255];
844     int eff;
845     natid plane_owner;
846     int dam;
847
848     dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
849     disp = 0;
850     plane_owner = pp->pln_own;
851     eff = pp->pln_effic;
852     if (dam <= 0)
853         return 0;
854     memset(dmess, 0, sizeof(dmess));
855     eff -= dam;
856     if (eff < 0)
857         eff = 0;
858     if (eff < PLANE_MINEFF) {
859         sprintf(dmess, " -- shot down");
860         disp = 1;
861     } else if (chance((100 - eff) / 100.0)) {
862         sprintf(dmess, " -- aborted with %d%% damage", 100 - eff);
863         disp = 2;
864     }
865     PR(plane_owner, "    Flak! %s %s takes %d%s.\n",
866        cname(pp->pln_own), prplane(pp), dam, dmess);
867
868     pp->pln_effic = eff;
869     if (disp == 1) {
870         if (from != 0)
871             nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
872     }
873     putplane(pp->pln_uid, pp);
874
875     if (disp > 0)
876         return 1;
877     return 0;
878 }