2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 if (target->sct_effic < SCT_MINEFF) {
373 if (target->sct_type == SCT_BSPAN)
374 knockdown(target, list);
375 else if (target->sct_type == SCT_BTOWER) {
376 knockdown(target, list);
377 bridgefall(target, list);
381 collateral_damage(target->sct_x, target->sct_y, dam, list);
385 comm_bomb(struct emp_qelem *list, struct sctstr *target)
392 struct emp_qelem *qp;
397 for (i = 0; i < nbomb; i++) {
398 if (target->sct_item[bombcomm[i]] == 0)
400 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
402 ip = &ichr[bombcomm[i]];
403 pr("some %s\n", ip->i_name);
406 ip = whatitem(NULL, "commodity to bomb? ");
412 for (i = 0; i < nbomb; i++) {
413 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
415 if (&ichr[bombcomm[i]] == ip)
419 pr("You can't bomb %s!\n", ip->i_name);
420 for (i = 0; i < nbomb; i++) {
421 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
423 pr("%s%s", i == 0 ? "Bombable: " : ", ",
424 ichr[bombcomm[i]].i_name);
430 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
431 plp = (struct plist *)qp;
432 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
434 if (plp->bombs || plp->plane.pln_nuketype != -1)
435 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
438 if (dam <= 0) /* dam == 0 if only nukes were delivered */
440 getsect(target->sct_x, target->sct_y, §);
442 before = target->sct_item[ip->i_uid];
443 target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
445 b = 100.0 * (1.0 - (double)amt / (double)before);
448 pr("did %.2f%% damage to %s in %s\n",
449 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
450 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
451 if (target->sct_own != 0)
452 wu(0, target->sct_own,
453 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
454 cname(player->cnum), b, ip->i_name,
455 xyas(target->sct_x, target->sct_y, target->sct_own));
457 collateral_damage(target->sct_x, target->sct_y, dam, list);
461 ship_bomb(struct emp_qelem *list, struct sctstr *target)
468 struct emp_qelem *qp;
473 struct shiplist *head = NULL;
482 for (qp = list->q_forw; qp != list && !player->aborted;
484 free_shiplist(&head);
485 plp = (struct plist *)qp;
486 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
488 if (plp->pcp->pl_flags & P_A)
489 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
492 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
494 pr("%s could not find any ships!\n", prplane(&plp->plane));
497 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
498 prplane(&plp->plane), plp->bombs);
501 while (shipno < 0 && !player->aborted && !ignore) {
502 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
509 if (plp->pcp->pl_flags & P_A)
510 print_shiplist(head);
512 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
522 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
524 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
525 ship.shp_y == target->sct_y)
530 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
534 gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
536 shell = ship.shp_item[I_SHELL];
538 shell = supply_commod(ship.shp_own,
539 ship.shp_x, ship.shp_y, I_SHELL, 1);
541 mcp = &mchr[(int)ship.shp_type];
542 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
543 flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
544 ship.shp_item[I_SHELL] = shell;
545 putship(ship.shp_uid, &ship);
546 PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
547 flak, prship(&ship));
548 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
553 if (plp->plane.pln_nuketype != -1)
556 hitchance = pln_hitchance(&plp->plane,
557 shp_hardtarget(&ship), EF_SHIP);
558 pr("%d%% hitchance...", hitchance);
560 if (roll(100) <= hitchance) {
561 /* pinbombing is more accurate than normal bombing */
562 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
566 /* Bombs that miss have to land somewhere! */
567 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
569 collateral_damage(target->sct_x, target->sct_y, dam, list);
572 if (dam <= 0) /* dam == 0 if only nukes were delivered */
574 if (mcp->m_flags & M_SUB)
575 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
577 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
579 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
580 cname(player->cnum), dam,
582 xyas(target->sct_x, target->sct_y, ship.shp_own));
585 check_retreat_and_do_shipdamage(&ship, dam);
586 if (ship.shp_rflags & RET_BOMBED)
587 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
588 retreat_ship(&ship, 'b');
589 putship(ship.shp_uid, &ship);
590 getship(ship.shp_uid, &ship);
592 pr("%s at %s sunk!\n",
594 xyas(target->sct_x, target->sct_y, player->cnum));
596 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
600 free_shiplist(&head);
604 plane_bomb(struct emp_qelem *list, struct sctstr *target)
611 struct emp_qelem *qp;
621 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
622 plp = (struct plist *)qp;
623 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
625 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
627 pr("%s could not find any planes!\n", prplane(&plp->plane));
630 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
631 prplane(&plp->plane), plp->bombs);
634 while (planeno < 0 && !player->aborted && !ignore) {
635 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
642 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
650 if (getplane(n, &plane) &&
651 plane.pln_x == target->sct_x &&
652 plane.pln_y == target->sct_y &&
653 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
654 (!ac_isflying(&plane, list)))
657 pr("Plane #%d not spotted\n", n);
662 if (plp->plane.pln_nuketype != -1)
665 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
666 pr("%d%% hitchance...", hitchance);
668 if (roll(100) <= hitchance) {
669 /* pinbombing is more accurate than normal bombing */
670 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
674 /* Bombs that miss have to land somewhere! */
675 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
677 collateral_damage(target->sct_x, target->sct_y, dam, list);
680 if (dam <= 0) /* dam == 0 if only nukes were delivered */
685 if (dam > plane.pln_effic)
688 plane.pln_effic -= dam;
689 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
690 if (own == player->cnum) {
691 pr("%s reports %d%% damage\n", prplane(&plane), dam);
695 "%s pinpoint bombing raid did %d%% damage to %s\n",
696 cname(player->cnum), dam, prplane(&plane));
698 nreport(player->cnum, N_DOWN_PLANE, own, 1);
700 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
701 cname(player->cnum), dam, prplane(&plane),
702 xyas(target->sct_x, target->sct_y, own));
703 putplane(plane.pln_uid, &plane);
704 collateral_damage(target->sct_x, target->sct_y, dam, list);
711 land_bomb(struct emp_qelem *list, struct sctstr *target)
720 struct emp_qelem *qp;
722 int ignore, flak, hitchance;
727 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
728 plp = (struct plist *)qp;
729 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
731 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
733 pr("%s could not find any units!\n", prplane(&plp->plane));
736 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
737 prplane(&plp->plane), plp->bombs);
740 while (unitno < 0 && !player->aborted && !ignore) {
741 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
748 unitsatxy(target->sct_x, target->sct_y, 0, 0);
756 if (getland(n, &land) &&
757 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
760 pr("Unit #%d not spotted\n", n);
765 flak = (int)(techfact(land.lnd_tech, land.lnd_aaf) * 3.0);
768 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
769 prland(&land), land.lnd_aaf);
770 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
775 if (plp->plane.pln_nuketype != -1)
778 hitchance = pln_hitchance(&plp->plane,
779 lnd_hardtarget(&land), EF_LAND);
780 pr("%d%% hitchance...", hitchance);
782 if (roll(100) <= hitchance) {
783 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
787 /* Bombs that miss have to land somewhere! */
788 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
790 collateral_damage(target->sct_x, target->sct_y, dam, list);
793 if (dam <= 0) /* dam == 0 if only nukes were delivered */
799 mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
800 cname(player->cnum), dam, prland(&land));
801 check_retreat_and_do_landdamage(&land, dam);
803 if (land.lnd_rflags & RET_BOMBED)
804 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
805 retreat_land(&land, 'b');
806 nreport(player->cnum, N_UNIT_BOMB, own, 1);
807 putland(land.lnd_uid, &land);
808 collateral_damage(target->sct_x, target->sct_y, dam, list);
815 strat_bomb(struct emp_qelem *list, struct sctstr *target)
819 struct emp_qelem *qp;
823 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
824 plp = (struct plist *)qp;
825 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
827 if (plp->bombs || plp->plane.pln_nuketype != -1)
828 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
831 if (dam <= 0) /* dam == 0 if only nukes were delivered */
833 getsect(target->sct_x, target->sct_y, §);
836 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
837 cname(player->cnum), PERCENT_DAMAGE(dam),
838 xyas(target->sct_x, target->sct_y, target->sct_own));
840 sectdamage(target, dam, list);
842 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
843 xyas(target->sct_x, target->sct_y, player->cnum));
848 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
859 dam = ac_flak_dam(flak, pp->pln_def, pcp->pl_flags);
861 plane_owner = pp->pln_own;
865 memset(dmess, 0, sizeof(dmess));
869 if (eff < PLANE_MINEFF) {
870 sprintf(dmess, " -- shot down");
872 } else if (chance((100 - eff) / 100.0)) {
873 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
876 PR(plane_owner, " Flak! %s %s takes %d%s.\n",
877 cname(pp->pln_own), prplane(pp), dam, dmess);
882 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
883 if (pp->pln_ship >= 0) {
884 getship(pp->pln_ship, &ship);
885 take_plane_off_ship(pp, &ship);
887 if (pp->pln_land >= 0) {
888 getland(pp->pln_land, &land);
889 take_plane_off_land(pp, &land);
892 putplane(pp->pln_uid, pp);