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, 0, P_FLYING) == 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 shiplist *head = NULL;
509 for (qp = list->q_forw; qp != list && !player->aborted;
511 free_shiplist(&head);
512 plp = (struct plist *)qp;
513 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
515 if (plp->pcp->pl_flags & P_A)
516 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
519 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
521 pr("%s could not find any ships!\n", prplane(&plp->plane));
524 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
525 prplane(&plp->plane), plp->bombs);
528 while (shipno < 0 && !player->aborted && !ignore) {
529 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
536 if (plp->pcp->pl_flags & P_A)
537 print_shiplist(head);
539 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
549 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
551 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
552 ship.shp_y == target->sct_y)
557 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
561 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
563 shell = ship.shp_item[I_SHELL];
565 shell = supply_commod(ship.shp_own, ship.shp_x,
566 ship.shp_y, I_SHELL, 1);
568 mcp = &mchr[(int)ship.shp_type];
569 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
570 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
571 ship.shp_item[I_SHELL] = shell;
572 putship(ship.shp_uid, &ship);
573 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
574 flak, prship(&ship));
575 PR(ship.shp_own, msg);
576 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
581 if (plp->plane.pln_nuketype != -1)
585 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
586 pr("%d%% hitchance...", hitchance);
588 if (roll(100) <= hitchance) {
589 /* pinbombing is more accurate than normal bombing */
591 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
595 /* Bombs that miss have to land somewhere! */
597 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
599 collateral_damage(target->sct_x, target->sct_y, dam, list);
602 if (dam <= 0) /* dam == 0 if only nukes were delivered */
604 if (mcp->m_flags & M_SUB)
605 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
607 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
609 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
610 cname(player->cnum), dam,
612 xyas(target->sct_x, target->sct_y, ship.shp_own));
615 check_retreat_and_do_shipdamage(&ship, dam);
616 if (ship.shp_rflags & RET_BOMBED)
617 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
618 retreat_ship(&ship, 'b');
619 putship(ship.shp_uid, &ship);
620 getship(ship.shp_uid, &ship);
622 pr("%s at %s sunk!\n",
624 xyas(target->sct_x, target->sct_y, player->cnum));
626 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
630 free_shiplist(&head);
634 plane_bomb(struct emp_qelem *list, struct sctstr *target)
641 struct emp_qelem *qp;
651 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
652 plp = (struct plist *)qp;
653 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
655 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
657 pr("%s could not find any planes!\n", prplane(&plp->plane));
660 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
661 prplane(&plp->plane), plp->bombs);
664 while (planeno < 0 && !player->aborted && !ignore) {
665 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
672 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
680 if (getplane(n, &plane) &&
681 plane.pln_x == target->sct_x &&
682 plane.pln_y == target->sct_y &&
683 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
684 (!ac_isflying(&plane, list)))
687 pr("Plane #%d not spotted\n", n);
692 if (plp->plane.pln_nuketype != -1)
695 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
696 pr("%d%% hitchance...", hitchance);
698 if (roll(100) <= hitchance) {
699 /* pinbombing is more accurate than normal bombing */
701 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
705 /* Bombs that miss have to land somewhere! */
707 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
709 collateral_damage(target->sct_x, target->sct_y, dam, list);
712 if (dam <= 0) /* dam == 0 if only nukes were delivered */
717 if (dam > plane.pln_effic) {
719 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
723 plane.pln_effic -= dam;
724 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
725 if (own == player->cnum) {
726 pr("%s reports %d%% damage\n", prplane(&plane), dam);
730 "%s pinpoint bombing raid did %d%% damage to %s\n",
731 cname(player->cnum), dam, prplane(&plane));
733 nreport(player->cnum, N_DOWN_PLANE, own, 1);
735 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
736 cname(player->cnum), dam, prplane(&plane),
737 xyas(target->sct_x, target->sct_y, own));
738 putplane(plane.pln_uid, &plane);
739 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
746 land_bomb(struct emp_qelem *list, struct sctstr *target)
756 struct emp_qelem *qp;
758 int ignore, flak, hitchance;
763 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
764 plp = (struct plist *)qp;
765 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
767 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
769 pr("%s could not find any units!\n", prplane(&plp->plane));
772 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
773 prplane(&plp->plane), plp->bombs);
776 while (unitno < 0 && !player->aborted && !ignore) {
777 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
784 unitsatxy(target->sct_x, target->sct_y, 0, 0);
792 if (getland(n, &land) &&
793 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
796 pr("Unit #%d not spotted\n", n);
801 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
804 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
805 prland(&land), land.lnd_aaf);
806 PR(land.lnd_own, msg);
807 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
812 if (plp->plane.pln_nuketype != -1)
816 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
817 pr("%d%% hitchance...", hitchance);
819 if (roll(100) <= hitchance) {
821 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
825 /* Bombs that miss have to land somewhere! */
827 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
829 collateral_damage(target->sct_x, target->sct_y, dam, list);
832 if (dam <= 0) /* dam == 0 if only nukes were delivered */
839 "%s pinpoint bombing raid did %d damage to %s\n",
840 cname(player->cnum), dam, prland(&land));
841 check_retreat_and_do_landdamage(&land, dam);
843 if (land.lnd_rflags & RET_BOMBED)
844 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
845 retreat_land(&land, 'b');
846 nreport(player->cnum, N_UNIT_BOMB, own, 1);
847 putland(land.lnd_uid, &land);
848 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
855 strat_bomb(struct emp_qelem *list, struct sctstr *target)
859 struct emp_qelem *qp;
863 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
864 plp = (struct plist *)qp;
865 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
867 if (plp->bombs || plp->plane.pln_nuketype != -1)
869 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
872 if (dam <= 0) /* dam == 0 if only nukes were delivered */
874 getsect(target->sct_x, target->sct_y, §);
877 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
878 cname(player->cnum), PERCENT_DAMAGE(dam),
879 xyas(target->sct_x, target->sct_y, target->sct_own));
881 sectdamage(target, dam, list);
883 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
884 xyas(target->sct_x, target->sct_y, player->cnum));
889 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
901 flak -= (pp->pln_def + 1);
902 if (pcp->pl_flags & P_X)
904 if (pcp->pl_flags & P_H)
906 dam = ac_flak_dam(flak);
908 plane_owner = pp->pln_own;
912 memset(dmess, 0, sizeof(dmess));
916 if (eff < PLANE_MINEFF) {
917 sprintf(dmess, " -- shot down");
919 } else if (chance((100 - eff) / 100.0)) {
920 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
923 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
924 cname(pp->pln_own), prplane(pp), dam, dmess);
925 PR(plane_owner, mesg);
930 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
931 if (pp->pln_ship >= 0) {
932 getship(pp->pln_ship, &ship);
933 take_plane_off_ship(pp, &ship);
935 if (pp->pln_land >= 0) {
936 getland(pp->pln_land, &land);
937 take_plane_off_land(pp, &land);
939 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
941 putplane(pp->pln_uid, pp);
943 putplane(pp->pln_uid, pp);