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
50 static void pin_bomb(struct emp_qelem *list, struct sctstr *target);
51 static void strat_bomb(struct emp_qelem *list, struct sctstr *target);
52 static void comm_bomb(struct emp_qelem *list, struct sctstr *target);
53 static void eff_bomb(struct emp_qelem *list, struct sctstr *target);
54 static int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp,
55 natid from, int flak);
56 static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
57 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
58 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
60 static i_type bombcomm[] = {
76 static int nbomb = sizeof(bombcomm) / sizeof(*bombcomm);
87 char flightpath[MAX_PATH_LEN];
88 struct nstr_item ni_bomb;
89 struct nstr_item ni_esc;
91 struct emp_qelem bomb_list;
92 struct emp_qelem esc_list;
94 struct sctstr ap_sect;
101 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
103 if (!snxtitem(&ni_esc, EF_PLANE,
104 getstarg(player->argp[2], "escort(s)? ", buf)))
105 pr("No escorts...\n");
106 p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
110 if (strchr("ps", mission) == 0)
112 if (!get_assembly_point(player->argp[4], &ap_sect, buf))
116 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING) == 0
121 (void)pathtoxy(flightpath, &tx, &ty, fcost);
122 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
123 getsect(tx, ty, &target);
125 ap_to_target = strlen(flightpath);
126 if (flightpath[ap_to_target - 1] == 'h')
128 pr("range to target is %d\n", ap_to_target);
130 * select planes within range
133 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
134 2, wantflags, P_M | P_O);
135 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
136 2, wantflags | P_F | P_ESC, P_M | P_O);
138 * now arm and equip the bombers, transports, whatever.
140 mission_flags |= P_X; /* stealth (shhh) */
141 mission_flags |= P_H; /* gets turned off if not all choppers */
142 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
143 ip, 0, mission_flags);
144 if (QEMPTY(&bomb_list)) {
145 pr("No planes could be equipped for the mission.\n");
148 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
149 ip, P_F | P_ESC, mission_flags);
150 ac_encounter(&bomb_list, &esc_list, ax, ay,
151 flightpath, mission_flags, 0);
152 if (QEMPTY(&bomb_list)) {
153 pr("No planes got through fighter defenses\n");
154 } else if (target.sct_type == SCT_SANCT) {
155 pr("You can't bomb that sector!\n");
159 pin_bomb(&bomb_list, &target);
163 natp = getnatp(player->cnum);
164 if (target.sct_own) {
165 rel = getrel(natp, target.sct_own);
166 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
167 && (target.sct_own) &&
168 (target.sct_oldown != player->cnum)) {
169 pr("You're not at war with them!\n");
176 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
177 strat_bomb(&bomb_list, &target);
189 pin_bomb(struct emp_qelem *list, struct sctstr *target)
206 type = target->sct_type;
208 pr("Target sector is a %s constructed %s\n",
209 effadv((int)target->sct_effic), dcp->d_name);
211 plp = (struct plist *)list->q_forw;
212 if (plp->pcp->pl_flags & P_A) {
213 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
214 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
216 pr("Some subs are present in the sector.\n");
218 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
220 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
221 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
223 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
225 if (p == 0 || *p == 0) {
236 natp = getnatp(player->cnum);
237 if (target->sct_own) {
238 rel = getrel(natp, target->sct_own);
239 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
240 && (target->sct_own) &&
241 (target->sct_oldown != player->cnum)) {
242 pr("You're not at war with them!\n");
248 pr("no units there\n");
251 land_bomb(list, target);
255 natp = getnatp(player->cnum);
256 if (target->sct_own) {
257 rel = getrel(natp, target->sct_own);
258 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
259 && (target->sct_own) &&
260 (target->sct_oldown != player->cnum)) {
261 pr("You're not at war with them!\n");
267 pr("no planes there\n");
270 plane_bomb(list, target);
274 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
276 pr("no ships there\n");
280 pr("no ships there\n");
284 ship_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 for (i = 0; i < nbomb; i++) {
301 if (!target->sct_item[bombcomm[i]])
306 pr("No bombable commodities in %s\n",
307 xyas(target->sct_x, target->sct_y, player->cnum));
310 comm_bomb(list, target);
314 natp = getnatp(player->cnum);
315 if (target->sct_own) {
316 rel = getrel(natp, target->sct_own);
317 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
318 && (target->sct_own) &&
319 (target->sct_oldown != player->cnum)) {
320 pr("You're not at war with them!\n");
325 eff_bomb(list, target);
328 pr("Aborting mission.\n");
331 pr("Bad target type.\n");
337 eff_bomb(struct emp_qelem *list, struct sctstr *target)
340 struct emp_qelem *qp;
345 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
346 plp = (struct plist *)qp;
347 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
349 if (plp->bombs || plp->plane.pln_nuketype != -1)
350 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
353 if (dam <= 0) /* dam == 0 if only nukes were delivered */
355 getsect(target->sct_x, target->sct_y, §);
357 oldeff = target->sct_effic;
358 target->sct_effic = effdamage(target->sct_effic, dam);
359 target->sct_avail = effdamage(target->sct_avail, dam);
360 target->sct_road = effdamage(target->sct_road, dam);
361 target->sct_rail = effdamage(target->sct_rail, dam);
362 target->sct_defense = effdamage(target->sct_defense, dam);
363 pr("did %d%% damage to efficiency in %s\n",
364 oldeff - target->sct_effic,
365 xyas(target->sct_x, target->sct_y, player->cnum));
367 wu(0, target->sct_own,
368 "%s bombing raid did %d%% damage in %s\n",
369 cname(player->cnum), oldeff - target->sct_effic,
370 xyas(target->sct_x, target->sct_y, target->sct_own));
371 bridge_damaged(target);
373 collateral_damage(target->sct_x, target->sct_y, dam);
377 comm_bomb(struct emp_qelem *list, struct sctstr *target)
384 struct emp_qelem *qp;
389 for (i = 0; i < nbomb; i++) {
390 if (target->sct_item[bombcomm[i]] == 0)
392 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
394 ip = &ichr[bombcomm[i]];
395 pr("some %s\n", ip->i_name);
398 ip = whatitem(NULL, "commodity to bomb? ");
404 for (i = 0; i < nbomb; i++) {
405 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
407 if (&ichr[bombcomm[i]] == ip)
411 pr("You can't bomb %s!\n", ip->i_name);
412 for (i = 0; i < nbomb; i++) {
413 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
415 pr("%s%s", i == 0 ? "Bombable: " : ", ",
416 ichr[bombcomm[i]].i_name);
422 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
423 plp = (struct plist *)qp;
424 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
426 if (plp->bombs || plp->plane.pln_nuketype != -1)
427 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
430 if (dam <= 0) /* dam == 0 if only nukes were delivered */
432 getsect(target->sct_x, target->sct_y, §);
434 before = target->sct_item[ip->i_uid];
435 target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
437 b = 100.0 * (1.0 - (double)amt / (double)before);
440 pr("did %.2f%% damage to %s in %s\n",
441 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
442 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
443 if (target->sct_own != 0)
444 wu(0, target->sct_own,
445 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
446 cname(player->cnum), b, ip->i_name,
447 xyas(target->sct_x, target->sct_y, target->sct_own));
449 collateral_damage(target->sct_x, target->sct_y, dam);
453 ship_bomb(struct emp_qelem *list, struct sctstr *target)
460 struct emp_qelem *qp;
465 struct shiplist *head = NULL;
474 for (qp = list->q_forw; qp != list && !player->aborted;
476 free_shiplist(&head);
477 plp = (struct plist *)qp;
478 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
480 if (plp->pcp->pl_flags & P_A)
481 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
484 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
486 pr("%s could not find any ships!\n", prplane(&plp->plane));
489 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
490 prplane(&plp->plane), plp->bombs);
493 while (shipno < 0 && !player->aborted && !ignore) {
494 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
501 if (plp->pcp->pl_flags & P_A)
502 print_shiplist(head);
504 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
514 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
516 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
517 ship.shp_y == target->sct_y)
522 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
526 gun = shp_usable_guns(&ship);
528 shell = ship.shp_item[I_SHELL];
530 shell = supply_commod(ship.shp_own,
531 ship.shp_x, ship.shp_y, I_SHELL, 1);
533 mcp = &mchr[(int)ship.shp_type];
534 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
535 flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
536 ship.shp_item[I_SHELL] = shell;
537 putship(ship.shp_uid, &ship);
538 PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
539 flak, prship(&ship));
540 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
545 if (plp->plane.pln_nuketype != -1)
548 hitchance = pln_hitchance(&plp->plane,
549 shp_hardtarget(&ship), EF_SHIP);
550 pr("%d%% hitchance...", hitchance);
552 if (roll(100) <= hitchance) {
553 /* pinbombing is more accurate than normal bombing */
554 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
558 /* Bombs that miss have to land somewhere! */
559 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
561 collateral_damage(target->sct_x, target->sct_y, dam);
564 if (dam <= 0) /* dam == 0 if only nukes were delivered */
566 if (mcp->m_flags & M_SUB)
567 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
569 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
571 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
572 cname(player->cnum), dam,
574 xyas(target->sct_x, target->sct_y, ship.shp_own));
577 check_retreat_and_do_shipdamage(&ship, dam);
578 if (ship.shp_rflags & RET_BOMBED)
579 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
580 retreat_ship(&ship, 'b');
581 putship(ship.shp_uid, &ship);
582 getship(ship.shp_uid, &ship);
584 pr("%s at %s sunk!\n",
586 xyas(target->sct_x, target->sct_y, player->cnum));
588 collateral_damage(target->sct_x, target->sct_y, dam / 2);
592 free_shiplist(&head);
596 plane_bomb(struct emp_qelem *list, struct sctstr *target)
603 struct emp_qelem *qp;
613 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
614 plp = (struct plist *)qp;
615 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
617 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
619 pr("%s could not find any planes!\n", prplane(&plp->plane));
622 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
623 prplane(&plp->plane), plp->bombs);
626 while (planeno < 0 && !player->aborted && !ignore) {
627 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
634 planesatxy(target->sct_x, target->sct_y, 0, 0);
642 if (getplane(n, &plane) &&
643 plane.pln_x == target->sct_x &&
644 plane.pln_y == target->sct_y &&
645 !(plane.pln_flags & PLN_LAUNCHED))
648 pr("Plane #%d not spotted\n", n);
653 if (plp->plane.pln_nuketype != -1)
656 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
657 pr("%d%% hitchance...", hitchance);
659 if (roll(100) <= hitchance) {
660 /* pinbombing is more accurate than normal bombing */
661 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
665 /* Bombs that miss have to land somewhere! */
666 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
668 collateral_damage(target->sct_x, target->sct_y, dam);
671 if (dam <= 0) /* dam == 0 if only nukes were delivered */
676 if (dam > plane.pln_effic)
679 plane.pln_effic -= dam;
680 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
681 if (own == player->cnum) {
682 pr("%s reports %d%% damage\n", prplane(&plane), dam);
686 "%s pinpoint bombing raid did %d%% damage to %s\n",
687 cname(player->cnum), dam, prplane(&plane));
689 nreport(player->cnum, N_DOWN_PLANE, own, 1);
691 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
692 cname(player->cnum), dam, prplane(&plane),
693 xyas(target->sct_x, target->sct_y, own));
694 putplane(plane.pln_uid, &plane);
695 collateral_damage(target->sct_x, target->sct_y, dam);
702 land_bomb(struct emp_qelem *list, struct sctstr *target)
711 struct emp_qelem *qp;
713 int ignore, aaf, flak, hitchance;
718 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
719 plp = (struct plist *)qp;
720 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
722 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
724 pr("%s could not find any units!\n", prplane(&plp->plane));
727 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
728 prplane(&plp->plane), plp->bombs);
731 while (unitno < 0 && !player->aborted && !ignore) {
732 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
739 unitsatxy(target->sct_x, target->sct_y, 0, 0);
747 if (getland(n, &land) &&
748 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
751 pr("Unit #%d not spotted\n", n);
756 aaf = lnd_aaf(&land);
757 flak = (int)(techfact(land.lnd_tech, aaf) * 3.0);
760 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
762 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
767 if (plp->plane.pln_nuketype != -1)
770 hitchance = pln_hitchance(&plp->plane,
771 lnd_hardtarget(&land), EF_LAND);
772 pr("%d%% hitchance...", hitchance);
774 if (roll(100) <= hitchance) {
775 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
779 /* Bombs that miss have to land somewhere! */
780 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
782 collateral_damage(target->sct_x, target->sct_y, dam);
785 if (dam <= 0) /* dam == 0 if only nukes were delivered */
790 mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
791 cname(player->cnum), dam, prland(&land));
792 check_retreat_and_do_landdamage(&land, dam);
794 if (land.lnd_rflags & RET_BOMBED)
795 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
796 retreat_land(&land, 'b');
797 nreport(player->cnum, N_UNIT_BOMB, own, 1);
798 putland(land.lnd_uid, &land);
799 collateral_damage(target->sct_x, target->sct_y, dam);
806 strat_bomb(struct emp_qelem *list, struct sctstr *target)
810 struct emp_qelem *qp;
814 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
815 plp = (struct plist *)qp;
816 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
818 if (plp->bombs || plp->plane.pln_nuketype != -1)
819 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
822 if (dam <= 0) /* dam == 0 if only nukes were delivered */
824 getsect(target->sct_x, target->sct_y, §);
827 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
828 cname(player->cnum), PERCENT_DAMAGE(dam),
829 xyas(target->sct_x, target->sct_y, target->sct_own));
831 sectdamage(target, dam);
833 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
834 xyas(target->sct_x, target->sct_y, player->cnum));
839 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
848 dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
850 plane_owner = pp->pln_own;
854 memset(dmess, 0, sizeof(dmess));
858 if (eff < PLANE_MINEFF) {
859 sprintf(dmess, " -- shot down");
861 } else if (chance((100 - eff) / 100.0)) {
862 sprintf(dmess, " -- aborted with %d%% damage", 100 - eff);
865 PR(plane_owner, " Flak! %s %s takes %d%s.\n",
866 cname(pp->pln_own), prplane(pp), dam, dmess);
871 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
873 putplane(pp->pln_uid, pp);