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
58 static void pin_bomb(struct emp_qelem *list, struct sctstr *target);
59 static void strat_bomb(struct emp_qelem *list, struct sctstr *target);
60 static void comm_bomb(struct emp_qelem *list, struct sctstr *target);
61 static void eff_bomb(struct emp_qelem *list, struct sctstr *target);
62 static int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp,
63 natid from, int flak);
64 static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
65 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
66 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
68 static i_type bombcomm[] = {
84 static int nbomb = sizeof(bombcomm) / sizeof(*bombcomm);
95 char flightpath[MAX_PATH_LEN];
96 struct nstr_item ni_bomb;
97 struct nstr_item ni_esc;
99 struct emp_qelem bomb_list;
100 struct emp_qelem esc_list;
102 struct sctstr ap_sect;
109 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
111 if (!snxtitem(&ni_esc, EF_PLANE,
112 getstarg(player->argp[2], "escort(s)? ", buf)))
113 pr("No escorts...\n");
114 p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
118 if (strchr("ps", mission) == 0)
120 if (!get_assembly_point(player->argp[4], &ap_sect, buf))
124 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING) == 0
129 (void)pathtoxy(flightpath, &tx, &ty, fcost);
130 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
131 getsect(tx, ty, &target);
133 ap_to_target = strlen(flightpath);
134 if (flightpath[ap_to_target - 1] == 'h')
136 pr("range to target is %d\n", ap_to_target);
138 * select planes within range
141 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
142 2, wantflags, P_M | P_O);
143 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
144 2, wantflags | P_F | P_ESC, P_M | P_O);
146 * now arm and equip the bombers, transports, whatever.
148 mission_flags |= P_X; /* stealth (shhh) */
149 mission_flags |= P_H; /* gets turned off if not all choppers */
150 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
151 ip, 0, mission_flags);
152 if (QEMPTY(&bomb_list)) {
153 pr("No planes could be equipped for the mission.\n");
156 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
157 ip, P_F | P_ESC, mission_flags);
158 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
160 if (QEMPTY(&bomb_list)) {
161 pr("No planes got through fighter defenses\n");
162 } else if (target.sct_type == SCT_SANCT) {
163 pr("You can't bomb that sector!\n");
167 pin_bomb(&bomb_list, &target);
171 natp = getnatp(player->cnum);
172 if (target.sct_own) {
173 rel = getrel(natp, target.sct_own);
174 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
175 && (target.sct_own) &&
176 (target.sct_oldown != player->cnum)) {
177 pr("You're not at war with them!\n");
184 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
185 strat_bomb(&bomb_list, &target);
188 pr("Bad mission %c\n", mission);
198 pin_bomb(struct emp_qelem *list, struct sctstr *target)
215 type = target->sct_type;
217 pr("Target sector is a %s constructed %s\n",
218 effadv((int)target->sct_effic), dcp->d_name);
220 plp = (struct plist *)list->q_forw;
221 if (plp->pcp->pl_flags & P_A) {
222 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
223 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
225 pr("Some subs are present in the sector.\n");
227 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
229 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
230 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
232 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
234 if (p == 0 || *p == 0) {
245 natp = getnatp(player->cnum);
246 if (target->sct_own) {
247 rel = getrel(natp, target->sct_own);
248 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
249 && (target->sct_own) &&
250 (target->sct_oldown != player->cnum)) {
251 pr("You're not at war with them!\n");
257 pr("no units there\n");
260 land_bomb(list, target);
264 natp = getnatp(player->cnum);
265 if (target->sct_own) {
266 rel = getrel(natp, target->sct_own);
267 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
268 && (target->sct_own) &&
269 (target->sct_oldown != player->cnum)) {
270 pr("You're not at war with them!\n");
276 pr("no planes there\n");
279 plane_bomb(list, target);
283 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
285 pr("no ships there\n");
289 pr("no ships there\n");
293 ship_bomb(list, target);
297 natp = getnatp(player->cnum);
298 if (target->sct_own) {
299 rel = getrel(natp, target->sct_own);
300 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
301 && (target->sct_own) &&
302 (target->sct_oldown != player->cnum)) {
303 pr("You're not at war with them!\n");
309 for (i = 0; i < nbomb; i++) {
310 if (!target->sct_item[bombcomm[i]])
315 pr("No bombable commodities in %s\n",
316 xyas(target->sct_x, target->sct_y, player->cnum));
319 comm_bomb(list, target);
323 natp = getnatp(player->cnum);
324 if (target->sct_own) {
325 rel = getrel(natp, target->sct_own);
326 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
327 && (target->sct_own) &&
328 (target->sct_oldown != player->cnum)) {
329 pr("You're not at war with them!\n");
334 eff_bomb(list, target);
337 pr("Aborting mission.\n");
340 pr("Bad target type.\n");
346 eff_bomb(struct emp_qelem *list, struct sctstr *target)
349 struct emp_qelem *qp;
354 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
355 plp = (struct plist *)qp;
356 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
358 if (plp->bombs || plp->plane.pln_nuketype != -1)
359 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
362 if (dam <= 0) /* dam == 0 if only nukes were delivered */
364 getsect(target->sct_x, target->sct_y, §);
366 oldeff = target->sct_effic;
367 target->sct_effic = effdamage(target->sct_effic, dam);
368 target->sct_avail = effdamage(target->sct_avail, dam);
369 target->sct_road = effdamage(target->sct_road, dam);
370 target->sct_rail = effdamage(target->sct_rail, dam);
371 target->sct_defense = effdamage(target->sct_defense, dam);
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(NULL, "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("%s%s", i == 0 ? "Bombable: " : ", ",
432 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 = target->sct_item[ip->i_uid];
451 target->sct_item[ip->i_uid] = amt = commdamage(before, dam, ip->i_uid);
453 b = 100.0 * (1.0 - (double)amt / (double)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;
490 for (qp = list->q_forw; qp != list && !player->aborted;
492 free_shiplist(&head);
493 plp = (struct plist *)qp;
494 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
496 if (plp->pcp->pl_flags & P_A)
497 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
500 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
502 pr("%s could not find any ships!\n", prplane(&plp->plane));
505 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
506 prplane(&plp->plane), plp->bombs);
509 while (shipno < 0 && !player->aborted && !ignore) {
510 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
517 if (plp->pcp->pl_flags & P_A)
518 print_shiplist(head);
520 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
530 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
532 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
533 ship.shp_y == target->sct_y)
538 if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
542 gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
544 shell = ship.shp_item[I_SHELL];
546 shell = supply_commod(ship.shp_own,
547 ship.shp_x, ship.shp_y, I_SHELL, 1);
549 mcp = &mchr[(int)ship.shp_type];
550 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
551 flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
552 ship.shp_item[I_SHELL] = shell;
553 putship(ship.shp_uid, &ship);
554 PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
555 flak, prship(&ship));
556 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
561 if (plp->plane.pln_nuketype != -1)
564 hitchance = pln_hitchance(&plp->plane,
565 shp_hardtarget(&ship), EF_SHIP);
566 pr("%d%% hitchance...", hitchance);
568 if (roll(100) <= hitchance) {
569 /* pinbombing is more accurate than normal bombing */
570 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
574 /* Bombs that miss have to land somewhere! */
575 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
577 collateral_damage(target->sct_x, target->sct_y, dam, list);
580 if (dam <= 0) /* dam == 0 if only nukes were delivered */
582 if (mcp->m_flags & M_SUB)
583 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
585 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
587 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
588 cname(player->cnum), dam,
590 xyas(target->sct_x, target->sct_y, ship.shp_own));
593 check_retreat_and_do_shipdamage(&ship, dam);
594 if (ship.shp_rflags & RET_BOMBED)
595 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
596 retreat_ship(&ship, 'b');
597 putship(ship.shp_uid, &ship);
598 getship(ship.shp_uid, &ship);
600 pr("%s at %s sunk!\n",
602 xyas(target->sct_x, target->sct_y, player->cnum));
604 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
608 free_shiplist(&head);
612 plane_bomb(struct emp_qelem *list, struct sctstr *target)
619 struct emp_qelem *qp;
629 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
630 plp = (struct plist *)qp;
631 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
633 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
635 pr("%s could not find any planes!\n", prplane(&plp->plane));
638 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
639 prplane(&plp->plane), plp->bombs);
642 while (planeno < 0 && !player->aborted && !ignore) {
643 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
650 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
658 if (getplane(n, &plane) &&
659 plane.pln_x == target->sct_x &&
660 plane.pln_y == target->sct_y &&
661 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
662 (!ac_isflying(&plane, list)))
665 pr("Plane #%d not spotted\n", n);
670 if (plp->plane.pln_nuketype != -1)
673 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
674 pr("%d%% hitchance...", hitchance);
676 if (roll(100) <= hitchance) {
677 /* pinbombing is more accurate than normal bombing */
678 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
682 /* Bombs that miss have to land somewhere! */
683 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
685 collateral_damage(target->sct_x, target->sct_y, dam, list);
688 if (dam <= 0) /* dam == 0 if only nukes were delivered */
693 if (dam > plane.pln_effic)
696 plane.pln_effic -= dam;
697 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
698 if (own == player->cnum) {
699 pr("%s reports %d%% damage\n", prplane(&plane), dam);
703 "%s pinpoint bombing raid did %d%% damage to %s\n",
704 cname(player->cnum), dam, prplane(&plane));
706 nreport(player->cnum, N_DOWN_PLANE, own, 1);
708 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
709 cname(player->cnum), dam, prplane(&plane),
710 xyas(target->sct_x, target->sct_y, own));
711 putplane(plane.pln_uid, &plane);
712 collateral_damage(target->sct_x, target->sct_y, dam, list);
719 land_bomb(struct emp_qelem *list, struct sctstr *target)
728 struct emp_qelem *qp;
730 int ignore, flak, hitchance;
735 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
736 plp = (struct plist *)qp;
737 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
739 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
741 pr("%s could not find any units!\n", prplane(&plp->plane));
744 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
745 prplane(&plp->plane), plp->bombs);
748 while (unitno < 0 && !player->aborted && !ignore) {
749 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
756 unitsatxy(target->sct_x, target->sct_y, 0, 0);
764 if (getland(n, &land) &&
765 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
768 pr("Unit #%d not spotted\n", n);
773 flak = (int)(techfact(land.lnd_tech, land.lnd_aaf) * 3.0);
776 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
777 prland(&land), land.lnd_aaf);
778 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
783 if (plp->plane.pln_nuketype != -1)
786 hitchance = pln_hitchance(&plp->plane,
787 lnd_hardtarget(&land), EF_LAND);
788 pr("%d%% hitchance...", hitchance);
790 if (roll(100) <= hitchance) {
791 dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
795 /* Bombs that miss have to land somewhere! */
796 dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
798 collateral_damage(target->sct_x, target->sct_y, dam, list);
801 if (dam <= 0) /* dam == 0 if only nukes were delivered */
807 mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
808 cname(player->cnum), dam, prland(&land));
809 check_retreat_and_do_landdamage(&land, dam);
811 if (land.lnd_rflags & RET_BOMBED)
812 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
813 retreat_land(&land, 'b');
814 nreport(player->cnum, N_UNIT_BOMB, own, 1);
815 putland(land.lnd_uid, &land);
816 collateral_damage(target->sct_x, target->sct_y, dam, list);
823 strat_bomb(struct emp_qelem *list, struct sctstr *target)
827 struct emp_qelem *qp;
831 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
832 plp = (struct plist *)qp;
833 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
835 if (plp->bombs || plp->plane.pln_nuketype != -1)
836 dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
839 if (dam <= 0) /* dam == 0 if only nukes were delivered */
841 getsect(target->sct_x, target->sct_y, §);
844 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
845 cname(player->cnum), PERCENT_DAMAGE(dam),
846 xyas(target->sct_x, target->sct_y, target->sct_own));
848 sectdamage(target, dam, list);
850 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
851 xyas(target->sct_x, target->sct_y, player->cnum));
856 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
867 dam = ac_flak_dam(flak, pp->pln_def, pcp->pl_flags);
869 plane_owner = pp->pln_own;
873 memset(dmess, 0, sizeof(dmess));
877 if (eff < PLANE_MINEFF) {
878 sprintf(dmess, " -- shot down");
880 } else if (chance((100 - eff) / 100.0)) {
881 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
884 PR(plane_owner, " Flak! %s %s takes %d%s.\n",
885 cname(pp->pln_own), prplane(pp), dam, dmess);
890 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
891 if (pp->pln_ship >= 0) {
892 getship(pp->pln_ship, &ship);
893 take_plane_off_ship(pp, &ship);
895 if (pp->pln_land >= 0) {
896 getland(pp->pln_land, &land);
897 take_plane_off_land(pp, &land);
900 putplane(pp->pln_uid, pp);