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