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