2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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
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);
66 static i_type bombcomm[] = {
82 static int nbomb = sizeof(bombcomm) / sizeof(int);
93 s_char flightpath[MAX_PATH_LEN];
94 struct nstr_item ni_bomb;
95 struct nstr_item ni_esc;
98 struct emp_qelem bomb_list;
99 struct emp_qelem esc_list;
101 struct sctstr ap_sect;
108 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
110 if (!snxtitem(&ni_esc, EF_PLANE,
111 getstarg(player->argp[2], "escort(s)? ", buf)))
112 pr("No escorts...\n");
114 getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
117 if (strchr("ps", mission) == 0)
119 if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0
122 if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
124 if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
125 getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
126 pr("Assembly point not owned by you or an ally!\n");
131 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0,
132 0, P_FLYING) == 0 || *flightpath == 0)
136 (void)pathtoxy(flightpath, &tx, &ty, fcost);
137 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
138 getsect(tx, ty, &target);
140 ap_to_target = strlen(flightpath);
141 if (*(flightpath + strlen(flightpath) - 1) == 'h')
143 pr("range to target is %d\n", ap_to_target);
145 * select planes within range
148 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
149 2, wantflags, P_M | P_O);
150 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
151 2, wantflags | P_F | P_ESC, P_M | P_O);
153 * now arm and equip the bombers, transports, whatever.
155 mission_flags |= P_X; /* stealth (shhh) */
156 mission_flags |= P_H; /* gets turned off if not all choppers */
157 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
158 ip, 0, mission_flags);
159 if (QEMPTY(&bomb_list)) {
160 pr("No planes could be equipped for the mission.\n");
163 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
164 ip, P_F | P_ESC, mission_flags);
165 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
167 if (QEMPTY(&bomb_list)) {
168 pr("No planes got through fighter defenses\n");
169 } else if (target.sct_type == SCT_SANCT) {
170 pr("You can't bomb that sector!\n");
174 pin_bomb(&bomb_list, &target);
178 natp = getnatp(player->cnum);
179 if (target.sct_own) {
180 rel = getrel(natp, target.sct_own);
181 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
182 && (target.sct_own) &&
183 (target.sct_oldown != player->cnum)) {
184 pr("You're not at war with them!\n");
191 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
192 strat_bomb(&bomb_list, &target);
195 pr("Bad mission %c\n", mission);
205 pin_bomb(struct emp_qelem *list, struct sctstr *target)
214 struct emp_qelem *qp;
224 type = target->sct_type;
226 pr("Target sector is a %s constructed %s\n",
227 effadv((int)target->sct_effic), dcp->d_name);
229 plp = (struct plist *)list->q_forw;
230 if (plp->pcp->pl_flags & P_A) {
232 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
233 plp = (struct plist *)qp;
234 if (plp->plane.pln_acc < bestacc)
235 bestacc = plp->plane.pln_acc;
236 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
237 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
239 pr("Some subs are present in the sector.\n");
241 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
243 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
244 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
246 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
248 if (p == 0 || *p == 0) {
259 natp = getnatp(player->cnum);
260 if (target->sct_own) {
261 rel = getrel(natp, target->sct_own);
262 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
263 && (target->sct_own) &&
264 (target->sct_oldown != player->cnum)) {
265 pr("You're not at war with them!\n");
271 pr("no units there\n");
274 land_bomb(list, target);
278 natp = getnatp(player->cnum);
279 if (target->sct_own) {
280 rel = getrel(natp, target->sct_own);
281 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
282 && (target->sct_own) &&
283 (target->sct_oldown != player->cnum)) {
284 pr("You're not at war with them!\n");
290 pr("no planes there\n");
293 plane_bomb(list, target);
297 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
299 pr("no ships there\n");
303 pr("no ships there\n");
307 ship_bomb(list, target);
311 natp = getnatp(player->cnum);
312 if (target->sct_own) {
313 rel = getrel(natp, target->sct_own);
314 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
315 && (target->sct_own) &&
316 (target->sct_oldown != player->cnum)) {
317 pr("You're not at war with them!\n");
323 for (i = 0; i < nbomb; i++) {
324 if (!target->sct_item[bombcomm[i]])
329 pr("No bombable commodities in %s\n",
330 xyas(target->sct_x, target->sct_y, player->cnum));
333 comm_bomb(list, target);
337 natp = getnatp(player->cnum);
338 if (target->sct_own) {
339 rel = getrel(natp, target->sct_own);
340 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
341 && (target->sct_own) &&
342 (target->sct_oldown != player->cnum)) {
343 pr("You're not at war with them!\n");
348 eff_bomb(list, target);
351 pr("Aborting mission.\n");
354 pr("Bad target type.\n");
360 eff_bomb(struct emp_qelem *list, struct sctstr *target)
363 struct emp_qelem *qp;
368 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
369 plp = (struct plist *)qp;
370 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
372 if (plp->bombs || plp->plane.pln_nuketype != -1)
374 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
377 if (dam <= 0) /* dam == 0 if only nukes were delivered */
379 getsect(target->sct_x, target->sct_y, §);
381 oldeff = target->sct_effic;
382 target->sct_effic = effdamage(target->sct_effic, dam);
383 target->sct_avail = effdamage(target->sct_avail, dam);
384 target->sct_road = effdamage(target->sct_road, dam);
385 target->sct_rail = effdamage(target->sct_rail, dam);
386 target->sct_defense = effdamage(target->sct_defense, dam);
387 if (!opt_DEFENSE_INFRA)
388 target->sct_defense = target->sct_effic;
389 pr("did %d%% damage to efficiency in %s\n",
390 oldeff - target->sct_effic,
391 xyas(target->sct_x, target->sct_y, player->cnum));
393 wu(0, target->sct_own,
394 "%s bombing raid did %d%% damage in %s\n",
395 cname(player->cnum), oldeff - target->sct_effic,
396 xyas(target->sct_x, target->sct_y, target->sct_own));
397 if (target->sct_effic < SCT_MINEFF) {
398 if (target->sct_type == SCT_BSPAN)
399 knockdown(target, list);
400 else if (target->sct_type == SCT_BTOWER) {
401 knockdown(target, list);
402 bridgefall(target, list);
406 collateral_damage(target->sct_x, target->sct_y, dam, list);
410 comm_bomb(struct emp_qelem *list, struct sctstr *target)
417 struct emp_qelem *qp;
422 for (i = 0; i < nbomb; i++) {
423 if (target->sct_item[bombcomm[i]] == 0)
425 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
427 ip = &ichr[bombcomm[i]];
428 pr("some %s\n", ip->i_name);
431 ip = whatitem((s_char *)0, "commodity to bomb? ");
437 for (i = 0; i < nbomb; i++) {
438 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
440 if (&ichr[bombcomm[i]] == ip)
444 pr("You can't bomb %s!\n", ip->i_name);
445 for (i = 0; i < nbomb; i++) {
446 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
448 pr(i == 0 ? "Bombable: " : ", ");
449 pr(ichr[bombcomm[i]].i_name);
455 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
456 plp = (struct plist *)qp;
457 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
459 if (plp->bombs || plp->plane.pln_nuketype != -1)
461 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
464 if (dam <= 0) /* dam == 0 if only nukes were delivered */
466 getsect(target->sct_x, target->sct_y, §);
468 before = amt = target->sct_item[ip->i_vtype];
469 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
471 b = 100.0 * (1.0 - ((float)amt / (float)before));
474 pr("did %.2f%% damage to %s in %s\n",
475 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
476 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
477 if (target->sct_own != 0)
478 wu(0, target->sct_own,
479 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
480 cname(player->cnum), b, ip->i_name,
481 xyas(target->sct_x, target->sct_y, target->sct_own));
483 collateral_damage(target->sct_x, target->sct_y, dam, list);
487 ship_bomb(struct emp_qelem *list, struct sctstr *target)
494 struct emp_qelem *qp;
499 struct shiplook head, *s, *s2;
509 memset(&head, 0, sizeof(struct shiplook));
511 for (qp = list->q_forw; qp != list && !player->aborted;
513 if (head.uid != -1) {
515 while (s != (struct shiplook *)0) {
521 memset(&head, 0, sizeof(struct shiplook));
523 plp = (struct plist *)qp;
524 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
526 if (plp->pcp->pl_flags & P_A)
527 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
530 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
532 pr("%s could not find any ships!\n", prplane(&plp->plane));
535 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
536 prplane(&plp->plane), plp->bombs);
539 while (shipno < 0 && !player->aborted && !ignore) {
540 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
547 if (plp->pcp->pl_flags & P_A)
550 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
560 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
561 ship.shp_y == target->sct_y)
568 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
570 shell = ship.shp_item[I_SHELL];
572 shell = supply_commod(ship.shp_own, ship.shp_x,
573 ship.shp_y, I_SHELL, 1);
575 mcp = &mchr[(int)ship.shp_type];
576 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
577 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
578 ship.shp_item[I_SHELL] = shell;
579 putship(ship.shp_uid, &ship);
580 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
581 flak, prship(&ship));
582 PR(ship.shp_own, msg);
583 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
588 if (plp->plane.pln_nuketype != -1)
592 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
593 pr("%d%% hitchance...", hitchance);
595 if (roll(100) <= hitchance) {
596 /* pinbombing is more accurate than normal bombing */
598 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
602 /* Bombs that miss have to land somewhere! */
604 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
606 collateral_damage(target->sct_x, target->sct_y, dam, list);
609 if (dam <= 0) /* dam == 0 if only nukes were delivered */
611 if (mcp->m_flags & M_SUB)
612 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
614 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
616 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
617 cname(player->cnum), dam,
619 xyas(target->sct_x, target->sct_y, ship.shp_own));
622 check_retreat_and_do_shipdamage(&ship, dam);
623 if (ship.shp_rflags & RET_BOMBED)
624 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
625 retreat_ship(&ship, 'b');
626 putship(ship.shp_uid, &ship);
627 getship(ship.shp_uid, &ship);
629 pr("%s at %s sunk!\n",
631 xyas(target->sct_x, target->sct_y, player->cnum));
633 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
638 while (s != (struct shiplook *)0) {
646 plane_bomb(struct emp_qelem *list, struct sctstr *target)
653 struct emp_qelem *qp;
663 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
664 plp = (struct plist *)qp;
665 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
667 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
669 pr("%s could not find any planes!\n", prplane(&plp->plane));
672 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
673 prplane(&plp->plane), plp->bombs);
676 while (planeno < 0 && !player->aborted && !ignore) {
677 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
684 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
692 if (getplane(n, &plane) &&
693 plane.pln_x == target->sct_x &&
694 plane.pln_y == target->sct_y &&
695 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
696 (!ac_isflying(&plane, list)))
699 pr("Plane #%d not spotted\n", n);
704 if (plp->plane.pln_nuketype != -1)
707 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
708 pr("%d%% hitchance...", hitchance);
710 if (roll(100) <= hitchance) {
711 /* pinbombing is more accurate than normal bombing */
713 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
717 /* Bombs that miss have to land somewhere! */
719 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
721 collateral_damage(target->sct_x, target->sct_y, dam, list);
724 if (dam <= 0) /* dam == 0 if only nukes were delivered */
729 if (dam > plane.pln_effic) {
731 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
735 plane.pln_effic -= dam;
736 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
737 if (own == player->cnum) {
738 pr("%s reports %d%% damage\n", prplane(&plane), dam);
742 "%s pinpoint bombing raid did %d%% damage to %s\n",
743 cname(player->cnum), dam, prplane(&plane));
745 nreport(player->cnum, N_DOWN_PLANE, own, 1);
747 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
748 cname(player->cnum), dam, prplane(&plane),
749 xyas(target->sct_x, target->sct_y, own));
750 putplane(plane.pln_uid, &plane);
751 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
758 land_bomb(struct emp_qelem *list, struct sctstr *target)
768 struct emp_qelem *qp;
770 int ignore, flak, hitchance;
775 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
776 plp = (struct plist *)qp;
777 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
779 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
781 pr("%s could not find any units!\n", prplane(&plp->plane));
784 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
785 prplane(&plp->plane), plp->bombs);
788 while (unitno < 0 && !player->aborted && !ignore) {
789 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
796 unitsatxy(target->sct_x, target->sct_y, 0, 0);
804 if (getland(n, &land) &&
805 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
808 pr("Unit #%d not spotted\n", n);
813 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
816 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
817 prland(&land), land.lnd_aaf);
818 PR(land.lnd_own, msg);
819 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
824 if (plp->plane.pln_nuketype != -1)
828 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
829 pr("%d%% hitchance...", hitchance);
831 if (roll(100) <= hitchance) {
833 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
837 /* Bombs that miss have to land somewhere! */
839 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
841 collateral_damage(target->sct_x, target->sct_y, dam, list);
844 if (dam <= 0) /* dam == 0 if only nukes were delivered */
851 "%s pinpoint bombing raid did %d damage to %s\n",
852 cname(player->cnum), dam, prland(&land));
853 check_retreat_and_do_landdamage(&land, dam);
855 if (land.lnd_rflags & RET_BOMBED)
856 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
857 retreat_land(&land, 'b');
858 nreport(player->cnum, N_UNIT_BOMB, own, 1);
859 putland(land.lnd_uid, &land);
860 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
867 strat_bomb(struct emp_qelem *list, struct sctstr *target)
871 struct emp_qelem *qp;
875 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
876 plp = (struct plist *)qp;
877 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
879 if (plp->bombs || plp->plane.pln_nuketype != -1)
881 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
884 if (dam <= 0) /* dam == 0 if only nukes were delivered */
886 getsect(target->sct_x, target->sct_y, §);
889 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
890 cname(player->cnum), PERCENT_DAMAGE(dam),
891 xyas(target->sct_x, target->sct_y, target->sct_own));
893 sectdamage(target, dam, list);
895 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
896 xyas(target->sct_x, target->sct_y, player->cnum));
901 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
902 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
906 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
919 flak -= (pp->pln_def + 1);
920 if (pcp->pl_flags & P_X)
922 if (pcp->pl_flags & P_H)
925 mult = lflaktable[FLAK_MAX] * 1.33;
927 mult = lflaktable[0] * 0.66;
930 mult = lflaktable[flak];
933 dam = (int)((roll(8) + 2) * mult);
938 plane_owner = pp->pln_own;
942 memset(dmess, 0, sizeof(dmess));
946 if (eff < PLANE_MINEFF) {
947 sprintf(dmess, " -- shot down");
949 } else if (chance((100 - eff) / 100.0)) {
950 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
953 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
954 cname(pp->pln_own), prplane(pp), dam, dmess);
955 PR(plane_owner, mesg);
960 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
961 if (pp->pln_ship >= 0) {
962 getship(pp->pln_ship, &ship);
963 take_plane_off_ship(pp, &ship);
965 if (pp->pln_land >= 0) {
966 getland(pp->pln_land, &land);
967 take_plane_off_land(pp, &land);
969 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
971 putplane(pp->pln_uid, pp);
973 putplane(pp->pln_uid, pp);