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, flightpath, mission_flags,
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);
180 pr("Bad mission %c\n", mission);
190 pin_bomb(struct emp_qelem *list, struct sctstr *target)
207 type = target->sct_type;
209 pr("Target sector is a %s constructed %s\n",
210 effadv((int)target->sct_effic), dcp->d_name);
212 plp = (struct plist *)list->q_forw;
213 if (plp->pcp->pl_flags & P_A) {
214 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
215 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
217 pr("Some subs are present in the sector.\n");
219 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
221 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
222 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
224 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
226 if (p == 0 || *p == 0) {
237 natp = getnatp(player->cnum);
238 if (target->sct_own) {
239 rel = getrel(natp, target->sct_own);
240 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
241 && (target->sct_own) &&
242 (target->sct_oldown != player->cnum)) {
243 pr("You're not at war with them!\n");
249 pr("no units there\n");
252 land_bomb(list, target);
256 natp = getnatp(player->cnum);
257 if (target->sct_own) {
258 rel = getrel(natp, target->sct_own);
259 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
260 && (target->sct_own) &&
261 (target->sct_oldown != player->cnum)) {
262 pr("You're not at war with them!\n");
268 pr("no planes there\n");
271 plane_bomb(list, target);
275 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
277 pr("no ships there\n");
281 pr("no ships there\n");
285 ship_bomb(list, target);
289 natp = getnatp(player->cnum);
290 if (target->sct_own) {
291 rel = getrel(natp, target->sct_own);
292 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
293 && (target->sct_own) &&
294 (target->sct_oldown != player->cnum)) {
295 pr("You're not at war with them!\n");
301 for (i = 0; i < nbomb; i++) {
302 if (!target->sct_item[bombcomm[i]])
307 pr("No bombable commodities in %s\n",
308 xyas(target->sct_x, target->sct_y, player->cnum));
311 comm_bomb(list, target);
315 natp = getnatp(player->cnum);
316 if (target->sct_own) {
317 rel = getrel(natp, target->sct_own);
318 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
319 && (target->sct_own) &&
320 (target->sct_oldown != player->cnum)) {
321 pr("You're not at war with them!\n");
326 eff_bomb(list, target);
329 pr("Aborting mission.\n");
332 pr("Bad target type.\n");
338 eff_bomb(struct emp_qelem *list, struct sctstr *target)
341 struct emp_qelem *qp;
346 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
347 plp = (struct plist *)qp;
348 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
350 if (plp->bombs || plp->plane.pln_nuketype != -1)
351 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
354 if (dam <= 0) /* dam == 0 if only nukes were delivered */
356 getsect(target->sct_x, target->sct_y, §);
358 oldeff = target->sct_effic;
359 target->sct_effic = effdamage(target->sct_effic, dam);
360 target->sct_avail = effdamage(target->sct_avail, dam);
361 target->sct_road = effdamage(target->sct_road, dam);
362 target->sct_rail = effdamage(target->sct_rail, dam);
363 target->sct_defense = effdamage(target->sct_defense, dam);
364 pr("did %d%% damage to efficiency in %s\n",
365 oldeff - target->sct_effic,
366 xyas(target->sct_x, target->sct_y, player->cnum));
368 wu(0, target->sct_own,
369 "%s bombing raid did %d%% damage in %s\n",
370 cname(player->cnum), oldeff - target->sct_effic,
371 xyas(target->sct_x, target->sct_y, target->sct_own));
372 bridge_damaged(target, list);
374 collateral_damage(target->sct_x, target->sct_y, dam, list);
378 comm_bomb(struct emp_qelem *list, struct sctstr *target)
385 struct emp_qelem *qp;
390 for (i = 0; i < nbomb; i++) {
391 if (target->sct_item[bombcomm[i]] == 0)
393 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
395 ip = &ichr[bombcomm[i]];
396 pr("some %s\n", ip->i_name);
399 ip = whatitem(NULL, "commodity to bomb? ");
405 for (i = 0; i < nbomb; i++) {
406 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
408 if (&ichr[bombcomm[i]] == ip)
412 pr("You can't bomb %s!\n", ip->i_name);
413 for (i = 0; i < nbomb; i++) {
414 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
416 pr("%s%s", i == 0 ? "Bombable: " : ", ",
417 ichr[bombcomm[i]].i_name);
423 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
424 plp = (struct plist *)qp;
425 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
427 if (plp->bombs || plp->plane.pln_nuketype != -1)
428 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
431 if (dam <= 0) /* dam == 0 if only nukes were delivered */
433 getsect(target->sct_x, target->sct_y, §);
435 before = target->sct_item[ip->i_uid];
436 target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
438 b = 100.0 * (1.0 - (double)amt / (double)before);
441 pr("did %.2f%% damage to %s in %s\n",
442 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
443 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
444 if (target->sct_own != 0)
445 wu(0, target->sct_own,
446 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
447 cname(player->cnum), b, ip->i_name,
448 xyas(target->sct_x, target->sct_y, target->sct_own));
450 collateral_damage(target->sct_x, target->sct_y, dam, list);
454 ship_bomb(struct emp_qelem *list, struct sctstr *target)
461 struct emp_qelem *qp;
466 struct shiplist *head = NULL;
475 for (qp = list->q_forw; qp != list && !player->aborted;
477 free_shiplist(&head);
478 plp = (struct plist *)qp;
479 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
481 if (plp->pcp->pl_flags & P_A)
482 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
485 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
487 pr("%s could not find any ships!\n", prplane(&plp->plane));
490 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
491 prplane(&plp->plane), plp->bombs);
494 while (shipno < 0 && !player->aborted && !ignore) {
495 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
502 if (plp->pcp->pl_flags & P_A)
503 print_shiplist(head);
505 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
515 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
517 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
518 ship.shp_y == target->sct_y)
523 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
527 gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
529 shell = ship.shp_item[I_SHELL];
531 shell = supply_commod(ship.shp_own,
532 ship.shp_x, ship.shp_y, I_SHELL, 1);
534 mcp = &mchr[(int)ship.shp_type];
535 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
536 flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
537 ship.shp_item[I_SHELL] = shell;
538 putship(ship.shp_uid, &ship);
539 PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
540 flak, prship(&ship));
541 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
546 if (plp->plane.pln_nuketype != -1)
549 hitchance = pln_hitchance(&plp->plane,
550 shp_hardtarget(&ship), EF_SHIP);
551 pr("%d%% hitchance...", hitchance);
553 if (roll(100) <= hitchance) {
554 /* pinbombing is more accurate than normal bombing */
555 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
559 /* Bombs that miss have to land somewhere! */
560 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
562 collateral_damage(target->sct_x, target->sct_y, dam, list);
565 if (dam <= 0) /* dam == 0 if only nukes were delivered */
567 if (mcp->m_flags & M_SUB)
568 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
570 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
572 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
573 cname(player->cnum), dam,
575 xyas(target->sct_x, target->sct_y, ship.shp_own));
578 check_retreat_and_do_shipdamage(&ship, dam);
579 if (ship.shp_rflags & RET_BOMBED)
580 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
581 retreat_ship(&ship, 'b');
582 putship(ship.shp_uid, &ship);
583 getship(ship.shp_uid, &ship);
585 pr("%s at %s sunk!\n",
587 xyas(target->sct_x, target->sct_y, player->cnum));
589 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
593 free_shiplist(&head);
597 plane_bomb(struct emp_qelem *list, struct sctstr *target)
604 struct emp_qelem *qp;
614 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
615 plp = (struct plist *)qp;
616 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
618 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
620 pr("%s could not find any planes!\n", prplane(&plp->plane));
623 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
624 prplane(&plp->plane), plp->bombs);
627 while (planeno < 0 && !player->aborted && !ignore) {
628 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
635 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
643 if (getplane(n, &plane) &&
644 plane.pln_x == target->sct_x &&
645 plane.pln_y == target->sct_y &&
646 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
647 (!ac_isflying(&plane, list)))
650 pr("Plane #%d not spotted\n", n);
655 if (plp->plane.pln_nuketype != -1)
658 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
659 pr("%d%% hitchance...", hitchance);
661 if (roll(100) <= hitchance) {
662 /* pinbombing is more accurate than normal bombing */
663 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
667 /* Bombs that miss have to land somewhere! */
668 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
670 collateral_damage(target->sct_x, target->sct_y, dam, list);
673 if (dam <= 0) /* dam == 0 if only nukes were delivered */
678 if (dam > plane.pln_effic)
681 plane.pln_effic -= dam;
682 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
683 if (own == player->cnum) {
684 pr("%s reports %d%% damage\n", prplane(&plane), dam);
688 "%s pinpoint bombing raid did %d%% damage to %s\n",
689 cname(player->cnum), dam, prplane(&plane));
691 nreport(player->cnum, N_DOWN_PLANE, own, 1);
693 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
694 cname(player->cnum), dam, prplane(&plane),
695 xyas(target->sct_x, target->sct_y, own));
696 putplane(plane.pln_uid, &plane);
697 collateral_damage(target->sct_x, target->sct_y, dam, list);
704 land_bomb(struct emp_qelem *list, struct sctstr *target)
713 struct emp_qelem *qp;
715 int ignore, flak, hitchance;
720 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
721 plp = (struct plist *)qp;
722 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
724 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
726 pr("%s could not find any units!\n", prplane(&plp->plane));
729 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
730 prplane(&plp->plane), plp->bombs);
733 while (unitno < 0 && !player->aborted && !ignore) {
734 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
741 unitsatxy(target->sct_x, target->sct_y, 0, 0);
749 if (getland(n, &land) &&
750 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
753 pr("Unit #%d not spotted\n", n);
758 flak = (int)(techfact(land.lnd_tech, land.lnd_aaf) * 3.0);
761 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
762 prland(&land), land.lnd_aaf);
763 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
768 if (plp->plane.pln_nuketype != -1)
771 hitchance = pln_hitchance(&plp->plane,
772 lnd_hardtarget(&land), EF_LAND);
773 pr("%d%% hitchance...", hitchance);
775 if (roll(100) <= hitchance) {
776 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
780 /* Bombs that miss have to land somewhere! */
781 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
783 collateral_damage(target->sct_x, target->sct_y, dam, list);
786 if (dam <= 0) /* dam == 0 if only nukes were delivered */
792 mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
793 cname(player->cnum), dam, prland(&land));
794 check_retreat_and_do_landdamage(&land, dam);
796 if (land.lnd_rflags & RET_BOMBED)
797 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
798 retreat_land(&land, 'b');
799 nreport(player->cnum, N_UNIT_BOMB, own, 1);
800 putland(land.lnd_uid, &land);
801 collateral_damage(target->sct_x, target->sct_y, dam, list);
808 strat_bomb(struct emp_qelem *list, struct sctstr *target)
812 struct emp_qelem *qp;
816 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
817 plp = (struct plist *)qp;
818 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
820 if (plp->bombs || plp->plane.pln_nuketype != -1)
821 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
824 if (dam <= 0) /* dam == 0 if only nukes were delivered */
826 getsect(target->sct_x, target->sct_y, §);
829 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
830 cname(player->cnum), PERCENT_DAMAGE(dam),
831 xyas(target->sct_x, target->sct_y, target->sct_own));
833 sectdamage(target, dam, list);
835 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
836 xyas(target->sct_x, target->sct_y, player->cnum));
841 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
852 dam = ac_flak_dam(flak, pp->pln_def, pcp->pl_flags);
854 plane_owner = pp->pln_own;
858 memset(dmess, 0, sizeof(dmess));
862 if (eff < PLANE_MINEFF) {
863 sprintf(dmess, " -- shot down");
865 } else if (chance((100 - eff) / 100.0)) {
866 sprintf(dmess, " -- aborted with %d%% damage", 100 - eff);
869 PR(plane_owner, " Flak! %s %s takes %d%s.\n",
870 cname(pp->pln_own), prplane(pp), dam, dmess);
875 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
876 if (pp->pln_ship >= 0) {
877 getship(pp->pln_ship, &ship);
878 take_plane_off_ship(pp, &ship);
880 if (pp->pln_land >= 0) {
881 getland(pp->pln_land, &land);
882 take_plane_off_land(pp, &land);
885 putplane(pp->pln_uid, pp);