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