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);
142 if (target.sct_type == SCT_SANCT) {
143 pr("You can't bomb that sector!\n");
147 ap_to_target = strlen(flightpath);
148 if (*(flightpath + strlen(flightpath) - 1) == 'h')
150 pr("range to target is %d\n", ap_to_target);
152 * select planes within range
155 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
156 2, wantflags, P_M | P_O);
157 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
158 2, wantflags | P_F | P_ESC, P_M | P_O);
160 * now arm and equip the bombers, transports, whatever.
161 * tech is stored in high 16 bits of mission_flags.
165 mission_flags |= P_X; /* stealth (shhh) */
166 mission_flags |= P_H; /* gets turned off if not all choppers */
168 pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0,
169 mission_flags, &tech);
170 if (QEMPTY(&bomb_list)) {
171 pr("No planes could be equipped for the mission.\n");
175 pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC,
176 mission_flags, &tech);
177 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
179 if (QEMPTY(&bomb_list)) {
180 pr("No planes got through fighter defenses\n");
184 pin_bomb(&bomb_list, &target);
188 natp = getnatp(player->cnum);
189 if (target.sct_own) {
190 rel = getrel(natp, target.sct_own);
191 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
192 && (target.sct_own) &&
193 (target.sct_oldown != player->cnum)) {
194 pr("You're not at war with them!\n");
201 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
202 strat_bomb(&bomb_list, &target);
205 pr("Bad mission %c\n", mission);
215 pin_bomb(struct emp_qelem *list, struct sctstr *target)
225 struct emp_qelem *qp;
235 type = target->sct_type;
237 pr("Target sector is a %s constructed %s\n",
238 effadv((int)target->sct_effic), dcp->d_name);
240 plp = (struct plist *)list->q_forw;
241 if (plp->pcp->pl_flags & P_A) {
243 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
244 plp = (struct plist *)qp;
245 if (plp->plane.pln_acc < bestacc)
246 bestacc = plp->plane.pln_acc;
247 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
248 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
250 pr("Some subs are present in the sector.\n");
252 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
254 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
255 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
256 getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
258 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
260 if (p == 0 || *p == 0) {
271 natp = getnatp(player->cnum);
272 if (target->sct_own) {
273 rel = getrel(natp, target->sct_own);
274 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
275 && (target->sct_own) &&
276 (target->sct_oldown != player->cnum)) {
277 pr("You're not at war with them!\n");
283 pr("no units there\n");
286 land_bomb(list, target);
290 natp = getnatp(player->cnum);
291 if (target->sct_own) {
292 rel = getrel(natp, target->sct_own);
293 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
294 && (target->sct_own) &&
295 (target->sct_oldown != player->cnum)) {
296 pr("You're not at war with them!\n");
302 pr("no planes there\n");
305 plane_bomb(list, target);
309 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
311 pr("no ships there\n");
315 pr("no ships there\n");
319 ship_bomb(list, target);
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");
335 for (i = 0; i < nbomb; i++) {
336 if (!vec[bombcomm[i]])
341 pr("No bombable commodities in %s\n",
342 xyas(target->sct_x, target->sct_y, player->cnum));
345 comm_bomb(list, target);
349 natp = getnatp(player->cnum);
350 if (target->sct_own) {
351 rel = getrel(natp, target->sct_own);
352 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
353 && (target->sct_own) &&
354 (target->sct_oldown != player->cnum)) {
355 pr("You're not at war with them!\n");
360 eff_bomb(list, target);
363 pr("Aborting mission.\n");
366 pr("Bad target type.\n");
372 eff_bomb(struct emp_qelem *list, struct sctstr *target)
374 register struct plist *plp;
375 struct emp_qelem *qp;
380 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
381 plp = (struct plist *)qp;
382 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
384 if (plp->bombs || plp->plane.pln_nuketype != -1)
386 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
389 if (dam <= 0) /* dam == 0 if only nukes were delivered */
391 getsect(target->sct_x, target->sct_y, §);
393 oldeff = target->sct_effic;
394 target->sct_effic = effdamage(target->sct_effic, dam);
395 target->sct_road = effdamage(target->sct_road, dam);
396 target->sct_rail = effdamage(target->sct_rail, dam);
397 target->sct_defense = effdamage(target->sct_defense, dam);
398 if (!opt_DEFENSE_INFRA)
399 target->sct_defense = target->sct_effic;
400 pr("did %d%% damage to efficiency in %s\n",
401 oldeff - target->sct_effic,
402 xyas(target->sct_x, target->sct_y, player->cnum));
404 wu(0, target->sct_own,
405 "%s bombing raid did %d%% damage in %s\n",
406 cname(player->cnum), oldeff - target->sct_effic,
407 xyas(target->sct_x, target->sct_y, target->sct_own));
408 if (target->sct_effic < 20) {
409 if (target->sct_type == SCT_BSPAN)
410 knockdown(target, list);
411 else if (target->sct_type == SCT_BTOWER) {
412 knockdown(target, list);
413 bridgefall(target, list);
417 collateral_damage(target->sct_x, target->sct_y, dam, list);
421 comm_bomb(struct emp_qelem *list, struct sctstr *target)
423 register struct plist *plp;
429 struct emp_qelem *qp;
434 getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
435 for (i = 0; i < nbomb; i++) {
436 if (vec[bombcomm[i]] == 0)
438 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
440 ip = &ichr[bombcomm[i]];
441 pr("some %s\n", ip->i_name);
444 ip = whatitem((s_char *)0, "commodity to bomb? ");
450 for (i = 0; i < nbomb; i++) {
451 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
453 if (&ichr[bombcomm[i]] == ip)
457 pr("You can't bomb %s!\n", ip->i_name);
458 for (i = 0; i < nbomb; i++) {
459 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
461 pr(i == 0 ? "Bombable: " : ", ");
462 pr(ichr[bombcomm[i]].i_name);
468 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
469 plp = (struct plist *)qp;
470 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
472 if (plp->bombs || plp->plane.pln_nuketype != -1)
474 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
477 if (dam <= 0) /* dam == 0 if only nukes were delivered */
479 getsect(target->sct_x, target->sct_y, §);
481 before = amt = target->sct_item[ip->i_vtype];
482 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
484 b = 100.0 * (1.0 - ((float)amt / (float)before));
487 pr("did %.2f%% damage to %s in %s\n",
488 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
489 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
490 if (target->sct_own != 0)
491 wu(0, target->sct_own,
492 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
493 cname(player->cnum), b, ip->i_name,
494 xyas(target->sct_x, target->sct_y, target->sct_own));
496 collateral_damage(target->sct_x, target->sct_y, dam, list);
500 ship_bomb(struct emp_qelem *list, struct sctstr *target)
508 struct emp_qelem *qp;
513 struct shiplook head, *s, *s2;
523 memset(&head, 0, sizeof(struct shiplook));
525 onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
526 for (qp = list->q_forw; qp != list && !player->aborted;
528 if (head.uid != -1) {
530 while (s != (struct shiplook *)0) {
536 memset(&head, 0, sizeof(struct shiplook));
538 plp = (struct plist *)qp;
539 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
541 if (plp->pcp->pl_flags & P_A)
542 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
545 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
547 pr("%s could not find any ships!\n", prplane(&plp->plane));
550 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
551 prplane(&plp->plane), plp->bombs);
554 while (shipno < 0 && !player->aborted && !ignore) {
555 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
562 if (plp->pcp->pl_flags & P_A)
565 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
575 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
576 ship.shp_y == target->sct_y)
583 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
585 shell = ship.shp_item[I_SHELL];
587 shell = supply_commod(ship.shp_own, ship.shp_x,
588 ship.shp_y, I_SHELL, 1);
590 mcp = &mchr[(int)ship.shp_type];
591 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
592 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
593 ship.shp_item[I_SHELL] = shell;
594 putship(ship.shp_uid, &ship);
595 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
596 flak, prship(&ship));
597 PR(ship.shp_own, msg);
598 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
603 if (plp->plane.pln_nuketype != -1)
607 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
608 pr("%d%% hitchance...", hitchance);
610 if (roll(100) <= hitchance) {
611 /* pinbombing is more accurate than normal bombing */
613 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
617 /* Bombs that miss have to land somewhere! */
619 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
621 collateral_damage(target->sct_x, target->sct_y, dam, list);
624 if (dam <= 0) /* dam == 0 if only nukes were delivered */
626 if (mcp->m_flags & M_SUB)
627 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
629 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
631 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
632 cname(player->cnum), dam,
634 xyas(target->sct_x, target->sct_y, ship.shp_own));
637 check_retreat_and_do_shipdamage(&ship, dam);
638 if (ship.shp_rflags & RET_BOMBED)
639 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
640 retreat_ship(&ship, 'b');
641 putship(ship.shp_uid, &ship);
644 pr("%s at %s sunk!\n",
646 xyas(target->sct_x, target->sct_y, player->cnum));
648 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
653 while (s != (struct shiplook *)0) {
661 plane_bomb(struct emp_qelem *list, struct sctstr *target)
668 struct emp_qelem *qp;
678 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
679 plp = (struct plist *)qp;
680 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
682 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
684 pr("%s could not find any planes!\n", prplane(&plp->plane));
687 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
688 prplane(&plp->plane), plp->bombs);
691 while (planeno < 0 && !player->aborted && !ignore) {
692 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
699 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
707 if (getplane(n, &plane) &&
708 plane.pln_x == target->sct_x &&
709 plane.pln_y == target->sct_y &&
710 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
711 (!ac_isflying(&plane, list)))
714 pr("Plane #%d not spotted\n", n);
719 if (plp->plane.pln_nuketype != -1)
722 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
723 pr("%d%% hitchance...", hitchance);
725 if (roll(100) <= hitchance) {
726 /* pinbombing is more accurate than normal bombing */
728 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
732 /* Bombs that miss have to land somewhere! */
734 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
736 collateral_damage(target->sct_x, target->sct_y, dam, list);
739 if (dam <= 0) /* dam == 0 if only nukes were delivered */
744 if (dam > plane.pln_effic) {
746 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
750 plane.pln_effic -= dam;
751 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
752 if (own == player->cnum) {
753 pr("%s reports %d%% damage\n", prplane(&plane), dam);
757 "%s pinpoint bombing raid did %d%% damage to %s\n",
758 cname(player->cnum), dam, prplane(&plane));
760 nreport(player->cnum, N_DOWN_PLANE, own, 1);
762 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
763 cname(player->cnum), dam, prplane(&plane),
764 xyas(target->sct_x, target->sct_y, own));
765 putplane(plane.pln_uid, &plane);
766 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
773 land_bomb(struct emp_qelem *list, struct sctstr *target)
784 struct emp_qelem *qp;
786 int ignore, flak, hitchance;
791 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
792 plp = (struct plist *)qp;
793 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
795 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
797 pr("%s could not find any units!\n", prplane(&plp->plane));
800 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
801 prplane(&plp->plane), plp->bombs);
804 while (unitno < 0 && !player->aborted && !ignore) {
805 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
812 unitsatxy(target->sct_x, target->sct_y, 0, 0);
820 if (getland(n, &land) &&
821 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
824 pr("Unit #%d not spotted\n", n);
829 lcp = &lchr[(int)land.lnd_type];
831 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
834 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
835 prland(&land), land.lnd_aaf);
836 PR(land.lnd_own, msg);
837 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
842 if (plp->plane.pln_nuketype != -1)
846 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
847 pr("%d%% hitchance...", hitchance);
849 if (roll(100) <= hitchance) {
851 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
855 /* Bombs that miss have to land somewhere! */
857 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
859 collateral_damage(target->sct_x, target->sct_y, dam, list);
862 if (dam <= 0) /* dam == 0 if only nukes were delivered */
869 "%s pinpoint bombing raid did %d damage to %s\n",
870 cname(player->cnum), dam, prland(&land));
871 check_retreat_and_do_landdamage(&land, dam);
873 if (land.lnd_rflags & RET_BOMBED)
874 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
875 retreat_land(&land, 'b');
876 nreport(player->cnum, N_UNIT_BOMB, own, 1);
877 putland(land.lnd_uid, &land);
878 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
885 strat_bomb(struct emp_qelem *list, struct sctstr *target)
887 register struct plist *plp;
889 struct emp_qelem *qp;
893 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
894 plp = (struct plist *)qp;
895 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
897 if (plp->bombs || plp->plane.pln_nuketype != -1)
899 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
902 if (dam <= 0) /* dam == 0 if only nukes were delivered */
904 getsect(target->sct_x, target->sct_y, §);
907 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
908 cname(player->cnum), PERCENT_DAMAGE(dam),
909 xyas(target->sct_x, target->sct_y, target->sct_own));
911 sectdamage(target, dam, list);
913 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
914 xyas(target->sct_x, target->sct_y, player->cnum));
919 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
920 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
924 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
937 flak -= (pp->pln_def + 1);
938 if (pcp->pl_flags & P_X)
940 if (pcp->pl_flags & P_H)
943 mult = lflaktable[FLAK_MAX] * 1.33;
945 mult = lflaktable[0] * 0.66;
948 mult = lflaktable[flak];
951 dam = (int)((roll(8) + 2) * mult);
956 plane_owner = pp->pln_own;
960 memset(dmess, 0, sizeof(dmess));
964 if (eff < PLANE_MINEFF) {
965 sprintf(dmess, " -- shot down");
967 } else if (chance((100 - eff) / 100.0)) {
968 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
971 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
972 cname(pp->pln_own), prplane(pp), dam, dmess);
973 PR(plane_owner, mesg);
978 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
979 if (pp->pln_ship >= 0) {
980 getship(pp->pln_ship, &ship);
981 take_plane_off_ship(pp, &ship);
983 if (pp->pln_land >= 0) {
984 getland(pp->pln_land, &land);
985 take_plane_off_land(pp, &land);
987 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
989 putplane(pp->pln_uid, pp);
991 putplane(pp->pln_uid, pp);