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