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