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);
61 static int pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp,
62 natid from, int flak);
63 static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
64 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
65 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
67 static int bombcomm[] = {
83 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]))
113 (&ni_esc, EF_PLANE, getstarg(player->argp[2], "escort(s)? ", buf)))
114 pr("No escorts...\n");
116 getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
119 if (index("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);
141 if (target.sct_type == SCT_SANCT) {
142 pr("You can't bomb that sector!\n");
146 ap_to_target = strlen(flightpath);
147 if (*(flightpath + strlen(flightpath) - 1) == 'h')
149 pr("range to target is %d\n", ap_to_target);
151 * select planes within range
154 pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
155 2, wantflags, P_M | P_O);
156 pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
157 2, wantflags | P_F | P_ESC, P_M | P_O);
159 * now arm and equip the bombers, transports, whatever.
160 * tech is stored in high 16 bits of mission_flags.
164 mission_flags |= P_X; /* stealth (shhh) */
165 mission_flags |= P_H; /* gets turned off if not all choppers */
167 pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0,
168 mission_flags, &tech);
169 if (QEMPTY(&bomb_list)) {
170 pr("No planes could be equipped for the mission.\n");
174 pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC,
175 mission_flags, &tech);
176 ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
178 if (QEMPTY(&bomb_list)) {
179 pr("No planes got through fighter defenses\n");
183 pin_bomb(&bomb_list, &target);
187 natp = getnatp(player->cnum);
188 if (target.sct_own) {
189 rel = getrel(natp, target.sct_own);
190 if ((rel != AT_WAR) && (player->cnum != target.sct_own)
191 && (target.sct_own) &&
192 (target.sct_oldown != player->cnum)) {
193 pr("You're not at war with them!\n");
200 nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
201 strat_bomb(&bomb_list, &target);
204 pr("Bad mission %c\n", mission);
214 pin_bomb(struct emp_qelem *list, struct sctstr *target)
216 extern s_char *effadv();
225 struct emp_qelem *qp;
235 type = target->sct_type;
237 pr("Target sector is a %s constructed %s\n",
238 effadv((int)target->sct_effic), dcp->d_name);
240 plp = (struct plist *)list->q_forw;
241 if (plp->pcp->pl_flags & P_A) {
243 for (qp = list->q_forw; qp != list; qp = qp->q_forw)
244 plp = (struct plist *)qp;
245 if (plp->plane.pln_acc < bestacc)
246 bestacc = plp->plane.pln_acc;
247 nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
248 nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
250 pr("Some subs are present in the sector.\n");
252 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
254 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
255 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
256 getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
259 ("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
261 if (p == 0 || *p == 0) {
272 natp = getnatp(player->cnum);
273 if (target->sct_own) {
274 rel = getrel(natp, target->sct_own);
275 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
276 && (target->sct_own) &&
277 (target->sct_oldown != player->cnum)) {
278 pr("You're not at war with them!\n");
284 pr("no units there\n");
287 land_bomb(list, target);
291 natp = getnatp(player->cnum);
292 if (target->sct_own) {
293 rel = getrel(natp, target->sct_own);
294 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
295 && (target->sct_own) &&
296 (target->sct_oldown != player->cnum)) {
297 pr("You're not at war with them!\n");
303 pr("no planes there\n");
306 plane_bomb(list, target);
310 if (((struct plist *)list->q_forw)->pcp->pl_flags & P_A) {
312 pr("no ships there\n");
316 pr("no ships there\n");
320 ship_bomb(list, target);
324 natp = getnatp(player->cnum);
325 if (target->sct_own) {
326 rel = getrel(natp, target->sct_own);
327 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
328 && (target->sct_own) &&
329 (target->sct_oldown != player->cnum)) {
330 pr("You're not at war with them!\n");
336 for (i = 0; i < nbomb; i++) {
337 if (!vec[bombcomm[i]])
342 pr("No bombable commodities in %s\n",
343 xyas(target->sct_x, target->sct_y, player->cnum));
346 comm_bomb(list, target);
350 natp = getnatp(player->cnum);
351 if (target->sct_own) {
352 rel = getrel(natp, target->sct_own);
353 if ((rel != AT_WAR) && (player->cnum != target->sct_own)
354 && (target->sct_own) &&
355 (target->sct_oldown != player->cnum)) {
356 pr("You're not at war with them!\n");
361 eff_bomb(list, target);
364 pr("Aborting mission.\n");
367 pr("Bad target type.\n");
373 eff_bomb(struct emp_qelem *list, struct sctstr *target)
375 register struct plist *plp;
376 struct emp_qelem *qp;
381 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
382 plp = (struct plist *)qp;
383 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
385 if (plp->bombs || plp->plane.pln_nuketype != -1)
387 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
390 if (dam <= 0) /* dam == 0 if only nukes were delivered */
392 getsect(target->sct_x, target->sct_y, §);
394 oldeff = target->sct_effic;
395 target->sct_effic = effdamage(target->sct_effic, dam);
396 target->sct_road = effdamage(target->sct_road, dam);
397 target->sct_rail = effdamage(target->sct_rail, dam);
398 target->sct_defense = effdamage(target->sct_defense, dam);
399 if (!opt_DEFENSE_INFRA)
400 target->sct_defense = target->sct_effic;
401 pr("did %d%% damage to efficiency in %s\n",
402 oldeff - target->sct_effic,
403 xyas(target->sct_x, target->sct_y, player->cnum));
405 wu(0, target->sct_own,
406 "%s bombing raid did %d%% damage in %s\n",
407 cname(player->cnum), oldeff - target->sct_effic,
408 xyas(target->sct_x, target->sct_y, target->sct_own));
409 if (target->sct_effic < 20) {
410 if (target->sct_type == SCT_BSPAN)
411 knockdown(target, list);
412 else if (target->sct_type == SCT_BTOWER) {
413 knockdown(target, list);
414 bridgefall(target, list);
418 collateral_damage(target->sct_x, target->sct_y, dam, list);
422 comm_bomb(struct emp_qelem *list, struct sctstr *target)
424 register struct plist *plp;
430 struct emp_qelem *qp;
435 getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
436 for (i = 0; i < nbomb; i++) {
437 if (vec[bombcomm[i]] == 0)
439 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
441 ip = &ichr[bombcomm[i]];
442 pr("some %s\n", ip->i_name);
445 ip = whatitem((s_char *)0, "commodity to bomb? ");
451 for (i = 0; i < nbomb; i++) {
452 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
454 if (&ichr[bombcomm[i]] == ip)
458 pr("You can't bomb %s!\n", ip->i_name);
459 for (i = 0; i < nbomb; i++) {
460 if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
462 pr(i == 0 ? "Bombable: " : ", ");
463 pr(ichr[bombcomm[i]].i_name);
469 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
470 plp = (struct plist *)qp;
471 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
473 if (plp->bombs || plp->plane.pln_nuketype != -1)
475 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
478 if (dam <= 0) /* dam == 0 if only nukes were delivered */
480 getsect(target->sct_x, target->sct_y, §);
482 before = amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR);
483 putvar(ip->i_vtype, commdamage(amt, dam, ip->i_vtype),
484 (s_char *)target, EF_SECTOR);
485 amt = getvar(ip->i_vtype, (s_char *)target, EF_SECTOR);
487 b = 100.0 * (1.0 - ((float)amt / (float)before));
490 pr("did %.2f%% damage to %s in %s\n",
491 b, ip->i_name, xyas(target->sct_x, target->sct_y, player->cnum));
492 nreport(player->cnum, N_SCT_BOMB, target->sct_own, 1);
493 if (target->sct_own != 0)
494 wu(0, target->sct_own,
495 "%s precision bombing raid did %.2f%% damage to %s in %s\n",
496 cname(player->cnum), b, ip->i_name,
497 xyas(target->sct_x, target->sct_y, target->sct_own));
499 collateral_damage(target->sct_x, target->sct_y, dam, list);
503 ship_bomb(struct emp_qelem *list, struct sctstr *target)
511 struct emp_qelem *qp;
516 struct shiplook head, *s, *s2;
526 memset(&head, 0, sizeof(struct shiplook));
528 onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
529 for (qp = list->q_forw; qp != list && !player->aborted;
531 if (head.uid != -1) {
533 while (s != (struct shiplook *)0) {
539 memset(&head, 0, sizeof(struct shiplook));
541 plp = (struct plist *)qp;
542 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
544 if (plp->pcp->pl_flags & P_A)
545 nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
548 nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
550 pr("%s could not find any ships!\n", prplane(&plp->plane));
553 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
554 prplane(&plp->plane), plp->bombs);
557 while (shipno < 0 && !player->aborted && !ignore) {
558 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
565 if (plp->pcp->pl_flags & P_A)
568 shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
578 if (getship(n, &ship) && ship.shp_x == target->sct_x &&
579 ship.shp_y == target->sct_y)
586 gun = min(getvar(V_GUN, (s_char *)&ship, EF_SHIP), ship.shp_glim);
588 shell = getvar(V_SHELL, (s_char *)&ship, EF_SHIP);
590 shell = supply_commod(ship.shp_own, ship.shp_x,
591 ship.shp_y, I_SHELL, 1);
593 mcp = &mchr[(int)ship.shp_type];
594 if (gun > 0 && shell > 0 && !(mcp->m_flags & M_SUB)) {
595 flak = (int)(techfact(ship.shp_tech, (double)gun) * 2.0);
596 putvar(V_SHELL, shell, (s_char *)&ship, EF_SHIP);
597 putship(ship.shp_uid, &ship);
598 sprintf(msg, "Flak! Firing %d guns from ship %s\n",
599 flak, prship(&ship));
600 PR(ship.shp_own, msg);
601 if (pinflak_planedamage
602 (&plp->plane, plp->pcp, ship.shp_own, flak))
607 if (plp->plane.pln_nuketype != -1)
611 pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
612 pr("%d%% hitchance...", hitchance);
614 if (roll(100) <= hitchance) {
615 /* pinbombing is more accurate than normal bombing */
617 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
621 /* Bombs that miss have to land somewhere! */
623 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
625 collateral_damage(target->sct_x, target->sct_y, dam, list);
628 if (dam <= 0) /* dam == 0 if only nukes were delivered */
630 if (mcp->m_flags & M_SUB)
631 nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
633 nreport(player->cnum, N_SHP_BOMB, ship.shp_own, 1);
635 wu(0, ship.shp_own, "%s bombs did %d damage to %s at %s\n",
636 cname(player->cnum), dam,
638 xyas(target->sct_x, target->sct_y, ship.shp_own));
641 check_retreat_and_do_shipdamage(&ship, dam);
642 if (ship.shp_rflags & RET_BOMBED)
643 if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
644 retreat_ship(&ship, 'b');
645 putship(ship.shp_uid, &ship);
648 pr("%s at %s sunk!\n",
650 xyas(target->sct_x, target->sct_y, player->cnum));
652 collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
657 while (s != (struct shiplook *)0) {
665 plane_bomb(struct emp_qelem *list, struct sctstr *target)
672 struct emp_qelem *qp;
682 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
683 plp = (struct plist *)qp;
684 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
686 nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
688 pr("%s could not find any planes!\n", prplane(&plp->plane));
691 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
692 prplane(&plp->plane), plp->bombs);
695 while (planeno < 0 && !player->aborted && !ignore) {
696 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
703 planesatxy(target->sct_x, target->sct_y, 0, 0, list);
711 if (getplane(n, &plane) &&
712 plane.pln_x == target->sct_x &&
713 plane.pln_y == target->sct_y &&
714 ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
715 (!ac_isflying(&plane, list)))
718 pr("Plane #%d not spotted\n", n);
723 if (plp->plane.pln_nuketype != -1)
726 hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
727 pr("%d%% hitchance...", hitchance);
729 if (roll(100) <= hitchance) {
730 /* pinbombing is more accurate than normal bombing */
732 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
736 /* Bombs that miss have to land somewhere! */
738 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
740 collateral_damage(target->sct_x, target->sct_y, dam, list);
743 if (dam <= 0) /* dam == 0 if only nukes were delivered */
748 if (dam > plane.pln_effic) {
750 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
754 plane.pln_effic -= dam;
755 plane.pln_mobil = (dam * plane.pln_mobil / 100.0);
756 if (own == player->cnum) {
757 pr("%s reports %d%% damage\n", prplane(&plane), dam);
761 "%s pinpoint bombing raid did %d%% damage to %s\n",
762 cname(player->cnum), dam, prplane(&plane));
764 nreport(player->cnum, N_DOWN_PLANE, own, 1);
766 wu(0, own, "%s bombs did %d%% damage to %s at %s\n",
767 cname(player->cnum), dam, prplane(&plane),
768 xyas(target->sct_x, target->sct_y, own));
769 putplane(plane.pln_uid, &plane);
770 collateral_damage(plane.pln_x, plane.pln_y, dam, list);
777 land_bomb(struct emp_qelem *list, struct sctstr *target)
788 struct emp_qelem *qp;
790 int ignore, flak, hitchance;
795 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
796 plp = (struct plist *)qp;
797 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
799 nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
801 pr("%s could not find any units!\n", prplane(&plp->plane));
804 (void)sprintf(prompt, "%s, %d bombs. Target ('~' to skip)? ",
805 prplane(&plp->plane), plp->bombs);
808 while (unitno < 0 && !player->aborted && !ignore) {
809 if ((q = getstring(prompt, buf)) == 0 || *q == 0)
816 unitsatxy(target->sct_x, target->sct_y, 0, 0);
824 if (getland(n, &land) &&
825 land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
828 pr("Unit #%d not spotted\n", n);
833 lcp = &lchr[(int)land.lnd_type];
835 flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
838 "Flak! Firing flak guns from unit %s (aa rating %d)\n",
839 prland(&land), land.lnd_aaf);
840 PR(land.lnd_own, msg);
841 if (pinflak_planedamage
842 (&plp->plane, plp->pcp, land.lnd_own, flak))
847 if (plp->plane.pln_nuketype != -1)
851 pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
852 pr("%d%% hitchance...", hitchance);
854 if (roll(100) <= hitchance) {
856 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
860 /* Bombs that miss have to land somewhere! */
862 pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
864 collateral_damage(target->sct_x, target->sct_y, dam, list);
867 if (dam <= 0) /* dam == 0 if only nukes were delivered */
874 "%s pinpoint bombing raid did %d damage to %s\n",
875 cname(player->cnum), dam, prland(&land));
876 check_retreat_and_do_landdamage(&land, dam);
878 if (land.lnd_rflags & RET_BOMBED)
879 if (((land.lnd_rflags & RET_INJURED) == 0) || !dam)
880 retreat_land(&land, 'b');
881 nreport(player->cnum, N_UNIT_BOMB, own, 1);
882 putland(land.lnd_uid, &land);
883 collateral_damage(land.lnd_x, land.lnd_y, dam, list);
890 strat_bomb(struct emp_qelem *list, struct sctstr *target)
892 register struct plist *plp;
894 struct emp_qelem *qp;
898 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
899 plp = (struct plist *)qp;
900 if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
902 if (plp->bombs || plp->plane.pln_nuketype != -1)
904 pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
907 if (dam <= 0) /* dam == 0 if only nukes were delivered */
909 getsect(target->sct_x, target->sct_y, §);
912 wu(0, target->sct_own, "%s bombing raid did %d damage in %s\n",
913 cname(player->cnum), PERCENT_DAMAGE(dam),
914 xyas(target->sct_x, target->sct_y, target->sct_own));
916 sectdamage(target, dam, list);
918 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
919 xyas(target->sct_x, target->sct_y, player->cnum));
924 float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
925 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;
966 memset(dmess, 0, sizeof(dmess));
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);