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