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)
224 struct emp_qelem *qp;
234 type = target->sct_type;
236 pr("Target sector is a %s constructed %s\n",
237 effadv((int)target->sct_effic), dcp->d_name);
239 plp = (struct plist *)list->q_forw;
240 if (plp->pcp->pl_flags & P_A) {
242 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
243 plp = (struct plist *)qp;
244 if (plp->plane.pln_acc < bestacc)
245 bestacc = plp->plane.pln_acc;
246 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
247 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
249 pr("Some subs are present in the sector.\n");
251 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
253 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
254 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
256 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
258 if (p == 0 || *p == 0) {
269 natp = getnatp(player->cnum);
270 if (target->sct_own) {
271 rel = getrel(natp, target->sct_own);
272 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
273 && (target->sct_own) &&
274 (target->sct_oldown != player->cnum)) {
275 pr("You're not at war with them!\n");
281 pr("no units there\n");
284 land_bomb(list, target);
288 natp = getnatp(player->cnum);
289 if (target->sct_own) {
290 rel = getrel(natp, target->sct_own);
291 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
292 && (target->sct_own) &&
293 (target->sct_oldown != player->cnum)) {
294 pr("You're not at war with them!\n");
300 pr("no planes there\n");
303 plane_bomb(list, target);
307 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
309 pr("no ships there\n");
313 pr("no ships there\n");
317 ship_bomb(list, target);
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");
333 for (i = 0; i < nbomb; i++) {
334 if (!target->sct_item[bombcomm[i]])
339 pr("No bombable commodities in %s\n",
340 xyas(target->sct_x, target->sct_y, player->cnum));
343 comm_bomb(list, target);
347 natp = getnatp(player->cnum);
348 if (target->sct_own) {
349 rel = getrel(natp, target->sct_own);
350 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
351 && (target->sct_own) &&
352 (target->sct_oldown != player->cnum)) {
353 pr("You're not at war with them!\n");
358 eff_bomb(list, target);
361 pr("Aborting mission.\n");
364 pr("Bad target type.\n");
370 eff_bomb(struct emp_qelem *list, struct sctstr *target)
372 register struct plist *plp;
373 struct emp_qelem *qp;
378 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
379 plp = (struct plist *)qp;
380 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
382 if (plp->bombs || plp->plane.pln_nuketype != -1)
384 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
387 if (dam <= 0) /* dam == 0 if only nukes were delivered */
389 getsect(target->sct_x, target->sct_y, §);
391 oldeff = target->sct_effic;
392 target->sct_effic = effdamage(target->sct_effic, dam);
393 target->sct_avail = effdamage(target->sct_avail, dam);
394 target->sct_road = effdamage(target->sct_road, dam);
395 target->sct_rail = effdamage(target->sct_rail, dam);
396 target->sct_defense = effdamage(target->sct_defense, dam);
397 if (!opt_DEFENSE_INFRA)
398 target->sct_defense = target->sct_effic;
399 pr("did %d%% damage to efficiency in %s\n",
400 oldeff - target->sct_effic,
401 xyas(target->sct_x, target->sct_y, player->cnum));
403 wu(0, target->sct_own,
404 "%s bombing raid did %d%% damage in %s\n",
405 cname(player->cnum), oldeff - target->sct_effic,
406 xyas(target->sct_x, target->sct_y, target->sct_own));
407 if (target->sct_effic < SCT_MINEFF) {
408 if (target->sct_type == SCT_BSPAN)
409 knockdown(target, list);
410 else if (target->sct_type == SCT_BTOWER) {
411 knockdown(target, list);
412 bridgefall(target, list);
416 collateral_damage(target->sct_x, target->sct_y, dam, list);
420 comm_bomb(struct emp_qelem *list, struct sctstr *target)
422 register struct plist *plp;
427 struct emp_qelem *qp;
432 for (i = 0; i < nbomb; i++) {
433 if (target->sct_item[bombcomm[i]] == 0)
435 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
437 ip = &ichr[bombcomm[i]];
438 pr("some %s\n", ip->i_name);
441 ip = whatitem((s_char *)0, "commodity to bomb? ");
447 for (i = 0; i < nbomb; i++) {
448 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
450 if (&ichr[bombcomm[i]] == ip)
454 pr("You can't bomb %s!\n", ip->i_name);
455 for (i = 0; i < nbomb; i++) {
456 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
458 pr(i == 0 ? "Bombable: " : ", ");
459 pr(ichr[bombcomm[i]].i_name);
465 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
466 plp = (struct plist *)qp;
467 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
469 if (plp->bombs || plp->plane.pln_nuketype != -1)
471 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
474 if (dam <= 0) /* dam == 0 if only nukes were delivered */
476 getsect(target->sct_x, target->sct_y, §);
478 before = amt = target->sct_item[ip->i_vtype];
479 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
481 b = 100.0 * (1.0 - ((float)amt / (float)before));
484 pr("did %.2f%% damage to %s in %s\n",
485 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
486 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
487 if (target->sct_own != 0)
488 wu(0, target->sct_own,
489 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
490 cname(player->cnum), b, ip->i_name,
491 xyas(target->sct_x, target->sct_y, target->sct_own));
493 collateral_damage(target->sct_x, target->sct_y, dam, list);
497 ship_bomb(struct emp_qelem *list, struct sctstr *target)
505 struct emp_qelem *qp;
510 struct shiplook head, *s, *s2;
520 memset(&head, 0, sizeof(struct shiplook));
522 onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
523 for (qp = list->q_forw; qp != list && !player->aborted;
525 if (head.uid != -1) {
527 while (s != (struct shiplook *)0) {
533 memset(&head, 0, sizeof(struct shiplook));
535 plp = (struct plist *)qp;
536 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
538 if (plp->pcp->pl_flags & P_A)
539 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
542 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
544 pr("%s could not find any ships!\n", prplane(&plp->plane));
547 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
548 prplane(&plp->plane), plp->bombs);
551 while (shipno < 0 && !player->aborted && !ignore) {
552 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
559 if (plp->pcp->pl_flags & P_A)
562 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
572 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
573 ship.shp_y == target->sct_y)
580 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
582 shell = ship.shp_item[I_SHELL];
584 shell = supply_commod(ship.shp_own, ship.shp_x,
585 ship.shp_y, I_SHELL, 1);
587 mcp = &mchr[(int)ship.shp_type];
588 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
589 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
590 ship.shp_item[I_SHELL] = shell;
591 putship(ship.shp_uid, &ship);
592 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
593 flak, prship(&ship));
594 PR(ship.shp_own, msg);
595 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
600 if (plp->plane.pln_nuketype != -1)
604 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
605 pr("%d%% hitchance...", hitchance);
607 if (roll(100) <= hitchance) {
608 /* pinbombing is more accurate than normal bombing */
610 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
614 /* Bombs that miss have to land somewhere! */
616 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
618 collateral_damage(target->sct_x, target->sct_y, dam, list);
621 if (dam <= 0) /* dam == 0 if only nukes were delivered */
623 if (mcp->m_flags & M_SUB)
624 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
626 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
628 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
629 cname(player->cnum), dam,
631 xyas(target->sct_x, target->sct_y, ship.shp_own));
634 check_retreat_and_do_shipdamage(&ship, dam);
635 if (ship.shp_rflags & RET_BOMBED)
636 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
637 retreat_ship(&ship, 'b');
638 putship(ship.shp_uid, &ship);
641 pr("%s at %s sunk!\n",
643 xyas(target->sct_x, target->sct_y, player->cnum));
645 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
650 while (s != (struct shiplook *)0) {
658 plane_bomb(struct emp_qelem *list, struct sctstr *target)
665 struct emp_qelem *qp;
675 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
676 plp = (struct plist *)qp;
677 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
679 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
681 pr("%s could not find any planes!\n", prplane(&plp->plane));
684 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
685 prplane(&plp->plane), plp->bombs);
688 while (planeno < 0 && !player->aborted && !ignore) {
689 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
696 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
704 if (getplane(n, &plane) &&
705 plane.pln_x == target->sct_x &&
706 plane.pln_y == target->sct_y &&
707 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
708 (!ac_isflying(&plane, list)))
711 pr("Plane #%d not spotted\n", n);
716 if (plp->plane.pln_nuketype != -1)
719 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
720 pr("%d%% hitchance...", hitchance);
722 if (roll(100) <= hitchance) {
723 /* pinbombing is more accurate than normal bombing */
725 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
729 /* Bombs that miss have to land somewhere! */
731 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
733 collateral_damage(target->sct_x, target->sct_y, dam, list);
736 if (dam <= 0) /* dam == 0 if only nukes were delivered */
741 if (dam > plane.pln_effic) {
743 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
747 plane.pln_effic -= dam;
748 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
749 if (own == player->cnum) {
750 pr("%s reports %d%% damage\n", prplane(&plane), dam);
754 "%s pinpoint bombing raid did %d%% damage to %s\n",
755 cname(player->cnum), dam, prplane(&plane));
757 nreport(player->cnum, N_DOWN_PLANE, own, 1);
759 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
760 cname(player->cnum), dam, prplane(&plane),
761 xyas(target->sct_x, target->sct_y, own));
762 putplane(plane.pln_uid, &plane);
763 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
770 land_bomb(struct emp_qelem *list, struct sctstr *target)
781 struct emp_qelem *qp;
783 int ignore, flak, hitchance;
788 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
789 plp = (struct plist *)qp;
790 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
792 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
794 pr("%s could not find any units!\n", prplane(&plp->plane));
797 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
798 prplane(&plp->plane), plp->bombs);
801 while (unitno < 0 && !player->aborted && !ignore) {
802 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
809 unitsatxy(target->sct_x, target->sct_y, 0, 0);
817 if (getland(n, &land) &&
818 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
821 pr("Unit #%d not spotted\n", n);
826 lcp = &lchr[(int)land.lnd_type];
828 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
831 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
832 prland(&land), land.lnd_aaf);
833 PR(land.lnd_own, msg);
834 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
839 if (plp->plane.pln_nuketype != -1)
843 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
844 pr("%d%% hitchance...", hitchance);
846 if (roll(100) <= hitchance) {
848 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
852 /* Bombs that miss have to land somewhere! */
854 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
856 collateral_damage(target->sct_x, target->sct_y, dam, list);
859 if (dam <= 0) /* dam == 0 if only nukes were delivered */
866 "%s pinpoint bombing raid did %d damage to %s\n",
867 cname(player->cnum), dam, prland(&land));
868 check_retreat_and_do_landdamage(&land, dam);
870 if (land.lnd_rflags & RET_BOMBED)
871 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
872 retreat_land(&land, 'b');
873 nreport(player->cnum, N_UNIT_BOMB, own, 1);
874 putland(land.lnd_uid, &land);
875 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
882 strat_bomb(struct emp_qelem *list, struct sctstr *target)
884 register struct plist *plp;
886 struct emp_qelem *qp;
890 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
891 plp = (struct plist *)qp;
892 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
894 if (plp->bombs || plp->plane.pln_nuketype != -1)
896 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
899 if (dam <= 0) /* dam == 0 if only nukes were delivered */
901 getsect(target->sct_x, target->sct_y, §);
904 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
905 cname(player->cnum), PERCENT_DAMAGE(dam),
906 xyas(target->sct_x, target->sct_y, target->sct_own));
908 sectdamage(target, dam, list);
910 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
911 xyas(target->sct_x, target->sct_y, player->cnum));
916 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
917 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
921 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
934 flak -= (pp->pln_def + 1);
935 if (pcp->pl_flags & P_X)
937 if (pcp->pl_flags & P_H)
940 mult = lflaktable[FLAK_MAX] * 1.33;
942 mult = lflaktable[0] * 0.66;
945 mult = lflaktable[flak];
948 dam = (int)((roll(8) + 2) * mult);
953 plane_owner = pp->pln_own;
957 memset(dmess, 0, sizeof(dmess));
961 if (eff < PLANE_MINEFF) {
962 sprintf(dmess, " -- shot down");
964 } else if (chance((100 - eff) / 100.0)) {
965 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
968 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
969 cname(pp->pln_own), prplane(pp), dam, dmess);
970 PR(plane_owner, mesg);
975 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
976 if (pp->pln_ship >= 0) {
977 getship(pp->pln_ship, &ship);
978 take_plane_off_ship(pp, &ship);
980 if (pp->pln_land >= 0) {
981 getland(pp->pln_land, &land);
982 take_plane_off_land(pp, &land);
984 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
986 putplane(pp->pln_uid, pp);
988 putplane(pp->pln_uid, pp);