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