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