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");
112 p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
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)
213 type = target->sct_type;
215 pr("Target sector is a %s constructed %s\n",
216 effadv((int)target->sct_effic), dcp->d_name);
218 plp = (struct plist *)list->q_forw;
219 if (plp->pcp->pl_flags & P_A) {
220 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
221 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
223 pr("Some subs are present in the sector.\n");
225 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
227 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
228 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
230 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
232 if (p == 0 || *p == 0) {
243 natp = getnatp(player->cnum);
244 if (target->sct_own) {
245 rel = getrel(natp, target->sct_own);
246 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
247 && (target->sct_own) &&
248 (target->sct_oldown != player->cnum)) {
249 pr("You're not at war with them!\n");
255 pr("no units there\n");
258 land_bomb(list, target);
262 natp = getnatp(player->cnum);
263 if (target->sct_own) {
264 rel = getrel(natp, target->sct_own);
265 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
266 && (target->sct_own) &&
267 (target->sct_oldown != player->cnum)) {
268 pr("You're not at war with them!\n");
274 pr("no planes there\n");
277 plane_bomb(list, target);
281 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
283 pr("no ships there\n");
287 pr("no ships there\n");
291 ship_bomb(list, target);
295 natp = getnatp(player->cnum);
296 if (target->sct_own) {
297 rel = getrel(natp, target->sct_own);
298 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
299 && (target->sct_own) &&
300 (target->sct_oldown != player->cnum)) {
301 pr("You're not at war with them!\n");
307 for (i = 0; i < nbomb; i++) {
308 if (!target->sct_item[bombcomm[i]])
313 pr("No bombable commodities in %s\n",
314 xyas(target->sct_x, target->sct_y, player->cnum));
317 comm_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");
332 eff_bomb(list, target);
335 pr("Aborting mission.\n");
338 pr("Bad target type.\n");
344 eff_bomb(struct emp_qelem *list, struct sctstr *target)
347 struct emp_qelem *qp;
352 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
353 plp = (struct plist *)qp;
354 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
356 if (plp->bombs || plp->plane.pln_nuketype != -1)
357 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
360 if (dam <= 0) /* dam == 0 if only nukes were delivered */
362 getsect(target->sct_x, target->sct_y, §);
364 oldeff = target->sct_effic;
365 target->sct_effic = effdamage(target->sct_effic, dam);
366 target->sct_avail = effdamage(target->sct_avail, dam);
367 target->sct_road = effdamage(target->sct_road, dam);
368 target->sct_rail = effdamage(target->sct_rail, dam);
369 target->sct_defense = effdamage(target->sct_defense, dam);
370 if (!opt_DEFENSE_INFRA)
371 target->sct_defense = target->sct_effic;
372 pr("did %d%% damage to efficiency in %s\n",
373 oldeff - target->sct_effic,
374 xyas(target->sct_x, target->sct_y, player->cnum));
376 wu(0, target->sct_own,
377 "%s bombing raid did %d%% damage in %s\n",
378 cname(player->cnum), oldeff - target->sct_effic,
379 xyas(target->sct_x, target->sct_y, target->sct_own));
380 if (target->sct_effic < SCT_MINEFF) {
381 if (target->sct_type == SCT_BSPAN)
382 knockdown(target, list);
383 else if (target->sct_type == SCT_BTOWER) {
384 knockdown(target, list);
385 bridgefall(target, list);
389 collateral_damage(target->sct_x, target->sct_y, dam, list);
393 comm_bomb(struct emp_qelem *list, struct sctstr *target)
400 struct emp_qelem *qp;
405 for (i = 0; i < nbomb; i++) {
406 if (target->sct_item[bombcomm[i]] == 0)
408 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
410 ip = &ichr[bombcomm[i]];
411 pr("some %s\n", ip->i_name);
414 ip = whatitem((s_char *)0, "commodity to bomb? ");
420 for (i = 0; i < nbomb; i++) {
421 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
423 if (&ichr[bombcomm[i]] == ip)
427 pr("You can't bomb %s!\n", ip->i_name);
428 for (i = 0; i < nbomb; i++) {
429 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
431 pr(i == 0 ? "Bombable: " : ", ");
432 pr(ichr[bombcomm[i]].i_name);
438 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
439 plp = (struct plist *)qp;
440 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
442 if (plp->bombs || plp->plane.pln_nuketype != -1)
443 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
446 if (dam <= 0) /* dam == 0 if only nukes were delivered */
448 getsect(target->sct_x, target->sct_y, §);
450 before = amt = target->sct_item[ip->i_vtype];
451 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
453 b = 100.0 * (1.0 - ((float)amt / (float)before));
456 pr("did %.2f%% damage to %s in %s\n",
457 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
458 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
459 if (target->sct_own != 0)
460 wu(0, target->sct_own,
461 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
462 cname(player->cnum), b, ip->i_name,
463 xyas(target->sct_x, target->sct_y, target->sct_own));
465 collateral_damage(target->sct_x, target->sct_y, dam, list);
469 ship_bomb(struct emp_qelem *list, struct sctstr *target)
476 struct emp_qelem *qp;
481 struct shiplist *head = NULL;
491 for (qp = list->q_forw; qp != list && !player->aborted;
493 free_shiplist(&head);
494 plp = (struct plist *)qp;
495 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
497 if (plp->pcp->pl_flags & P_A)
498 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
501 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
503 pr("%s could not find any ships!\n", prplane(&plp->plane));
506 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
507 prplane(&plp->plane), plp->bombs);
510 while (shipno < 0 && !player->aborted && !ignore) {
511 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
518 if (plp->pcp->pl_flags & P_A)
519 print_shiplist(head);
521 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
531 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
533 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
534 ship.shp_y == target->sct_y)
539 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
543 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
545 shell = ship.shp_item[I_SHELL];
547 shell = supply_commod(ship.shp_own, ship.shp_x,
548 ship.shp_y, I_SHELL, 1);
550 mcp = &mchr[(int)ship.shp_type];
551 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
552 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
553 ship.shp_item[I_SHELL] = shell;
554 putship(ship.shp_uid, &ship);
555 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
556 flak, prship(&ship));
557 PR(ship.shp_own, msg);
558 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
563 if (plp->plane.pln_nuketype != -1)
566 hitchance = pln_hitchance(&plp->plane,
567 shp_hardtarget(&ship), EF_SHIP);
568 pr("%d%% hitchance...", hitchance);
570 if (roll(100) <= hitchance) {
571 /* pinbombing is more accurate than normal bombing */
572 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
576 /* Bombs that miss have to land somewhere! */
577 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
579 collateral_damage(target->sct_x, target->sct_y, dam, list);
582 if (dam <= 0) /* dam == 0 if only nukes were delivered */
584 if (mcp->m_flags & M_SUB)
585 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
587 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
589 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
590 cname(player->cnum), dam,
592 xyas(target->sct_x, target->sct_y, ship.shp_own));
595 check_retreat_and_do_shipdamage(&ship, dam);
596 if (ship.shp_rflags & RET_BOMBED)
597 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
598 retreat_ship(&ship, 'b');
599 putship(ship.shp_uid, &ship);
600 getship(ship.shp_uid, &ship);
602 pr("%s at %s sunk!\n",
604 xyas(target->sct_x, target->sct_y, player->cnum));
606 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
610 free_shiplist(&head);
614 plane_bomb(struct emp_qelem *list, struct sctstr *target)
621 struct emp_qelem *qp;
631 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
632 plp = (struct plist *)qp;
633 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
635 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
637 pr("%s could not find any planes!\n", prplane(&plp->plane));
640 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
641 prplane(&plp->plane), plp->bombs);
644 while (planeno < 0 && !player->aborted && !ignore) {
645 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
652 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
660 if (getplane(n, &plane) &&
661 plane.pln_x == target->sct_x &&
662 plane.pln_y == target->sct_y &&
663 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
664 (!ac_isflying(&plane, list)))
667 pr("Plane #%d not spotted\n", n);
672 if (plp->plane.pln_nuketype != -1)
675 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
676 pr("%d%% hitchance...", hitchance);
678 if (roll(100) <= hitchance) {
679 /* pinbombing is more accurate than normal bombing */
680 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
684 /* Bombs that miss have to land somewhere! */
685 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
687 collateral_damage(target->sct_x, target->sct_y, dam, list);
690 if (dam <= 0) /* dam == 0 if only nukes were delivered */
695 if (dam > plane.pln_effic) {
697 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
701 plane.pln_effic -= dam;
702 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
703 if (own == player->cnum) {
704 pr("%s reports %d%% damage\n", prplane(&plane), dam);
708 "%s pinpoint bombing raid did %d%% damage to %s\n",
709 cname(player->cnum), dam, prplane(&plane));
711 nreport(player->cnum, N_DOWN_PLANE, own, 1);
713 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
714 cname(player->cnum), dam, prplane(&plane),
715 xyas(target->sct_x, target->sct_y, own));
716 putplane(plane.pln_uid, &plane);
717 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
724 land_bomb(struct emp_qelem *list, struct sctstr *target)
734 struct emp_qelem *qp;
736 int ignore, flak, hitchance;
741 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
742 plp = (struct plist *)qp;
743 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
745 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
747 pr("%s could not find any units!\n", prplane(&plp->plane));
750 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
751 prplane(&plp->plane), plp->bombs);
754 while (unitno < 0 && !player->aborted && !ignore) {
755 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
762 unitsatxy(target->sct_x, target->sct_y, 0, 0);
770 if (getland(n, &land) &&
771 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
774 pr("Unit #%d not spotted\n", n);
779 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
782 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
783 prland(&land), land.lnd_aaf);
784 PR(land.lnd_own, msg);
785 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
790 if (plp->plane.pln_nuketype != -1)
793 hitchance = pln_hitchance(&plp->plane,
794 lnd_hardtarget(&land), EF_LAND);
795 pr("%d%% hitchance...", hitchance);
797 if (roll(100) <= hitchance) {
798 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
802 /* Bombs that miss have to land somewhere! */
803 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
805 collateral_damage(target->sct_x, target->sct_y, dam, list);
808 if (dam <= 0) /* dam == 0 if only nukes were delivered */
815 "%s pinpoint bombing raid did %d damage to %s\n",
816 cname(player->cnum), dam, prland(&land));
817 check_retreat_and_do_landdamage(&land, dam);
819 if (land.lnd_rflags & RET_BOMBED)
820 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
821 retreat_land(&land, 'b');
822 nreport(player->cnum, N_UNIT_BOMB, own, 1);
823 putland(land.lnd_uid, &land);
824 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
831 strat_bomb(struct emp_qelem *list, struct sctstr *target)
835 struct emp_qelem *qp;
839 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
840 plp = (struct plist *)qp;
841 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
843 if (plp->bombs || plp->plane.pln_nuketype != -1)
844 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
847 if (dam <= 0) /* dam == 0 if only nukes were delivered */
849 getsect(target->sct_x, target->sct_y, §);
852 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
853 cname(player->cnum), PERCENT_DAMAGE(dam),
854 xyas(target->sct_x, target->sct_y, target->sct_own));
856 sectdamage(target, dam, list);
858 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
859 xyas(target->sct_x, target->sct_y, player->cnum));
864 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
876 flak -= (pp->pln_def + 1);
877 if (pcp->pl_flags & P_X)
879 if (pcp->pl_flags & P_H)
881 dam = ac_flak_dam(flak);
883 plane_owner = pp->pln_own;
887 memset(dmess, 0, sizeof(dmess));
891 if (eff < PLANE_MINEFF) {
892 sprintf(dmess, " -- shot down");
894 } else if (chance((100 - eff) / 100.0)) {
895 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
898 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
899 cname(pp->pln_own), prplane(pp), dam, dmess);
900 PR(plane_owner, mesg);
905 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
906 if (pp->pln_ship >= 0) {
907 getship(pp->pln_ship, &ship);
908 take_plane_off_ship(pp, &ship);
910 if (pp->pln_land >= 0) {
911 getland(pp->pln_land, &land);
912 take_plane_off_land(pp, &land);
914 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
916 putplane(pp->pln_uid, pp);
918 putplane(pp->pln_uid, pp);