2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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
57 static void pin_bomb(struct emp_qelem *list, struct sctstr *target);
58 static void strat_bomb(struct emp_qelem *list, struct sctstr *target);
59 static void comm_bomb(struct emp_qelem *list, struct sctstr *target);
60 static void eff_bomb(struct emp_qelem *list, struct sctstr *target);
62 static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
63 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
64 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
65 int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp,
66 natid from, int flak);
68 static int bombcomm[] = {
84 static int nbomb = sizeof(bombcomm) / sizeof(int);
96 s_char flightpath[MAX_PATH_LEN];
97 struct nstr_item ni_bomb;
98 struct nstr_item ni_esc;
100 struct sctstr target;
101 struct emp_qelem bomb_list;
102 struct emp_qelem esc_list;
104 struct sctstr ap_sect;
111 if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
114 (&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf)))
115 pr("No escorts...\n");
117 getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
120 if (index("ps", mission) == 0)
122 if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0
125 if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
127 if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
128 getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
129 pr("Assembly point not owned by you or an ally!\n");
134 if (getpath(flightpath, player->argp[5], ax, ay, 0, 0,
135 0, P_FLYING) == 0 || *flightpath == 0)
139 (void)pathtoxy(flightpath, &tx, &ty, fcost);
140 pr("target sector is %s\n", xyas(tx, ty, player->cnum));
141 getsect(tx, ty, &target);
142 if (target.sct_type == SCT_SANCT) {
143 pr("You can't bomb that sector!\n");
147 ap_to_target = strlen(flightpath);
148 if (*(flightpath + strlen(flightpath) - 1) == 'h')
150 pr("range to target is %d\n", ap_to_target);
152 * select planes within range
155 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
156 2, wantflags, P_M | P_O);
157 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
158 2, wantflags | P_F | P_ESC, P_M | P_O);
160 * now arm and equip the bombers, transports, whatever.
161 * tech is stored in high 16 bits of mission_flags.
165 mission_flags |= P_X; /* stealth (shhh) */
166 mission_flags |= P_H; /* gets turned off if not all choppers */
168 pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0,
169 mission_flags, &tech);
170 if (QEMPTY(&bomb_list)) {
171 pr("No planes could be equipped for the mission.\n");
175 pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC,
176 mission_flags, &tech);
177 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
179 if (QEMPTY(&bomb_list)) {
180 pr("No planes got through fighter defenses\n");
184 pin_bomb(&bomb_list, &target);
188 natp = getnatp(player->cnum);
189 if (target.sct_own) {
190 rel = getrel(natp, target.sct_own);
191 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
192 && (target.sct_own) &&
193 (target.sct_oldown != player->cnum)) {
194 pr("You're not at war with them!\n");
201 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
202 strat_bomb(&bomb_list, &target);
205 pr("Bad mission %c\n", mission);
215 pin_bomb(struct emp_qelem *list, struct sctstr *target)
217 extern s_char *effadv();
226 struct emp_qelem *qp;
236 type = target->sct_type;
238 pr("Target sector is a %s constructed %s\n",
239 effadv((int)target->sct_effic), dcp->d_name);
241 plp = (struct plist *)list->q_forw;
242 if (plp->pcp->pl_flags & P_A) {
244 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
245 plp = (struct plist *)qp;
246 if (plp->plane.pln_acc < bestacc)
247 bestacc = plp->plane.pln_acc;
248 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
249 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
251 pr("Some subs are present in the sector.\n");
253 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
255 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
256 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
257 getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
260 ("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
262 if (p == 0 || *p == 0) {
273 natp = getnatp(player->cnum);
274 if (target->sct_own) {
275 rel = getrel(natp, target->sct_own);
276 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
277 && (target->sct_own) &&
278 (target->sct_oldown != player->cnum)) {
279 pr("You're not at war with them!\n");
285 pr("no units there\n");
288 land_bomb(list, target);
292 natp = getnatp(player->cnum);
293 if (target->sct_own) {
294 rel = getrel(natp, target->sct_own);
295 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
296 && (target->sct_own) &&
297 (target->sct_oldown != player->cnum)) {
298 pr("You're not at war with them!\n");
304 pr("no planes there\n");
307 plane_bomb(list, target);
311 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
313 pr("no ships there\n");
317 pr("no ships there\n");
321 ship_bomb(list, target);
325 natp = getnatp(player->cnum);
326 if (target->sct_own) {
327 rel = getrel(natp, target->sct_own);
328 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
329 && (target->sct_own) &&
330 (target->sct_oldown != player->cnum)) {
331 pr("You're not at war with them!\n");
337 for (i = 0; i < nbomb; i++) {
338 if (!vec[bombcomm[i]])
343 pr("No bombable commodities in %s\n",
344 xyas(target->sct_x, target->sct_y, player->cnum));
347 comm_bomb(list, target);
351 natp = getnatp(player->cnum);
352 if (target->sct_own) {
353 rel = getrel(natp, target->sct_own);
354 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
355 && (target->sct_own) &&
356 (target->sct_oldown != player->cnum)) {
357 pr("You're not at war with them!\n");
362 eff_bomb(list, target);
365 pr("Aborting mission.\n");
368 pr("Bad target type.\n");
374 eff_bomb(struct emp_qelem *list, struct sctstr *target)
376 register struct plist *plp;
377 struct emp_qelem *qp;
382 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
383 plp = (struct plist *)qp;
384 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
386 if (plp->bombs || plp->plane.pln_nuketype != -1)
388 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
391 if (dam <= 0) /* dam == 0 if only nukes were delivered */
393 getsect(target->sct_x, target->sct_y, §);
395 oldeff = target->sct_effic;
396 target->sct_effic = effdamage(target->sct_effic, dam);
397 target->sct_road = effdamage(target->sct_road, dam);
398 target->sct_rail = effdamage(target->sct_rail, dam);
399 target->sct_defense = effdamage(target->sct_defense, dam);
400 if (!opt_DEFENSE_INFRA)
401 target->sct_defense = target->sct_effic;
402 pr("did %d%% damage to efficiency in %s\n",
403 oldeff - target->sct_effic,
404 xyas(target->sct_x, target->sct_y, player->cnum));
406 wu(0, target->sct_own,
407 "%s bombing raid did %d%% damage in %s\n",
408 cname(player->cnum), oldeff - target->sct_effic,
409 xyas(target->sct_x, target->sct_y, target->sct_own));
410 if (target->sct_effic < 20) {
411 if (target->sct_type == SCT_BSPAN)
412 knockdown(target, list);
413 else if (target->sct_type == SCT_BTOWER) {
414 knockdown(target, list);
415 bridgefall(target, list);
419 collateral_damage(target->sct_x, target->sct_y, dam, list);
423 comm_bomb(struct emp_qelem *list, struct sctstr *target)
425 register struct plist *plp;
431 struct emp_qelem *qp;
436 getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
437 for (i = 0; i < nbomb; i++) {
438 if (vec[bombcomm[i]] == 0)
440 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
442 ip = &ichr[bombcomm[i]];
443 pr("some %s\n", ip->i_name);
446 ip = whatitem((s_char *)0, "commodity to bomb? ");
452 for (i = 0; i < nbomb; i++) {
453 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
455 if (&ichr[bombcomm[i]] == ip)
459 pr("You can't bomb %s!\n", ip->i_name);
460 for (i = 0; i < nbomb; i++) {
461 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
463 pr(i == 0 ? "Bombable: " : ", ");
464 pr(ichr[bombcomm[i]].i_name);
470 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
471 plp = (struct plist *)qp;
472 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
474 if (plp->bombs || plp->plane.pln_nuketype != -1)
476 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
479 if (dam <= 0) /* dam == 0 if only nukes were delivered */
481 getsect(target->sct_x, target->sct_y, §);
483 before = amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR);
484 putvar(ip->i_vtype, commdamage(amt, dam, ip->i_vtype),
485 (s_char *)target, EF_SECTOR);
486 amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR);
488 b = 100.0 * (1.0 - ((float)amt / (float)before));
491 pr("did %.2f%% damage to %s in %s\n",
492 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
493 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
494 if (target->sct_own != 0)
495 wu(0, target->sct_own,
496 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
497 cname(player->cnum), b, ip->i_name,
498 xyas(target->sct_x, target->sct_y, target->sct_own));
500 collateral_damage(target->sct_x, target->sct_y, dam, list);
504 ship_bomb(struct emp_qelem *list, struct sctstr *target)
512 struct emp_qelem *qp;
517 struct shiplook head, *s, *s2;
527 bzero((s_char *)&head, sizeof(struct shiplook));
529 onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
530 for (qp = list->q_forw; qp != list && !player->aborted;
532 if (head.uid != -1) {
534 while (s != (struct shiplook *)0) {
540 bzero((s_char *)&head, sizeof(struct shiplook));
542 plp = (struct plist *)qp;
543 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
545 if (plp->pcp->pl_flags & P_A)
546 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
549 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
551 pr("%s could not find any ships!\n", prplane(&plp->plane));
554 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
555 prplane(&plp->plane), plp->bombs);
558 while (shipno < 0 && !player->aborted && !ignore) {
559 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
566 if (plp->pcp->pl_flags & P_A)
569 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
579 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
580 ship.shp_y == target->sct_y)
587 gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim);
589 shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP);
591 shell = supply_commod(ship.shp_own, ship.shp_x,
592 ship.shp_y, I_SHELL, 1);
594 mcp = &mchr[(int)ship.shp_type];
595 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
596 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
597 putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP);
598 putship(ship.shp_uid, &ship);
599 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
600 flak, prship(&ship));
601 PR(ship.shp_own, msg);
602 if (pinflak_planedamage
603 (&plp->plane, plp->pcp, ship.shp_own, flak))
608 if (plp->plane.pln_nuketype != -1)
612 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
613 pr("%d%% hitchance...", hitchance);
615 if (roll(100) <= hitchance) {
616 /* pinbombing is more accurate than normal bombing */
618 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
622 /* Bombs that miss have to land somewhere! */
624 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
626 collateral_damage(target->sct_x, target->sct_y, dam, list);
629 if (dam <= 0) /* dam == 0 if only nukes were delivered */
631 if (mcp->m_flags & M_SUB)
632 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
634 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
636 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
637 cname(player->cnum), dam,
639 xyas(target->sct_x, target->sct_y, ship.shp_own));
642 check_retreat_and_do_shipdamage(&ship, dam);
643 if (ship.shp_rflags & RET_BOMBED)
644 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
645 retreat_ship(&ship, 'b');
646 putship(ship.shp_uid, &ship);
649 pr("%s at %s sunk!\n",
651 xyas(target->sct_x, target->sct_y, player->cnum));
653 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
658 while (s != (struct shiplook *)0) {
666 plane_bomb(struct emp_qelem *list, struct sctstr *target)
673 struct emp_qelem *qp;
683 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
684 plp = (struct plist *)qp;
685 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
687 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
689 pr("%s could not find any planes!\n", prplane(&plp->plane));
692 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
693 prplane(&plp->plane), plp->bombs);
696 while (planeno < 0 && !player->aborted && !ignore) {
697 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
704 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
712 if (getplane(n, &plane) &&
713 plane.pln_x == target->sct_x &&
714 plane.pln_y == target->sct_y &&
715 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
716 (!ac_isflying(&plane, list)))
719 pr("Plane #%d not spotted\n", n);
724 if (plp->plane.pln_nuketype != -1)
727 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
728 pr("%d%% hitchance...", hitchance);
730 if (roll(100) <= hitchance) {
731 /* pinbombing is more accurate than normal bombing */
733 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
737 /* Bombs that miss have to land somewhere! */
739 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
741 collateral_damage(target->sct_x, target->sct_y, dam, list);
744 if (dam <= 0) /* dam == 0 if only nukes were delivered */
749 if (dam > plane.pln_effic) {
751 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
755 plane.pln_effic -= dam;
756 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
757 if (own == player->cnum) {
758 pr("%s reports %d%% damage\n", prplane(&plane), dam);
762 "%s pinpoint bombing raid did %d%% damage to %s\n",
763 cname(player->cnum), dam, prplane(&plane));
765 nreport(player->cnum, N_DOWN_PLANE, own, 1);
767 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
768 cname(player->cnum), dam, prplane(&plane),
769 xyas(target->sct_x, target->sct_y, own));
770 putplane(plane.pln_uid, &plane);
771 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
778 land_bomb(struct emp_qelem *list, struct sctstr *target)
789 struct emp_qelem *qp;
791 int ignore, flak, hitchance;
796 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
797 plp = (struct plist *)qp;
798 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
800 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
802 pr("%s could not find any units!\n", prplane(&plp->plane));
805 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
806 prplane(&plp->plane), plp->bombs);
809 while (unitno < 0 && !player->aborted && !ignore) {
810 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
817 unitsatxy(target->sct_x, target->sct_y, 0, 0);
825 if (getland(n, &land) &&
826 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
829 pr("Unit #%d not spotted\n", n);
834 lcp = &lchr[(int)land.lnd_type];
836 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
839 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
840 prland(&land), land.lnd_aaf);
841 PR(land.lnd_own, msg);
842 if (pinflak_planedamage
843 (&plp->plane, plp->pcp, land.lnd_own, flak))
848 if (plp->plane.pln_nuketype != -1)
852 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
853 pr("%d%% hitchance...", hitchance);
855 if (roll(100) <= hitchance) {
857 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
861 /* Bombs that miss have to land somewhere! */
863 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
865 collateral_damage(target->sct_x, target->sct_y, dam, list);
868 if (dam <= 0) /* dam == 0 if only nukes were delivered */
875 "%s pinpoint bombing raid did %d damage to %s\n",
876 cname(player->cnum), dam, prland(&land));
877 check_retreat_and_do_landdamage(&land, dam);
879 if (land.lnd_rflags & RET_BOMBED)
880 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
881 retreat_land(&land, 'b');
882 nreport(player->cnum, N_UNIT_BOMB, own, 1);
883 putland(land.lnd_uid, &land);
884 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
891 strat_bomb(struct emp_qelem *list, struct sctstr *target)
893 register struct plist *plp;
895 struct emp_qelem *qp;
899 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
900 plp = (struct plist *)qp;
901 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
903 if (plp->bombs || plp->plane.pln_nuketype != -1)
905 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
908 if (dam <= 0) /* dam == 0 if only nukes were delivered */
910 getsect(target->sct_x, target->sct_y, §);
913 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
914 cname(player->cnum), PERCENT_DAMAGE(dam),
915 xyas(target->sct_x, target->sct_y, target->sct_own));
917 sectdamage(target, dam, list);
919 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
920 xyas(target->sct_x, target->sct_y, player->cnum));
925 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
926 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
929 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
932 extern double flakscale;
943 flak -= (pp->pln_def + 1);
944 if (pcp->pl_flags & P_X)
946 if (pcp->pl_flags & P_H)
949 mult = lflaktable[FLAK_MAX] * 1.33;
951 mult = lflaktable[0] * 0.66;
954 mult = lflaktable[flak];
957 dam = (int)((roll(8) + 2) * mult);
962 plane_owner = pp->pln_own;
970 if (eff < PLANE_MINEFF) {
971 sprintf(dmess, " -- shot down");
973 } else if (chance((100 - eff) / 100.0)) {
974 sprintf(dmess, " -- aborted with %d%%%% damage", 100 - eff);
977 sprintf(mesg, " Flak! %s %s takes %d%s.\n",
978 cname(pp->pln_own), prplane(pp), dam, dmess);
979 PR(plane_owner, mesg);
984 nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
985 if (pp->pln_ship >= 0) {
986 getship(pp->pln_ship, &ship);
987 take_plane_off_ship(pp, &ship);
989 if (pp->pln_land >= 0) {
990 getland(pp->pln_land, &land);
991 take_plane_off_land(pp, &land);
993 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
995 putplane(pp->pln_uid, pp);
997 putplane(pp->pln_uid, pp);