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