2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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(*bombcomm);
93 s_char flightpath[MAX_PATH_LEN];
94 struct nstr_item ni_bomb;
95 struct nstr_item ni_esc;
97 struct emp_qelem bomb_list;
98 struct emp_qelem esc_list;
100 struct sctstr ap_sect;
107 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
109 if (!snxtitem(&ni_esc, EF_PLANE,
110 getstarg(player->argp[2], "escort(s)? ", buf)))
111 pr("No escorts...\n");
113 getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
116 if (strchr("ps", mission) == 0)
118 if (!get_assembly_point(player->argp[4], &ap_sect, buf))
122 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING) == 0
127 (void)pathtoxy(flightpath, &tx, &ty, fcost);
128 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
129 getsect(tx, ty, &target);
131 ap_to_target = strlen(flightpath);
132 if (*(flightpath + strlen(flightpath) - 1) == 'h')
134 pr("range to target is %d\n", ap_to_target);
136 * select planes within range
139 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
140 2, wantflags, P_M | P_O);
141 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
142 2, wantflags | P_F | P_ESC, P_M | P_O);
144 * now arm and equip the bombers, transports, whatever.
146 mission_flags |= P_X; /* stealth (shhh) */
147 mission_flags |= P_H; /* gets turned off if not all choppers */
148 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
149 ip, 0, mission_flags);
150 if (QEMPTY(&bomb_list)) {
151 pr("No planes could be equipped for the mission.\n");
154 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
155 ip, P_F | P_ESC, mission_flags);
156 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
158 if (QEMPTY(&bomb_list)) {
159 pr("No planes got through fighter defenses\n");
160 } else if (target.sct_type == SCT_SANCT) {
161 pr("You can't bomb that sector!\n");
165 pin_bomb(&bomb_list, &target);
169 natp = getnatp(player->cnum);
170 if (target.sct_own) {
171 rel = getrel(natp, target.sct_own);
172 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
173 && (target.sct_own) &&
174 (target.sct_oldown != player->cnum)) {
175 pr("You're not at war with them!\n");
182 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
183 strat_bomb(&bomb_list, &target);
186 pr("Bad mission %c\n", mission);
196 pin_bomb(struct emp_qelem *list, struct sctstr *target)
205 struct emp_qelem *qp;
215 type = target->sct_type;
217 pr("Target sector is a %s constructed %s\n",
218 effadv((int)target->sct_effic), dcp->d_name);
220 plp = (struct plist *)list->q_forw;
221 if (plp->pcp->pl_flags & P_A) {
223 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
224 plp = (struct plist *)qp;
225 if (plp->plane.pln_acc < bestacc)
226 bestacc = plp->plane.pln_acc;
227 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
228 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
230 pr("Some subs are present in the sector.\n");
232 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
234 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
235 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
237 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
239 if (p == 0 || *p == 0) {
250 natp = getnatp(player->cnum);
251 if (target->sct_own) {
252 rel = getrel(natp, target->sct_own);
253 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
254 && (target->sct_own) &&
255 (target->sct_oldown != player->cnum)) {
256 pr("You're not at war with them!\n");
262 pr("no units there\n");
265 land_bomb(list, target);
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 planes there\n");
284 plane_bomb(list, target);
288 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
290 pr("no ships there\n");
294 pr("no ships there\n");
298 ship_bomb(list, target);
302 natp = getnatp(player->cnum);
303 if (target->sct_own) {
304 rel = getrel(natp, target->sct_own);
305 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
306 && (target->sct_own) &&
307 (target->sct_oldown != player->cnum)) {
308 pr("You're not at war with them!\n");
314 for (i = 0; i < nbomb; i++) {
315 if (!target->sct_item[bombcomm[i]])
320 pr("No bombable commodities in %s\n",
321 xyas(target->sct_x, target->sct_y, player->cnum));
324 comm_bomb(list, target);
328 natp = getnatp(player->cnum);
329 if (target->sct_own) {
330 rel = getrel(natp, target->sct_own);
331 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
332 && (target->sct_own) &&
333 (target->sct_oldown != player->cnum)) {
334 pr("You're not at war with them!\n");
339 eff_bomb(list, target);
342 pr("Aborting mission.\n");
345 pr("Bad target type.\n");
351 eff_bomb(struct emp_qelem *list, struct sctstr *target)
354 struct emp_qelem *qp;
359 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
360 plp = (struct plist *)qp;
361 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
363 if (plp->bombs || plp->plane.pln_nuketype != -1)
365 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
368 if (dam <= 0) /* dam == 0 if only nukes were delivered */
370 getsect(target->sct_x, target->sct_y, §);
372 oldeff = target->sct_effic;
373 target->sct_effic = effdamage(target->sct_effic, dam);
374 target->sct_avail = effdamage(target->sct_avail, dam);
375 target->sct_road = effdamage(target->sct_road, dam);
376 target->sct_rail = effdamage(target->sct_rail, dam);
377 target->sct_defense = effdamage(target->sct_defense, dam);
378 if (!opt_DEFENSE_INFRA)
379 target->sct_defense = target->sct_effic;
380 pr("did %d%% damage to efficiency in %s\n",
381 oldeff - target->sct_effic,
382 xyas(target->sct_x, target->sct_y, player->cnum));
384 wu(0, target->sct_own,
385 "%s bombing raid did %d%% damage in %s\n",
386 cname(player->cnum), oldeff - target->sct_effic,
387 xyas(target->sct_x, target->sct_y, target->sct_own));
388 if (target->sct_effic < SCT_MINEFF) {
389 if (target->sct_type == SCT_BSPAN)
390 knockdown(target, list);
391 else if (target->sct_type == SCT_BTOWER) {
392 knockdown(target, list);
393 bridgefall(target, list);
397 collateral_damage(target->sct_x, target->sct_y, dam, list);
401 comm_bomb(struct emp_qelem *list, struct sctstr *target)
408 struct emp_qelem *qp;
413 for (i = 0; i < nbomb; i++) {
414 if (target->sct_item[bombcomm[i]] == 0)
416 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
418 ip = &ichr[bombcomm[i]];
419 pr("some %s\n", ip->i_name);
422 ip = whatitem((s_char *)0, "commodity to bomb? ");
428 for (i = 0; i < nbomb; i++) {
429 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
431 if (&ichr[bombcomm[i]] == ip)
435 pr("You can't bomb %s!\n", ip->i_name);
436 for (i = 0; i < nbomb; i++) {
437 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
439 pr(i == 0 ? "Bombable: " : ", ");
440 pr(ichr[bombcomm[i]].i_name);
446 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
447 plp = (struct plist *)qp;
448 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
450 if (plp->bombs || plp->plane.pln_nuketype != -1)
452 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
455 if (dam <= 0) /* dam == 0 if only nukes were delivered */
457 getsect(target->sct_x, target->sct_y, §);
459 before = amt = target->sct_item[ip->i_vtype];
460 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
462 b = 100.0 * (1.0 - ((float)amt / (float)before));
465 pr("did %.2f%% damage to %s in %s\n",
466 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
467 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
468 if (target->sct_own != 0)
469 wu(0, target->sct_own,
470 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
471 cname(player->cnum), b, ip->i_name,
472 xyas(target->sct_x, target->sct_y, target->sct_own));
474 collateral_damage(target->sct_x, target->sct_y, dam, list);
478 ship_bomb(struct emp_qelem *list, struct sctstr *target)
485 struct emp_qelem *qp;
490 struct shiplist *head = NULL;
500 for (qp = list->q_forw; qp != list && !player->aborted;
502 free_shiplist(&head);
503 plp = (struct plist *)qp;
504 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
506 if (plp->pcp->pl_flags & P_A)
507 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
510 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
512 pr("%s could not find any ships!\n", prplane(&plp->plane));
515 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
516 prplane(&plp->plane), plp->bombs);
519 while (shipno < 0 && !player->aborted && !ignore) {
520 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
527 if (plp->pcp->pl_flags & P_A)
528 print_shiplist(head);
530 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
540 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
542 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
543 ship.shp_y == target->sct_y)
548 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
552 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
554 shell = ship.shp_item[I_SHELL];
556 shell = supply_commod(ship.shp_own, ship.shp_x,
557 ship.shp_y, I_SHELL, 1);
559 mcp = &mchr[(int)ship.shp_type];
560 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
561 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
562 ship.shp_item[I_SHELL] = shell;
563 putship(ship.shp_uid, &ship);
564 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
565 flak, prship(&ship));
566 PR(ship.shp_own, msg);
567 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
572 if (plp->plane.pln_nuketype != -1)
576 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
577 pr("%d%% hitchance...", hitchance);
579 if (roll(100) <= hitchance) {
580 /* pinbombing is more accurate than normal bombing */
582 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
586 /* Bombs that miss have to land somewhere! */
588 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
590 collateral_damage(target->sct_x, target->sct_y, dam, list);
593 if (dam <= 0) /* dam == 0 if only nukes were delivered */
595 if (mcp->m_flags & M_SUB)
596 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
598 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
600 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
601 cname(player->cnum), dam,
603 xyas(target->sct_x, target->sct_y, ship.shp_own));
606 check_retreat_and_do_shipdamage(&ship, dam);
607 if (ship.shp_rflags & RET_BOMBED)
608 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
609 retreat_ship(&ship, 'b');
610 putship(ship.shp_uid, &ship);
611 getship(ship.shp_uid, &ship);
613 pr("%s at %s sunk!\n",
615 xyas(target->sct_x, target->sct_y, player->cnum));
617 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
621 free_shiplist(&head);
625 plane_bomb(struct emp_qelem *list, struct sctstr *target)
632 struct emp_qelem *qp;
642 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
643 plp = (struct plist *)qp;
644 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
646 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
648 pr("%s could not find any planes!\n", prplane(&plp->plane));
651 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
652 prplane(&plp->plane), plp->bombs);
655 while (planeno < 0 && !player->aborted && !ignore) {
656 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
663 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
671 if (getplane(n, &plane) &&
672 plane.pln_x == target->sct_x &&
673 plane.pln_y == target->sct_y &&
674 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
675 (!ac_isflying(&plane, list)))
678 pr("Plane #%d not spotted\n", n);
683 if (plp->plane.pln_nuketype != -1)
686 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
687 pr("%d%% hitchance...", hitchance);
689 if (roll(100) <= hitchance) {
690 /* pinbombing is more accurate than normal bombing */
692 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
696 /* Bombs that miss have to land somewhere! */
698 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
700 collateral_damage(target->sct_x, target->sct_y, dam, list);
703 if (dam <= 0) /* dam == 0 if only nukes were delivered */
708 if (dam > plane.pln_effic) {
710 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
714 plane.pln_effic -= dam;
715 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
716 if (own == player->cnum) {
717 pr("%s reports %d%% damage\n", prplane(&plane), dam);
721 "%s pinpoint bombing raid did %d%% damage to %s\n",
722 cname(player->cnum), dam, prplane(&plane));
724 nreport(player->cnum, N_DOWN_PLANE, own, 1);
726 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
727 cname(player->cnum), dam, prplane(&plane),
728 xyas(target->sct_x, target->sct_y, own));
729 putplane(plane.pln_uid, &plane);
730 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
737 land_bomb(struct emp_qelem *list, struct sctstr *target)
747 struct emp_qelem *qp;
749 int ignore, flak, hitchance;
754 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
755 plp = (struct plist *)qp;
756 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
758 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
760 pr("%s could not find any units!\n", prplane(&plp->plane));
763 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
764 prplane(&plp->plane), plp->bombs);
767 while (unitno < 0 && !player->aborted && !ignore) {
768 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
775 unitsatxy(target->sct_x, target->sct_y, 0, 0);
783 if (getland(n, &land) &&
784 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
787 pr("Unit #%d not spotted\n", n);
792 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
795 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
796 prland(&land), land.lnd_aaf);
797 PR(land.lnd_own, msg);
798 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
803 if (plp->plane.pln_nuketype != -1)
807 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
808 pr("%d%% hitchance...", hitchance);
810 if (roll(100) <= hitchance) {
812 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
816 /* Bombs that miss have to land somewhere! */
818 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
820 collateral_damage(target->sct_x, target->sct_y, dam, list);
823 if (dam <= 0) /* dam == 0 if only nukes were delivered */
830 "%s pinpoint bombing raid did %d damage to %s\n",
831 cname(player->cnum), dam, prland(&land));
832 check_retreat_and_do_landdamage(&land, dam);
834 if (land.lnd_rflags & RET_BOMBED)
835 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
836 retreat_land(&land, 'b');
837 nreport(player->cnum, N_UNIT_BOMB, own, 1);
838 putland(land.lnd_uid, &land);
839 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
846 strat_bomb(struct emp_qelem *list, struct sctstr *target)
850 struct emp_qelem *qp;
854 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
855 plp = (struct plist *)qp;
856 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
858 if (plp->bombs || plp->plane.pln_nuketype != -1)
860 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
863 if (dam <= 0) /* dam == 0 if only nukes were delivered */
865 getsect(target->sct_x, target->sct_y, §);
868 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
869 cname(player->cnum), PERCENT_DAMAGE(dam),
870 xyas(target->sct_x, target->sct_y, target->sct_own));
872 sectdamage(target, dam, list);
874 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
875 xyas(target->sct_x, target->sct_y, player->cnum));
880 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
892 flak -= (pp->pln_def + 1);
893 if (pcp->pl_flags & P_X)
895 if (pcp->pl_flags & P_H)
897 dam = ac_flak_dam(flak);
899 plane_owner = pp->pln_own;
903 memset(dmess, 0, sizeof(dmess));
907 if (eff < PLANE_MINEFF) {
908 sprintf(dmess, " -- shot down");
910 } else if (chance((100 - eff) / 100.0)) {
911 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
914 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
915 cname(pp->pln_own), prplane(pp), dam, dmess);
916 PR(plane_owner, mesg);
921 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
922 if (pp->pln_ship >= 0) {
923 getship(pp->pln_ship, &ship);
924 take_plane_off_ship(pp, &ship);
926 if (pp->pln_land >= 0) {
927 getland(pp->pln_land, &land);
928 take_plane_off_land(pp, &land);
930 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
932 putplane(pp->pln_uid, pp);
934 putplane(pp->pln_uid, pp);