2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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
34 * Markus Armbruster, 2004-2008
51 static void pin_bomb(struct emp_qelem *list, struct sctstr *target);
52 static void strat_bomb(struct emp_qelem *list, struct sctstr *target);
53 static void comm_bomb(struct emp_qelem *list, struct sctstr *target);
54 static void eff_bomb(struct emp_qelem *list, struct sctstr *target);
55 static int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp,
56 natid from, int flak);
57 static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
58 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
59 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
61 static i_type bombcomm[] = {
77 static int nbomb = sizeof(bombcomm) / sizeof(*bombcomm);
88 char flightpath[MAX_PATH_LEN];
89 struct nstr_item ni_bomb;
90 struct nstr_item ni_esc;
92 struct emp_qelem bomb_list;
93 struct emp_qelem esc_list;
95 struct sctstr ap_sect;
102 if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0)
104 p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
108 if (strchr("ps", mission) == 0)
110 if (!get_assembly_point(player->argp[4], &ap_sect, buf))
114 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING) == 0
119 (void)pathtoxy(flightpath, &tx, &ty, fcost);
120 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
121 getsect(tx, ty, &target);
123 ap_to_target = strlen(flightpath);
124 if (flightpath[ap_to_target - 1] == 'h')
126 pr("range to target is %d\n", ap_to_target);
128 * select planes within range
131 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
132 2, wantflags, P_M | P_O);
133 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
134 2, wantflags | P_F | P_ESC, P_M | P_O);
136 * now arm and equip the bombers, transports, whatever.
138 mission_flags |= P_X; /* stealth (shhh) */
139 mission_flags |= P_H; /* gets turned off if not all choppers */
140 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
141 ip, 0, mission_flags);
142 if (QEMPTY(&bomb_list)) {
143 pr("No planes could be equipped for the mission.\n");
146 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
147 ip, P_F | P_ESC, mission_flags);
148 ac_encounter(&bomb_list, &esc_list, ax, ay,
149 flightpath, mission_flags, 0);
150 if (QEMPTY(&bomb_list)) {
151 pr("No planes got through fighter defenses\n");
152 } else if (target.sct_type == SCT_SANCT) {
153 pr("You can't bomb that sector!\n");
157 pin_bomb(&bomb_list, &target);
161 natp = getnatp(player->cnum);
162 if (target.sct_own) {
163 rel = getrel(natp, target.sct_own);
164 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
165 && (target.sct_own) &&
166 (target.sct_oldown != player->cnum)) {
167 pr("You're not at war with them!\n");
174 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
175 strat_bomb(&bomb_list, &target);
187 pin_bomb(struct emp_qelem *list, struct sctstr *target)
204 type = target->sct_type;
206 pr("Target sector is a %s constructed %s\n",
207 effadv((int)target->sct_effic), dcp->d_name);
209 plp = (struct plist *)list->q_forw;
210 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
211 if (plp->pcp->pl_flags & P_A) {
212 nsubs = shipsatxy(target->sct_x, target->sct_y, M_SUB, 0, 1);
214 pr("Some subs are present in the sector.\n");
216 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
217 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
219 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
232 natp = getnatp(player->cnum);
233 if (target->sct_own) {
234 rel = getrel(natp, target->sct_own);
235 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
236 && (target->sct_own) &&
237 (target->sct_oldown != player->cnum)) {
238 pr("You're not at war with them!\n");
244 pr("no units there\n");
247 land_bomb(list, target);
251 natp = getnatp(player->cnum);
252 if (target->sct_own) {
253 rel = getrel(natp, target->sct_own);
254 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
255 && (target->sct_own) &&
256 (target->sct_oldown != player->cnum)) {
257 pr("You're not at war with them!\n");
263 pr("no planes there\n");
266 plane_bomb(list, target);
270 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
272 pr("no ships there\n");
276 pr("no ships there\n");
280 ship_bomb(list, target);
284 natp = getnatp(player->cnum);
285 if (target->sct_own) {
286 rel = getrel(natp, target->sct_own);
287 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
288 && (target->sct_own) &&
289 (target->sct_oldown != player->cnum)) {
290 pr("You're not at war with them!\n");
296 for (i = 0; i < nbomb; i++) {
297 if (!target->sct_item[bombcomm[i]])
302 pr("No bombable commodities in %s\n",
303 xyas(target->sct_x, target->sct_y, player->cnum));
306 comm_bomb(list, target);
310 natp = getnatp(player->cnum);
311 if (target->sct_own) {
312 rel = getrel(natp, target->sct_own);
313 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
314 && (target->sct_own) &&
315 (target->sct_oldown != player->cnum)) {
316 pr("You're not at war with them!\n");
321 eff_bomb(list, target);
324 pr("Aborting mission.\n");
327 pr("Bad target type.\n");
333 eff_bomb(struct emp_qelem *list, struct sctstr *target)
336 struct emp_qelem *qp;
341 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
342 plp = (struct plist *)qp;
343 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
345 if (plp->bombs || plp->plane.pln_nuketype != -1)
346 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
349 if (dam <= 0) /* dam == 0 if only nukes were delivered */
351 getsect(target->sct_x, target->sct_y, §);
353 oldeff = target->sct_effic;
354 target->sct_effic = effdamage(target->sct_effic, dam);
355 target->sct_avail = effdamage(target->sct_avail, dam);
356 target->sct_road = effdamage(target->sct_road, dam);
357 target->sct_rail = effdamage(target->sct_rail, dam);
358 target->sct_defense = effdamage(target->sct_defense, dam);
359 pr("did %d%% damage to efficiency in %s\n",
360 oldeff - target->sct_effic,
361 xyas(target->sct_x, target->sct_y, player->cnum));
363 wu(0, target->sct_own,
364 "%s bombing raid did %d%% damage in %s\n",
365 cname(player->cnum), oldeff - target->sct_effic,
366 xyas(target->sct_x, target->sct_y, target->sct_own));
367 bridge_damaged(target);
369 collateral_damage(target->sct_x, target->sct_y, dam);
373 comm_bomb(struct emp_qelem *list, struct sctstr *target)
380 struct emp_qelem *qp;
385 for (i = 0; i < nbomb; i++) {
386 if (target->sct_item[bombcomm[i]] == 0)
388 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
390 ip = &ichr[bombcomm[i]];
391 pr("some %s\n", ip->i_name);
394 ip = whatitem(NULL, "commodity to bomb? ");
400 for (i = 0; i < nbomb; i++) {
401 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
403 if (&ichr[bombcomm[i]] == ip)
407 pr("You can't bomb %s!\n", ip->i_name);
408 for (i = 0; i < nbomb; i++) {
409 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
411 pr("%s%s", i == 0 ? "Bombable: " : ", ",
412 ichr[bombcomm[i]].i_name);
418 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
419 plp = (struct plist *)qp;
420 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
422 if (plp->bombs || plp->plane.pln_nuketype != -1)
423 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
426 if (dam <= 0) /* dam == 0 if only nukes were delivered */
428 getsect(target->sct_x, target->sct_y, §);
430 before = target->sct_item[ip->i_uid];
431 target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
433 b = 100.0 * (1.0 - (double)amt / (double)before);
436 pr("did %.2f%% damage to %s in %s\n",
437 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
438 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
439 if (target->sct_own != 0)
440 wu(0, target->sct_own,
441 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
442 cname(player->cnum), b, ip->i_name,
443 xyas(target->sct_x, target->sct_y, target->sct_own));
445 collateral_damage(target->sct_x, target->sct_y, dam);
449 ship_bomb(struct emp_qelem *list, struct sctstr *target)
456 struct emp_qelem *qp;
461 struct shiplist *head = NULL;
470 for (qp = list->q_forw; qp != list && !player->aborted;
472 free_shiplist(&head);
473 plp = (struct plist *)qp;
474 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
476 if (plp->pcp->pl_flags & P_A)
477 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
480 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
482 pr("%s could not find any ships!\n", prplane(&plp->plane));
485 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
486 prplane(&plp->plane), plp->bombs);
489 while (shipno < 0 && !player->aborted && !ignore) {
490 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
497 if (plp->pcp->pl_flags & P_A)
498 print_shiplist(head);
500 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
510 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
512 if (getship(n, &ship) && ship.shp_own &&
513 ship.shp_x == target->sct_x && ship.shp_y == target->sct_y)
518 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
522 gun = shp_usable_guns(&ship);
524 shell = ship.shp_item[I_SHELL];
526 shell = supply_commod(ship.shp_own,
527 ship.shp_x, ship.shp_y, I_SHELL, 1);
529 mcp = &mchr[(int)ship.shp_type];
530 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
531 flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
532 ship.shp_item[I_SHELL] = shell;
533 putship(ship.shp_uid, &ship);
534 PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
535 flak, prship(&ship));
536 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
541 if (plp->plane.pln_nuketype != -1)
544 hitchance = pln_hitchance(&plp->plane,
545 shp_hardtarget(&ship), EF_SHIP);
546 pr("%d%% hitchance...", hitchance);
548 if (roll(100) <= hitchance) {
549 /* pinbombing is more accurate than normal bombing */
550 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
554 /* Bombs that miss have to land somewhere! */
555 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
557 collateral_damage(target->sct_x, target->sct_y, dam);
560 if (dam <= 0) /* dam == 0 if only nukes were delivered */
562 if (mcp->m_flags & M_SUB)
563 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
565 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
567 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
568 cname(player->cnum), dam,
570 xyas(target->sct_x, target->sct_y, ship.shp_own));
573 check_retreat_and_do_shipdamage(&ship, dam);
574 if (ship.shp_rflags & RET_BOMBED)
575 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
576 retreat_ship(&ship, 'b');
577 putship(ship.shp_uid, &ship);
578 getship(ship.shp_uid, &ship);
580 pr("%s at %s sunk!\n",
582 xyas(target->sct_x, target->sct_y, player->cnum));
584 collateral_damage(target->sct_x, target->sct_y, dam / 2);
588 free_shiplist(&head);
592 plane_bomb(struct emp_qelem *list, struct sctstr *target)
599 struct emp_qelem *qp;
609 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
610 plp = (struct plist *)qp;
611 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
613 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
615 pr("%s could not find any planes!\n", prplane(&plp->plane));
618 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
619 prplane(&plp->plane), plp->bombs);
622 while (planeno < 0 && !player->aborted && !ignore) {
623 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
630 planesatxy(target->sct_x, target->sct_y, 0, 0);
638 if (getplane(n, &plane) &&
639 plane.pln_x == target->sct_x &&
640 plane.pln_y == target->sct_y &&
641 !(plane.pln_flags & PLN_LAUNCHED))
644 pr("Plane #%d not spotted\n", n);
649 if (plp->plane.pln_nuketype != -1)
652 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
653 pr("%d%% hitchance...", hitchance);
655 if (roll(100) <= hitchance) {
656 /* pinbombing is more accurate than normal bombing */
657 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
661 /* Bombs that miss have to land somewhere! */
662 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
664 collateral_damage(target->sct_x, target->sct_y, dam);
667 if (dam <= 0) /* dam == 0 if only nukes were delivered */
672 if (dam > plane.pln_effic)
675 plane.pln_effic -= dam;
676 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
677 if (own == player->cnum) {
678 pr("%s reports %d%% damage\n", prplane(&plane), dam);
682 "%s pinpoint bombing raid did %d%% damage to %s\n",
683 cname(player->cnum), dam, prplane(&plane));
685 nreport(player->cnum, N_DOWN_PLANE, own, 1);
687 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
688 cname(player->cnum), dam, prplane(&plane),
689 xyas(target->sct_x, target->sct_y, own));
690 putplane(plane.pln_uid, &plane);
691 collateral_damage(target->sct_x, target->sct_y, dam);
698 land_bomb(struct emp_qelem *list, struct sctstr *target)
707 struct emp_qelem *qp;
709 int ignore, aaf, flak, hitchance;
714 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
715 plp = (struct plist *)qp;
716 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
718 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
720 pr("%s could not find any units!\n", prplane(&plp->plane));
723 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
724 prplane(&plp->plane), plp->bombs);
727 while (unitno < 0 && !player->aborted && !ignore) {
728 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
735 unitsatxy(target->sct_x, target->sct_y, 0, 0);
743 if (getland(n, &land) && land.lnd_own &&
744 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
747 pr("Unit #%d not spotted\n", n);
752 aaf = lnd_aaf(&land);
753 flak = (int)(techfact(land.lnd_tech, aaf) * 3.0);
756 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
758 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
763 if (plp->plane.pln_nuketype != -1)
766 hitchance = pln_hitchance(&plp->plane,
767 lnd_hardtarget(&land), EF_LAND);
768 pr("%d%% hitchance...", hitchance);
770 if (roll(100) <= hitchance) {
771 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
775 /* Bombs that miss have to land somewhere! */
776 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
778 collateral_damage(target->sct_x, target->sct_y, dam);
781 if (dam <= 0) /* dam == 0 if only nukes were delivered */
786 mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
787 cname(player->cnum), dam, prland(&land));
788 check_retreat_and_do_landdamage(&land, dam);
790 if (land.lnd_rflags & RET_BOMBED)
791 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
792 retreat_land(&land, 'b');
793 nreport(player->cnum, N_UNIT_BOMB, own, 1);
794 putland(land.lnd_uid, &land);
795 collateral_damage(target->sct_x, target->sct_y, dam);
802 strat_bomb(struct emp_qelem *list, struct sctstr *target)
806 struct emp_qelem *qp;
810 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
811 plp = (struct plist *)qp;
812 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
814 if (plp->bombs || plp->plane.pln_nuketype != -1)
815 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
818 if (dam <= 0) /* dam == 0 if only nukes were delivered */
820 getsect(target->sct_x, target->sct_y, §);
823 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
824 cname(player->cnum), PERCENT_DAMAGE(dam),
825 xyas(target->sct_x, target->sct_y, target->sct_own));
827 sectdamage(target, dam);
829 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
830 xyas(target->sct_x, target->sct_y, player->cnum));
835 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
844 dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
846 plane_owner = pp->pln_own;
850 memset(dmess, 0, sizeof(dmess));
854 if (eff < PLANE_MINEFF) {
855 sprintf(dmess, " -- shot down");
857 } else if (chance((100 - eff) / 100.0)) {
858 sprintf(dmess, " -- aborted with %d%% damage", 100 - eff);
861 PR(plane_owner, " Flak! %s %s takes %d%s.\n",
862 cname(pp->pln_own), prplane(pp), dam, dmess);
867 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
869 putplane(pp->pln_uid, pp);