2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
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.
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.
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
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.
28 * bomb.c: Fly bombing missions
30 * Known contributors to this file:
33 * Steve McClure, 1998-2000
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);
68 static int bombcomm[] = {
84 static int nbomb = sizeof(bombcomm) / sizeof(int);
96 s_char flightpath[MAX_PATH_LEN];
97 struct nstr_item ni_bomb;
98 struct nstr_item ni_esc;
100 struct sctstr target;
101 struct emp_qelem bomb_list;
102 struct emp_qelem esc_list;
104 struct sctstr ap_sect;
111 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
113 if (!snxtitem(&ni_esc, EF_PLANE,
114 getstarg(player->argp[2], "escort(s)? ", buf)))
115 pr("No escorts...\n");
117 getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
120 if (strchr("ps", mission) == 0)
122 if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0
125 if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
127 if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
128 getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
129 pr("Assembly point not owned by you or an ally!\n");
134 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0,
135 0, P_FLYING) == 0 || *flightpath == 0)
139 (void)pathtoxy(flightpath, &tx, &ty, fcost);
140 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
141 getsect(tx, ty, &target);
143 ap_to_target = strlen(flightpath);
144 if (*(flightpath + strlen(flightpath) - 1) == 'h')
146 pr("range to target is %d\n", ap_to_target);
148 * select planes within range
151 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
152 2, wantflags, P_M | P_O);
153 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
154 2, wantflags | P_F | P_ESC, P_M | P_O);
156 * now arm and equip the bombers, transports, whatever.
157 * tech is stored in high 16 bits of mission_flags.
161 mission_flags |= P_X; /* stealth (shhh) */
162 mission_flags |= P_H; /* gets turned off if not all choppers */
164 pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0,
165 mission_flags, &tech);
166 if (QEMPTY(&bomb_list)) {
167 pr("No planes could be equipped for the mission.\n");
171 pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC,
172 mission_flags, &tech);
173 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
175 if (QEMPTY(&bomb_list)) {
176 pr("No planes got through fighter defenses\n");
177 } else if (target.sct_type == SCT_SANCT) {
178 pr("You can't bomb that sector!\n");
182 pin_bomb(&bomb_list, &target);
186 natp = getnatp(player->cnum);
187 if (target.sct_own) {
188 rel = getrel(natp, target.sct_own);
189 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
190 && (target.sct_own) &&
191 (target.sct_oldown != player->cnum)) {
192 pr("You're not at war with them!\n");
199 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
200 strat_bomb(&bomb_list, &target);
203 pr("Bad mission %c\n", mission);
213 pin_bomb(struct emp_qelem *list, struct sctstr *target)
222 struct emp_qelem *qp;
232 type = target->sct_type;
234 pr("Target sector is a %s constructed %s\n",
235 effadv((int)target->sct_effic), dcp->d_name);
237 plp = (struct plist *)list->q_forw;
238 if (plp->pcp->pl_flags & P_A) {
240 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
241 plp = (struct plist *)qp;
242 if (plp->plane.pln_acc < bestacc)
243 bestacc = plp->plane.pln_acc;
244 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
245 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
247 pr("Some subs are present in the sector.\n");
249 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
251 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
252 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
254 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
256 if (p == 0 || *p == 0) {
267 natp = getnatp(player->cnum);
268 if (target->sct_own) {
269 rel = getrel(natp, target->sct_own);
270 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
271 && (target->sct_own) &&
272 (target->sct_oldown != player->cnum)) {
273 pr("You're not at war with them!\n");
279 pr("no units there\n");
282 land_bomb(list, target);
286 natp = getnatp(player->cnum);
287 if (target->sct_own) {
288 rel = getrel(natp, target->sct_own);
289 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
290 && (target->sct_own) &&
291 (target->sct_oldown != player->cnum)) {
292 pr("You're not at war with them!\n");
298 pr("no planes there\n");
301 plane_bomb(list, target);
305 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
307 pr("no ships there\n");
311 pr("no ships there\n");
315 ship_bomb(list, target);
319 natp = getnatp(player->cnum);
320 if (target->sct_own) {
321 rel = getrel(natp, target->sct_own);
322 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
323 && (target->sct_own) &&
324 (target->sct_oldown != player->cnum)) {
325 pr("You're not at war with them!\n");
331 for (i = 0; i < nbomb; i++) {
332 if (!target->sct_item[bombcomm[i]])
337 pr("No bombable commodities in %s\n",
338 xyas(target->sct_x, target->sct_y, player->cnum));
341 comm_bomb(list, target);
345 natp = getnatp(player->cnum);
346 if (target->sct_own) {
347 rel = getrel(natp, target->sct_own);
348 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
349 && (target->sct_own) &&
350 (target->sct_oldown != player->cnum)) {
351 pr("You're not at war with them!\n");
356 eff_bomb(list, target);
359 pr("Aborting mission.\n");
362 pr("Bad target type.\n");
368 eff_bomb(struct emp_qelem *list, struct sctstr *target)
370 register struct plist *plp;
371 struct emp_qelem *qp;
376 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
377 plp = (struct plist *)qp;
378 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
380 if (plp->bombs || plp->plane.pln_nuketype != -1)
382 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
385 if (dam <= 0) /* dam == 0 if only nukes were delivered */
387 getsect(target->sct_x, target->sct_y, §);
389 oldeff = target->sct_effic;
390 target->sct_effic = effdamage(target->sct_effic, dam);
391 target->sct_avail = effdamage(target->sct_avail, dam);
392 target->sct_road = effdamage(target->sct_road, dam);
393 target->sct_rail = effdamage(target->sct_rail, dam);
394 target->sct_defense = effdamage(target->sct_defense, dam);
395 if (!opt_DEFENSE_INFRA)
396 target->sct_defense = target->sct_effic;
397 pr("did %d%% damage to efficiency in %s\n",
398 oldeff - target->sct_effic,
399 xyas(target->sct_x, target->sct_y, player->cnum));
401 wu(0, target->sct_own,
402 "%s bombing raid did %d%% damage in %s\n",
403 cname(player->cnum), oldeff - target->sct_effic,
404 xyas(target->sct_x, target->sct_y, target->sct_own));
405 if (target->sct_effic < SCT_MINEFF) {
406 if (target->sct_type == SCT_BSPAN)
407 knockdown(target, list);
408 else if (target->sct_type == SCT_BTOWER) {
409 knockdown(target, list);
410 bridgefall(target, list);
414 collateral_damage(target->sct_x, target->sct_y, dam, list);
418 comm_bomb(struct emp_qelem *list, struct sctstr *target)
420 register struct plist *plp;
425 struct emp_qelem *qp;
430 for (i = 0; i < nbomb; i++) {
431 if (target->sct_item[bombcomm[i]] == 0)
433 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
435 ip = &ichr[bombcomm[i]];
436 pr("some %s\n", ip->i_name);
439 ip = whatitem((s_char *)0, "commodity to bomb? ");
445 for (i = 0; i < nbomb; i++) {
446 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
448 if (&ichr[bombcomm[i]] == ip)
452 pr("You can't bomb %s!\n", ip->i_name);
453 for (i = 0; i < nbomb; i++) {
454 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
456 pr(i == 0 ? "Bombable: " : ", ");
457 pr(ichr[bombcomm[i]].i_name);
463 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
464 plp = (struct plist *)qp;
465 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
467 if (plp->bombs || plp->plane.pln_nuketype != -1)
469 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
472 if (dam <= 0) /* dam == 0 if only nukes were delivered */
474 getsect(target->sct_x, target->sct_y, §);
476 before = amt = target->sct_item[ip->i_vtype];
477 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
479 b = 100.0 * (1.0 - ((float)amt / (float)before));
482 pr("did %.2f%% damage to %s in %s\n",
483 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
484 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
485 if (target->sct_own != 0)
486 wu(0, target->sct_own,
487 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
488 cname(player->cnum), b, ip->i_name,
489 xyas(target->sct_x, target->sct_y, target->sct_own));
491 collateral_damage(target->sct_x, target->sct_y, dam, list);
495 ship_bomb(struct emp_qelem *list, struct sctstr *target)
503 struct emp_qelem *qp;
508 struct shiplook head, *s, *s2;
518 memset(&head, 0, sizeof(struct shiplook));
520 onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
521 for (qp = list->q_forw; qp != list && !player->aborted;
523 if (head.uid != -1) {
525 while (s != (struct shiplook *)0) {
531 memset(&head, 0, sizeof(struct shiplook));
533 plp = (struct plist *)qp;
534 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
536 if (plp->pcp->pl_flags & P_A)
537 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
540 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
542 pr("%s could not find any ships!\n", prplane(&plp->plane));
545 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
546 prplane(&plp->plane), plp->bombs);
549 while (shipno < 0 && !player->aborted && !ignore) {
550 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
557 if (plp->pcp->pl_flags & P_A)
560 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
570 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
571 ship.shp_y == target->sct_y)
578 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
580 shell = ship.shp_item[I_SHELL];
582 shell = supply_commod(ship.shp_own, ship.shp_x,
583 ship.shp_y, I_SHELL, 1);
585 mcp = &mchr[(int)ship.shp_type];
586 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
587 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
588 ship.shp_item[I_SHELL] = shell;
589 putship(ship.shp_uid, &ship);
590 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
591 flak, prship(&ship));
592 PR(ship.shp_own, msg);
593 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
598 if (plp->plane.pln_nuketype != -1)
602 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
603 pr("%d%% hitchance...", hitchance);
605 if (roll(100) <= hitchance) {
606 /* pinbombing is more accurate than normal bombing */
608 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
612 /* Bombs that miss have to land somewhere! */
614 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
616 collateral_damage(target->sct_x, target->sct_y, dam, list);
619 if (dam <= 0) /* dam == 0 if only nukes were delivered */
621 if (mcp->m_flags & M_SUB)
622 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
624 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
626 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
627 cname(player->cnum), dam,
629 xyas(target->sct_x, target->sct_y, ship.shp_own));
632 check_retreat_and_do_shipdamage(&ship, dam);
633 if (ship.shp_rflags & RET_BOMBED)
634 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
635 retreat_ship(&ship, 'b');
636 putship(ship.shp_uid, &ship);
637 getship(ship.shp_uid, &ship);
639 pr("%s at %s sunk!\n",
641 xyas(target->sct_x, target->sct_y, player->cnum));
643 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
648 while (s != (struct shiplook *)0) {
656 plane_bomb(struct emp_qelem *list, struct sctstr *target)
663 struct emp_qelem *qp;
673 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
674 plp = (struct plist *)qp;
675 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
677 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
679 pr("%s could not find any planes!\n", prplane(&plp->plane));
682 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
683 prplane(&plp->plane), plp->bombs);
686 while (planeno < 0 && !player->aborted && !ignore) {
687 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
694 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
702 if (getplane(n, &plane) &&
703 plane.pln_x == target->sct_x &&
704 plane.pln_y == target->sct_y &&
705 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
706 (!ac_isflying(&plane, list)))
709 pr("Plane #%d not spotted\n", n);
714 if (plp->plane.pln_nuketype != -1)
717 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
718 pr("%d%% hitchance...", hitchance);
720 if (roll(100) <= hitchance) {
721 /* pinbombing is more accurate than normal bombing */
723 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
727 /* Bombs that miss have to land somewhere! */
729 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
731 collateral_damage(target->sct_x, target->sct_y, dam, list);
734 if (dam <= 0) /* dam == 0 if only nukes were delivered */
739 if (dam > plane.pln_effic) {
741 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
745 plane.pln_effic -= dam;
746 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
747 if (own == player->cnum) {
748 pr("%s reports %d%% damage\n", prplane(&plane), dam);
752 "%s pinpoint bombing raid did %d%% damage to %s\n",
753 cname(player->cnum), dam, prplane(&plane));
755 nreport(player->cnum, N_DOWN_PLANE, own, 1);
757 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
758 cname(player->cnum), dam, prplane(&plane),
759 xyas(target->sct_x, target->sct_y, own));
760 putplane(plane.pln_uid, &plane);
761 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
768 land_bomb(struct emp_qelem *list, struct sctstr *target)
779 struct emp_qelem *qp;
781 int ignore, flak, hitchance;
786 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
787 plp = (struct plist *)qp;
788 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
790 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
792 pr("%s could not find any units!\n", prplane(&plp->plane));
795 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
796 prplane(&plp->plane), plp->bombs);
799 while (unitno < 0 && !player->aborted && !ignore) {
800 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
807 unitsatxy(target->sct_x, target->sct_y, 0, 0);
815 if (getland(n, &land) &&
816 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
819 pr("Unit #%d not spotted\n", n);
824 lcp = &lchr[(int)land.lnd_type];
826 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
829 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
830 prland(&land), land.lnd_aaf);
831 PR(land.lnd_own, msg);
832 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
837 if (plp->plane.pln_nuketype != -1)
841 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
842 pr("%d%% hitchance...", hitchance);
844 if (roll(100) <= hitchance) {
846 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
850 /* Bombs that miss have to land somewhere! */
852 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
854 collateral_damage(target->sct_x, target->sct_y, dam, list);
857 if (dam <= 0) /* dam == 0 if only nukes were delivered */
864 "%s pinpoint bombing raid did %d damage to %s\n",
865 cname(player->cnum), dam, prland(&land));
866 check_retreat_and_do_landdamage(&land, dam);
868 if (land.lnd_rflags & RET_BOMBED)
869 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
870 retreat_land(&land, 'b');
871 nreport(player->cnum, N_UNIT_BOMB, own, 1);
872 putland(land.lnd_uid, &land);
873 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
880 strat_bomb(struct emp_qelem *list, struct sctstr *target)
882 register struct plist *plp;
884 struct emp_qelem *qp;
888 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
889 plp = (struct plist *)qp;
890 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
892 if (plp->bombs || plp->plane.pln_nuketype != -1)
894 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
897 if (dam <= 0) /* dam == 0 if only nukes were delivered */
899 getsect(target->sct_x, target->sct_y, §);
902 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
903 cname(player->cnum), PERCENT_DAMAGE(dam),
904 xyas(target->sct_x, target->sct_y, target->sct_own));
906 sectdamage(target, dam, list);
908 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
909 xyas(target->sct_x, target->sct_y, player->cnum));
914 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
915 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
919 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
932 flak -= (pp->pln_def + 1);
933 if (pcp->pl_flags & P_X)
935 if (pcp->pl_flags & P_H)
938 mult = lflaktable[FLAK_MAX] * 1.33;
940 mult = lflaktable[0] * 0.66;
943 mult = lflaktable[flak];
946 dam = (int)((roll(8) + 2) * mult);
951 plane_owner = pp->pln_own;
955 memset(dmess, 0, sizeof(dmess));
959 if (eff < PLANE_MINEFF) {
960 sprintf(dmess, " -- shot down");
962 } else if (chance((100 - eff) / 100.0)) {
963 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
966 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
967 cname(pp->pln_own), prplane(pp), dam, dmess);
968 PR(plane_owner, mesg);
973 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
974 if (pp->pln_ship >= 0) {
975 getship(pp->pln_ship, &ship);
976 take_plane_off_ship(pp, &ship);
978 if (pp->pln_land >= 0) {
979 getland(pp->pln_land, &land);
980 take_plane_off_land(pp, &land);
982 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
984 putplane(pp->pln_uid, pp);
986 putplane(pp->pln_uid, pp);