2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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 int bombcomm[] = {
84 static int nbomb = sizeof(bombcomm) / sizeof(int);
95 s_char flightpath[MAX_PATH_LEN];
96 struct nstr_item ni_bomb;
97 struct nstr_item ni_esc;
100 struct emp_qelem bomb_list;
101 struct emp_qelem esc_list;
103 struct sctstr ap_sect;
110 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
112 if (!snxtitem(&ni_esc, EF_PLANE,
113 getstarg(player->argp[2], "escort(s)? ", buf)))
114 pr("No escorts...\n");
116 getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
119 if (strchr("ps", mission) == 0)
121 if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0
124 if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
126 if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
127 getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
128 pr("Assembly point not owned by you or an ally!\n");
133 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0,
134 0, P_FLYING) == 0 || *flightpath == 0)
138 (void)pathtoxy(flightpath, &tx, &ty, fcost);
139 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
140 getsect(tx, ty, &target);
142 ap_to_target = strlen(flightpath);
143 if (*(flightpath + strlen(flightpath) - 1) == 'h')
145 pr("range to target is %d\n", ap_to_target);
147 * select planes within range
150 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
151 2, wantflags, P_M | P_O);
152 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
153 2, wantflags | P_F | P_ESC, P_M | P_O);
155 * now arm and equip the bombers, transports, whatever.
157 mission_flags |= P_X; /* stealth (shhh) */
158 mission_flags |= P_H; /* gets turned off if not all choppers */
159 mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
160 ip, 0, mission_flags);
161 if (QEMPTY(&bomb_list)) {
162 pr("No planes could be equipped for the mission.\n");
165 mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
166 ip, P_F | P_ESC, mission_flags);
167 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
169 if (QEMPTY(&bomb_list)) {
170 pr("No planes got through fighter defenses\n");
171 } else if (target.sct_type == SCT_SANCT) {
172 pr("You can't bomb that sector!\n");
176 pin_bomb(&bomb_list, &target);
180 natp = getnatp(player->cnum);
181 if (target.sct_own) {
182 rel = getrel(natp, target.sct_own);
183 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
184 && (target.sct_own) &&
185 (target.sct_oldown != player->cnum)) {
186 pr("You're not at war with them!\n");
193 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
194 strat_bomb(&bomb_list, &target);
197 pr("Bad mission %c\n", mission);
207 pin_bomb(struct emp_qelem *list, struct sctstr *target)
216 struct emp_qelem *qp;
226 type = target->sct_type;
228 pr("Target sector is a %s constructed %s\n",
229 effadv((int)target->sct_effic), dcp->d_name);
231 plp = (struct plist *)list->q_forw;
232 if (plp->pcp->pl_flags & P_A) {
234 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
235 plp = (struct plist *)qp;
236 if (plp->plane.pln_acc < bestacc)
237 bestacc = plp->plane.pln_acc;
238 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
239 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
241 pr("Some subs are present in the sector.\n");
243 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
245 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
246 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
248 p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
250 if (p == 0 || *p == 0) {
261 natp = getnatp(player->cnum);
262 if (target->sct_own) {
263 rel = getrel(natp, target->sct_own);
264 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
265 && (target->sct_own) &&
266 (target->sct_oldown != player->cnum)) {
267 pr("You're not at war with them!\n");
273 pr("no units there\n");
276 land_bomb(list, target);
280 natp = getnatp(player->cnum);
281 if (target->sct_own) {
282 rel = getrel(natp, target->sct_own);
283 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
284 && (target->sct_own) &&
285 (target->sct_oldown != player->cnum)) {
286 pr("You're not at war with them!\n");
292 pr("no planes there\n");
295 plane_bomb(list, target);
299 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
301 pr("no ships there\n");
305 pr("no ships there\n");
309 ship_bomb(list, target);
313 natp = getnatp(player->cnum);
314 if (target->sct_own) {
315 rel = getrel(natp, target->sct_own);
316 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
317 && (target->sct_own) &&
318 (target->sct_oldown != player->cnum)) {
319 pr("You're not at war with them!\n");
325 for (i = 0; i < nbomb; i++) {
326 if (!target->sct_item[bombcomm[i]])
331 pr("No bombable commodities in %s\n",
332 xyas(target->sct_x, target->sct_y, player->cnum));
335 comm_bomb(list, target);
339 natp = getnatp(player->cnum);
340 if (target->sct_own) {
341 rel = getrel(natp, target->sct_own);
342 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
343 && (target->sct_own) &&
344 (target->sct_oldown != player->cnum)) {
345 pr("You're not at war with them!\n");
350 eff_bomb(list, target);
353 pr("Aborting mission.\n");
356 pr("Bad target type.\n");
362 eff_bomb(struct emp_qelem *list, struct sctstr *target)
364 register struct plist *plp;
365 struct emp_qelem *qp;
370 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
371 plp = (struct plist *)qp;
372 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
374 if (plp->bombs || plp->plane.pln_nuketype != -1)
376 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
379 if (dam <= 0) /* dam == 0 if only nukes were delivered */
381 getsect(target->sct_x, target->sct_y, §);
383 oldeff = target->sct_effic;
384 target->sct_effic = effdamage(target->sct_effic, dam);
385 target->sct_avail = effdamage(target->sct_avail, dam);
386 target->sct_road = effdamage(target->sct_road, dam);
387 target->sct_rail = effdamage(target->sct_rail, dam);
388 target->sct_defense = effdamage(target->sct_defense, dam);
389 if (!opt_DEFENSE_INFRA)
390 target->sct_defense = target->sct_effic;
391 pr("did %d%% damage to efficiency in %s\n",
392 oldeff - target->sct_effic,
393 xyas(target->sct_x, target->sct_y, player->cnum));
395 wu(0, target->sct_own,
396 "%s bombing raid did %d%% damage in %s\n",
397 cname(player->cnum), oldeff - target->sct_effic,
398 xyas(target->sct_x, target->sct_y, target->sct_own));
399 if (target->sct_effic < SCT_MINEFF) {
400 if (target->sct_type == SCT_BSPAN)
401 knockdown(target, list);
402 else if (target->sct_type == SCT_BTOWER) {
403 knockdown(target, list);
404 bridgefall(target, list);
408 collateral_damage(target->sct_x, target->sct_y, dam, list);
412 comm_bomb(struct emp_qelem *list, struct sctstr *target)
414 register struct plist *plp;
419 struct emp_qelem *qp;
424 for (i = 0; i < nbomb; i++) {
425 if (target->sct_item[bombcomm[i]] == 0)
427 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
429 ip = &ichr[bombcomm[i]];
430 pr("some %s\n", ip->i_name);
433 ip = whatitem((s_char *)0, "commodity to bomb? ");
439 for (i = 0; i < nbomb; i++) {
440 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
442 if (&ichr[bombcomm[i]] == ip)
446 pr("You can't bomb %s!\n", ip->i_name);
447 for (i = 0; i < nbomb; i++) {
448 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
450 pr(i == 0 ? "Bombable: " : ", ");
451 pr(ichr[bombcomm[i]].i_name);
457 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
458 plp = (struct plist *)qp;
459 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
461 if (plp->bombs || plp->plane.pln_nuketype != -1)
463 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
466 if (dam <= 0) /* dam == 0 if only nukes were delivered */
468 getsect(target->sct_x, target->sct_y, §);
470 before = amt = target->sct_item[ip->i_vtype];
471 target->sct_item[ip->i_vtype] = amt = commdamage(amt, dam, ip->i_vtype);
473 b = 100.0 * (1.0 - ((float)amt / (float)before));
476 pr("did %.2f%% damage to %s in %s\n",
477 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
478 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
479 if (target->sct_own != 0)
480 wu(0, target->sct_own,
481 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
482 cname(player->cnum), b, ip->i_name,
483 xyas(target->sct_x, target->sct_y, target->sct_own));
485 collateral_damage(target->sct_x, target->sct_y, dam, list);
489 ship_bomb(struct emp_qelem *list, struct sctstr *target)
497 struct emp_qelem *qp;
502 struct shiplook head, *s, *s2;
512 memset(&head, 0, sizeof(struct shiplook));
514 onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
515 for (qp = list->q_forw; qp != list && !player->aborted;
517 if (head.uid != -1) {
519 while (s != (struct shiplook *)0) {
525 memset(&head, 0, sizeof(struct shiplook));
527 plp = (struct plist *)qp;
528 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
530 if (plp->pcp->pl_flags & P_A)
531 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
534 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
536 pr("%s could not find any ships!\n", prplane(&plp->plane));
539 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
540 prplane(&plp->plane), plp->bombs);
543 while (shipno < 0 && !player->aborted && !ignore) {
544 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
551 if (plp->pcp->pl_flags & P_A)
554 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
564 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
565 ship.shp_y == target->sct_y)
572 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
574 shell = ship.shp_item[I_SHELL];
576 shell = supply_commod(ship.shp_own, ship.shp_x,
577 ship.shp_y, I_SHELL, 1);
579 mcp = &mchr[(int)ship.shp_type];
580 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
581 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
582 ship.shp_item[I_SHELL] = shell;
583 putship(ship.shp_uid, &ship);
584 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
585 flak, prship(&ship));
586 PR(ship.shp_own, msg);
587 if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
592 if (plp->plane.pln_nuketype != -1)
596 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
597 pr("%d%% hitchance...", hitchance);
599 if (roll(100) <= hitchance) {
600 /* pinbombing is more accurate than normal bombing */
602 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
606 /* Bombs that miss have to land somewhere! */
608 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
610 collateral_damage(target->sct_x, target->sct_y, dam, list);
613 if (dam <= 0) /* dam == 0 if only nukes were delivered */
615 if (mcp->m_flags & M_SUB)
616 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
618 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
620 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
621 cname(player->cnum), dam,
623 xyas(target->sct_x, target->sct_y, ship.shp_own));
626 check_retreat_and_do_shipdamage(&ship, dam);
627 if (ship.shp_rflags & RET_BOMBED)
628 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
629 retreat_ship(&ship, 'b');
630 putship(ship.shp_uid, &ship);
631 getship(ship.shp_uid, &ship);
633 pr("%s at %s sunk!\n",
635 xyas(target->sct_x, target->sct_y, player->cnum));
637 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
642 while (s != (struct shiplook *)0) {
650 plane_bomb(struct emp_qelem *list, struct sctstr *target)
657 struct emp_qelem *qp;
667 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
668 plp = (struct plist *)qp;
669 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
671 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
673 pr("%s could not find any planes!\n", prplane(&plp->plane));
676 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
677 prplane(&plp->plane), plp->bombs);
680 while (planeno < 0 && !player->aborted && !ignore) {
681 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
688 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
696 if (getplane(n, &plane) &&
697 plane.pln_x == target->sct_x &&
698 plane.pln_y == target->sct_y &&
699 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
700 (!ac_isflying(&plane, list)))
703 pr("Plane #%d not spotted\n", n);
708 if (plp->plane.pln_nuketype != -1)
711 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
712 pr("%d%% hitchance...", hitchance);
714 if (roll(100) <= hitchance) {
715 /* pinbombing is more accurate than normal bombing */
717 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
721 /* Bombs that miss have to land somewhere! */
723 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
725 collateral_damage(target->sct_x, target->sct_y, dam, list);
728 if (dam <= 0) /* dam == 0 if only nukes were delivered */
733 if (dam > plane.pln_effic) {
735 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
739 plane.pln_effic -= dam;
740 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
741 if (own == player->cnum) {
742 pr("%s reports %d%% damage\n", prplane(&plane), dam);
746 "%s pinpoint bombing raid did %d%% damage to %s\n",
747 cname(player->cnum), dam, prplane(&plane));
749 nreport(player->cnum, N_DOWN_PLANE, own, 1);
751 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
752 cname(player->cnum), dam, prplane(&plane),
753 xyas(target->sct_x, target->sct_y, own));
754 putplane(plane.pln_uid, &plane);
755 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
762 land_bomb(struct emp_qelem *list, struct sctstr *target)
773 struct emp_qelem *qp;
775 int ignore, flak, hitchance;
780 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
781 plp = (struct plist *)qp;
782 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
784 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
786 pr("%s could not find any units!\n", prplane(&plp->plane));
789 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
790 prplane(&plp->plane), plp->bombs);
793 while (unitno < 0 && !player->aborted && !ignore) {
794 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
801 unitsatxy(target->sct_x, target->sct_y, 0, 0);
809 if (getland(n, &land) &&
810 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
813 pr("Unit #%d not spotted\n", n);
818 lcp = &lchr[(int)land.lnd_type];
820 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
823 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
824 prland(&land), land.lnd_aaf);
825 PR(land.lnd_own, msg);
826 if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
831 if (plp->plane.pln_nuketype != -1)
835 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
836 pr("%d%% hitchance...", hitchance);
838 if (roll(100) <= hitchance) {
840 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
844 /* Bombs that miss have to land somewhere! */
846 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
848 collateral_damage(target->sct_x, target->sct_y, dam, list);
851 if (dam <= 0) /* dam == 0 if only nukes were delivered */
858 "%s pinpoint bombing raid did %d damage to %s\n",
859 cname(player->cnum), dam, prland(&land));
860 check_retreat_and_do_landdamage(&land, dam);
862 if (land.lnd_rflags & RET_BOMBED)
863 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
864 retreat_land(&land, 'b');
865 nreport(player->cnum, N_UNIT_BOMB, own, 1);
866 putland(land.lnd_uid, &land);
867 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
874 strat_bomb(struct emp_qelem *list, struct sctstr *target)
876 register struct plist *plp;
878 struct emp_qelem *qp;
882 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
883 plp = (struct plist *)qp;
884 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
886 if (plp->bombs || plp->plane.pln_nuketype != -1)
888 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
891 if (dam <= 0) /* dam == 0 if only nukes were delivered */
893 getsect(target->sct_x, target->sct_y, §);
896 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
897 cname(player->cnum), PERCENT_DAMAGE(dam),
898 xyas(target->sct_x, target->sct_y, target->sct_own));
900 sectdamage(target, dam, list);
902 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
903 xyas(target->sct_x, target->sct_y, player->cnum));
908 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
909 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
913 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
926 flak -= (pp->pln_def + 1);
927 if (pcp->pl_flags & P_X)
929 if (pcp->pl_flags & P_H)
932 mult = lflaktable[FLAK_MAX] * 1.33;
934 mult = lflaktable[0] * 0.66;
937 mult = lflaktable[flak];
940 dam = (int)((roll(8) + 2) * mult);
945 plane_owner = pp->pln_own;
949 memset(dmess, 0, sizeof(dmess));
953 if (eff < PLANE_MINEFF) {
954 sprintf(dmess, " -- shot down");
956 } else if (chance((100 - eff) / 100.0)) {
957 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
960 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
961 cname(pp->pln_own), prplane(pp), dam, dmess);
962 PR(plane_owner, mesg);
967 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
968 if (pp->pln_ship >= 0) {
969 getship(pp->pln_ship, &ship);
970 take_plane_off_ship(pp, &ship);
972 if (pp->pln_land >= 0) {
973 getland(pp->pln_land, &land);
974 take_plane_off_land(pp, &land);
976 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
978 putplane(pp->pln_uid, pp);
980 putplane(pp->pln_uid, pp);