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
57 static void pin_bomb(struct emp_qelem *list, struct sctstr *target);
58 static void strat_bomb(struct emp_qelem *list, struct sctstr *target);
59 static void comm_bomb(struct emp_qelem *list, struct sctstr *target);
60 static void eff_bomb(struct emp_qelem *list, struct sctstr *target);
61 static int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp,
62 natid from, int flak);
63 static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
64 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
65 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
67 static i_type bombcomm[] = {
83 static int nbomb = sizeof(bombcomm) / sizeof(int);
94 s_char flightpath[MAX_PATH_LEN];
95 struct nstr_item ni_bomb;
96 struct nstr_item ni_esc;
99 struct emp_qelem bomb_list;
100 struct emp_qelem esc_list;
102 struct sctstr ap_sect;
109 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
111 if (!snxtitem(&ni_esc, EF_PLANE,
112 getstarg(player->argp[2], "escort(s)? ", buf)))
113 pr("No escorts...\n");
115 getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
118 if (strchr("ps", mission) == 0)
120 if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0
123 if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
125 if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
126 getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
127 pr("Assembly point not owned by you or an ally!\n");
132 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0,
133 0, P_FLYING) == 0 || *flightpath == 0)
137 (void)pathtoxy(flightpath, &tx, &ty, fcost);
138 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
139 getsect(tx, ty, &target);
141 ap_to_target = strlen(flightpath);
142 if (*(flightpath + strlen(flightpath) - 1) == 'h')
144 pr("range to target is %d\n", ap_to_target);
146 * select planes within range
149 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
150 2, wantflags, P_M | P_O);
151 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
152 2, wantflags | P_F | P_ESC, P_M | P_O);
154 * now arm and equip the bombers, transports, whatever.
156 mission_flags |= P_X; /* stealth (shhh) */
157 mission_flags |= P_H; /* gets turned off if not all choppers */
158 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
159 ip, 0, mission_flags);
160 if (QEMPTY(&bomb_list)) {
161 pr("No planes could be equipped for the mission.\n");
164 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
165 ip, P_F | P_ESC, mission_flags);
166 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
168 if (QEMPTY(&bomb_list)) {
169 pr("No planes got through fighter defenses\n");
170 } else if (target.sct_type == SCT_SANCT) {
171 pr("You can't bomb that sector!\n");
175 pin_bomb(&bomb_list, &target);
179 natp = getnatp(player->cnum);
180 if (target.sct_own) {
181 rel = getrel(natp, target.sct_own);
182 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
183 && (target.sct_own) &&
184 (target.sct_oldown != player->cnum)) {
185 pr("You're not at war with them!\n");
192 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
193 strat_bomb(&bomb_list, &target);
196 pr("Bad mission %c\n", mission);
206 pin_bomb(struct emp_qelem *list, struct sctstr *target)
215 struct emp_qelem *qp;
225 type = target->sct_type;
227 pr("Target sector is a %s constructed %s\n",
228 effadv((int)target->sct_effic), dcp->d_name);
230 plp = (struct plist *)list->q_forw;
231 if (plp->pcp->pl_flags & P_A) {
233 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
234 plp = (struct plist *)qp;
235 if (plp->plane.pln_acc < bestacc)
236 bestacc = plp->plane.pln_acc;
237 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
238 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
240 pr("Some subs are present in the sector.\n");
242 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
244 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
245 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
247 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
249 if (p == 0 || *p == 0) {
260 natp = getnatp(player->cnum);
261 if (target->sct_own) {
262 rel = getrel(natp, target->sct_own);
263 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
264 && (target->sct_own) &&
265 (target->sct_oldown != player->cnum)) {
266 pr("You're not at war with them!\n");
272 pr("no units there\n");
275 land_bomb(list, target);
279 natp = getnatp(player->cnum);
280 if (target->sct_own) {
281 rel = getrel(natp, target->sct_own);
282 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
283 && (target->sct_own) &&
284 (target->sct_oldown != player->cnum)) {
285 pr("You're not at war with them!\n");
291 pr("no planes there\n");
294 plane_bomb(list, target);
298 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
300 pr("no ships there\n");
304 pr("no ships there\n");
308 ship_bomb(list, target);
312 natp = getnatp(player->cnum);
313 if (target->sct_own) {
314 rel = getrel(natp, target->sct_own);
315 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
316 && (target->sct_own) &&
317 (target->sct_oldown != player->cnum)) {
318 pr("You're not at war with them!\n");
324 for (i = 0; i < nbomb; i++) {
325 if (!target->sct_item[bombcomm[i]])
330 pr("No bombable commodities in %s\n",
331 xyas(target->sct_x, target->sct_y, player->cnum));
334 comm_bomb(list, target);
338 natp = getnatp(player->cnum);
339 if (target->sct_own) {
340 rel = getrel(natp, target->sct_own);
341 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
342 && (target->sct_own) &&
343 (target->sct_oldown != player->cnum)) {
344 pr("You're not at war with them!\n");
349 eff_bomb(list, target);
352 pr("Aborting mission.\n");
355 pr("Bad target type.\n");
361 eff_bomb(struct emp_qelem *list, struct sctstr *target)
364 struct emp_qelem *qp;
369 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
370 plp = (struct plist *)qp;
371 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
373 if (plp->bombs || plp->plane.pln_nuketype != -1)
375 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
378 if (dam <= 0) /* dam == 0 if only nukes were delivered */
380 getsect(target->sct_x, target->sct_y, §);
382 oldeff = target->sct_effic;
383 target->sct_effic = effdamage(target->sct_effic, dam);
384 target->sct_avail = effdamage(target->sct_avail, dam);
385 target->sct_road = effdamage(target->sct_road, dam);
386 target->sct_rail = effdamage(target->sct_rail, dam);
387 target->sct_defense = effdamage(target->sct_defense, dam);
388 if (!opt_DEFENSE_INFRA)
389 target->sct_defense = target->sct_effic;
390 pr("did %d%% damage to efficiency in %s\n",
391 oldeff - target->sct_effic,
392 xyas(target->sct_x, target->sct_y, player->cnum));
394 wu(0, target->sct_own,
395 "%s bombing raid did %d%% damage in %s\n",
396 cname(player->cnum), oldeff - target->sct_effic,
397 xyas(target->sct_x, target->sct_y, target->sct_own));
398 if (target->sct_effic < SCT_MINEFF) {
399 if (target->sct_type == SCT_BSPAN)
400 knockdown(target, list);
401 else if (target->sct_type == SCT_BTOWER) {
402 knockdown(target, list);
403 bridgefall(target, list);
407 collateral_damage(target->sct_x, target->sct_y, dam, list);
411 comm_bomb(struct emp_qelem *list, struct sctstr *target)
418 struct emp_qelem *qp;
423 for (i = 0; i < nbomb; i++) {
424 if (target->sct_item[bombcomm[i]] == 0)
426 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
428 ip = &ichr[bombcomm[i]];
429 pr("some %s\n", ip->i_name);
432 ip = whatitem((s_char *)0, "commodity to bomb? ");
438 for (i = 0; i < nbomb; i++) {
439 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
441 if (&ichr[bombcomm[i]] == ip)
445 pr("You can't bomb %s!\n", ip->i_name);
446 for (i = 0; i < nbomb; i++) {
447 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
449 pr(i == 0 ? "Bombable: " : ", ");
450 pr(ichr[bombcomm[i]].i_name);
456 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
457 plp = (struct plist *)qp;
458 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
460 if (plp->bombs || plp->plane.pln_nuketype != -1)
462 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
465 if (dam <= 0) /* dam == 0 if only nukes were delivered */
467 getsect(target->sct_x, target->sct_y, §);
469 before = amt = target->sct_item[ip->i_vtype];
470 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
472 b = 100.0 * (1.0 - ((float)amt / (float)before));
475 pr("did %.2f%% damage to %s in %s\n",
476 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
477 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
478 if (target->sct_own != 0)
479 wu(0, target->sct_own,
480 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
481 cname(player->cnum), b, ip->i_name,
482 xyas(target->sct_x, target->sct_y, target->sct_own));
484 collateral_damage(target->sct_x, target->sct_y, dam, list);
488 ship_bomb(struct emp_qelem *list, struct sctstr *target)
496 struct emp_qelem *qp;
501 struct shiplook head, *s, *s2;
511 memset(&head, 0, sizeof(struct shiplook));
513 onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
514 for (qp = list->q_forw; qp != list && !player->aborted;
516 if (head.uid != -1) {
518 while (s != (struct shiplook *)0) {
524 memset(&head, 0, sizeof(struct shiplook));
526 plp = (struct plist *)qp;
527 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
529 if (plp->pcp->pl_flags & P_A)
530 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
533 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
535 pr("%s could not find any ships!\n", prplane(&plp->plane));
538 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
539 prplane(&plp->plane), plp->bombs);
542 while (shipno < 0 && !player->aborted && !ignore) {
543 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
550 if (plp->pcp->pl_flags & P_A)
553 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
563 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
564 ship.shp_y == target->sct_y)
571 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
573 shell = ship.shp_item[I_SHELL];
575 shell = supply_commod(ship.shp_own, ship.shp_x,
576 ship.shp_y, I_SHELL, 1);
578 mcp = &mchr[(int)ship.shp_type];
579 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
580 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
581 ship.shp_item[I_SHELL] = shell;
582 putship(ship.shp_uid, &ship);
583 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
584 flak, prship(&ship));
585 PR(ship.shp_own, msg);
586 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
591 if (plp->plane.pln_nuketype != -1)
595 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
596 pr("%d%% hitchance...", hitchance);
598 if (roll(100) <= hitchance) {
599 /* pinbombing is more accurate than normal bombing */
601 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
605 /* Bombs that miss have to land somewhere! */
607 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
609 collateral_damage(target->sct_x, target->sct_y, dam, list);
612 if (dam <= 0) /* dam == 0 if only nukes were delivered */
614 if (mcp->m_flags & M_SUB)
615 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
617 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
619 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
620 cname(player->cnum), dam,
622 xyas(target->sct_x, target->sct_y, ship.shp_own));
625 check_retreat_and_do_shipdamage(&ship, dam);
626 if (ship.shp_rflags & RET_BOMBED)
627 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
628 retreat_ship(&ship, 'b');
629 putship(ship.shp_uid, &ship);
630 getship(ship.shp_uid, &ship);
632 pr("%s at %s sunk!\n",
634 xyas(target->sct_x, target->sct_y, player->cnum));
636 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
641 while (s != (struct shiplook *)0) {
649 plane_bomb(struct emp_qelem *list, struct sctstr *target)
656 struct emp_qelem *qp;
666 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
667 plp = (struct plist *)qp;
668 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
670 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
672 pr("%s could not find any planes!\n", prplane(&plp->plane));
675 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
676 prplane(&plp->plane), plp->bombs);
679 while (planeno < 0 && !player->aborted && !ignore) {
680 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
687 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
695 if (getplane(n, &plane) &&
696 plane.pln_x == target->sct_x &&
697 plane.pln_y == target->sct_y &&
698 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
699 (!ac_isflying(&plane, list)))
702 pr("Plane #%d not spotted\n", n);
707 if (plp->plane.pln_nuketype != -1)
710 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
711 pr("%d%% hitchance...", hitchance);
713 if (roll(100) <= hitchance) {
714 /* pinbombing is more accurate than normal bombing */
716 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
720 /* Bombs that miss have to land somewhere! */
722 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
724 collateral_damage(target->sct_x, target->sct_y, dam, list);
727 if (dam <= 0) /* dam == 0 if only nukes were delivered */
732 if (dam > plane.pln_effic) {
734 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
738 plane.pln_effic -= dam;
739 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
740 if (own == player->cnum) {
741 pr("%s reports %d%% damage\n", prplane(&plane), dam);
745 "%s pinpoint bombing raid did %d%% damage to %s\n",
746 cname(player->cnum), dam, prplane(&plane));
748 nreport(player->cnum, N_DOWN_PLANE, own, 1);
750 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
751 cname(player->cnum), dam, prplane(&plane),
752 xyas(target->sct_x, target->sct_y, own));
753 putplane(plane.pln_uid, &plane);
754 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
761 land_bomb(struct emp_qelem *list, struct sctstr *target)
772 struct emp_qelem *qp;
774 int ignore, flak, hitchance;
779 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
780 plp = (struct plist *)qp;
781 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
783 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
785 pr("%s could not find any units!\n", prplane(&plp->plane));
788 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
789 prplane(&plp->plane), plp->bombs);
792 while (unitno < 0 && !player->aborted && !ignore) {
793 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
800 unitsatxy(target->sct_x, target->sct_y, 0, 0);
808 if (getland(n, &land) &&
809 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
812 pr("Unit #%d not spotted\n", n);
817 lcp = &lchr[(int)land.lnd_type];
819 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
822 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
823 prland(&land), land.lnd_aaf);
824 PR(land.lnd_own, msg);
825 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
830 if (plp->plane.pln_nuketype != -1)
834 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
835 pr("%d%% hitchance...", hitchance);
837 if (roll(100) <= hitchance) {
839 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
843 /* Bombs that miss have to land somewhere! */
845 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
847 collateral_damage(target->sct_x, target->sct_y, dam, list);
850 if (dam <= 0) /* dam == 0 if only nukes were delivered */
857 "%s pinpoint bombing raid did %d damage to %s\n",
858 cname(player->cnum), dam, prland(&land));
859 check_retreat_and_do_landdamage(&land, dam);
861 if (land.lnd_rflags & RET_BOMBED)
862 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
863 retreat_land(&land, 'b');
864 nreport(player->cnum, N_UNIT_BOMB, own, 1);
865 putland(land.lnd_uid, &land);
866 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
873 strat_bomb(struct emp_qelem *list, struct sctstr *target)
877 struct emp_qelem *qp;
881 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
882 plp = (struct plist *)qp;
883 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
885 if (plp->bombs || plp->plane.pln_nuketype != -1)
887 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
890 if (dam <= 0) /* dam == 0 if only nukes were delivered */
892 getsect(target->sct_x, target->sct_y, §);
895 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
896 cname(player->cnum), PERCENT_DAMAGE(dam),
897 xyas(target->sct_x, target->sct_y, target->sct_own));
899 sectdamage(target, dam, list);
901 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
902 xyas(target->sct_x, target->sct_y, player->cnum));
907 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
908 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
912 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
925 flak -= (pp->pln_def + 1);
926 if (pcp->pl_flags & P_X)
928 if (pcp->pl_flags & P_H)
931 mult = lflaktable[FLAK_MAX] * 1.33;
933 mult = lflaktable[0] * 0.66;
936 mult = lflaktable[flak];
939 dam = (int)((roll(8) + 2) * mult);
944 plane_owner = pp->pln_own;
948 memset(dmess, 0, sizeof(dmess));
952 if (eff < PLANE_MINEFF) {
953 sprintf(dmess, " -- shot down");
955 } else if (chance((100 - eff) / 100.0)) {
956 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
959 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
960 cname(pp->pln_own), prplane(pp), dam, dmess);
961 PR(plane_owner, mesg);
966 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
967 if (pp->pln_ship >= 0) {
968 getship(pp->pln_ship, &ship);
969 take_plane_off_ship(pp, &ship);
971 if (pp->pln_land >= 0) {
972 getland(pp->pln_land, &land);
973 take_plane_off_land(pp, &land);
975 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
977 putplane(pp->pln_uid, pp);
979 putplane(pp->pln_uid, pp);