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