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