2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 * plnsub.c: Plane subroutine stuff
30 * Known contributors to this file:
33 * Steve McClure, 1998-2000
34 * Markus Armbruster, 2004-2009
52 #include "prototypes.h"
57 static int pln_equip(struct plist *, struct ichrstr *, char);
58 static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
61 * Get planes and escorts argument.
62 * Read planes into *NI_BOMB, and (optional) escorts into *NI_ESC.
63 * If INPUT_BOMB is not empty, use it, else prompt for more input.
65 * If we got a plane argument, initialize *NI_BOMB and *NI_ESC, and
67 * Else return -1 (*NI_BOMB and *NI_ESC may be modified).
70 get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc,
71 char *input_bomb, char *input_esc)
73 if (!snxtitem(ni_bomb, EF_PLANE, input_bomb, NULL))
75 if (!snxtitem(ni_esc, EF_PLANE, input_esc, "escort(s)? ")) {
78 pr("No escorts...\n");
84 * Get assembly point argument.
85 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
86 * If this yields a valid assembly point, read it into *AP_SECT and
88 * Else complain and return NULL.
89 * *AP_SECT and BUF[1024] may be modified in either case.
92 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
99 p = getstarg(input, "assembly point? ", buf);
102 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
105 /* over own or allied sector is fine */
106 if (ap_sect->sct_own == player->cnum
107 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
110 /* over own or allied ship is fine */
111 snxtitem_xy(&ni, EF_SHIP, x, y);
112 while (nxtitem(&ni, &ship)) {
113 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
115 if (ship.shp_own == player->cnum
116 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
120 pr("Assembly point not owned by you or an ally!\n");
125 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
137 nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
140 p = getstring("Carrier #? ", buf);
147 || !getship(cno, &ship)
149 && (getrel(getnatp(ship.shp_own), player->cnum)
154 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
155 pr("Ship #%d not in %s\n", cno,
156 xyas(target->sct_x, target->sct_y, player->cnum));
159 fl = carrier_planes(&ship, 0);
161 pr("Can't land on %s.\n", prship(&ship));
164 /* clear to land on ship#CNO */
165 pr("landing on carrier %d\n", cno);
173 /* try to land at sector */
174 if (target->sct_own != player->cnum
175 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
176 pr("Nowhere to land at sector %s!\n",
177 xyas(target->sct_x, target->sct_y, player->cnum));
180 if (target->sct_type == SCT_MOUNT) {
181 pr("Nowhere to land at sector %s!\n",
182 xyas(target->sct_x, target->sct_y, player->cnum));
185 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
188 /* clear to land at sector */
195 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
196 struct emp_qelem *esc_list, int cno)
198 struct emp_qelem *list, *qp;
202 if (cno < 0 || !getship(cno, &ship))
206 for (list = bomb_list;
208 list = list == bomb_list ? esc_list : NULL) {
209 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
210 plp = (struct plist *)qp;
211 if (plp->plane.pln_ship == ship.shp_uid)
213 if (!fit_plane_on_ship(&plp->plane, &ship))
221 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
223 struct emp_qelem *qp;
230 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
231 plp = (struct plist *)qp;
233 if (!could_be_on_ship(&plp->plane, &ship, 0, 0, 0, 0))
234 pr("\t%s cannot land on ship #%d! %s aborts!\n",
235 prplane(&plp->plane), cno, prplane(&plp->plane));
236 else if (!put_plane_on_ship(&plp->plane, &ship))
237 pr("\tNo room on ship #%d! %s aborts!\n",
238 cno, prplane(&plp->plane));
240 if (plp->plane.pln_own != ship.shp_own) {
241 wu(0, ship.shp_own, "%s %s lands on your %s\n",
242 cname(player->cnum), prplane(&plp->plane),
247 plp->plane.pln_x = tx;
248 plp->plane.pln_y = ty;
249 getsect(tx, ty, §);
250 if (plp->plane.pln_own != sect.sct_own) {
252 "%s %s lands at your sector %s\n",
254 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
256 plp->plane.pln_ship = cno;
262 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
265 struct emp_qelem *qp;
276 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
277 plp = (struct plist *)qp;
281 getsect(tx, ty, §);
283 if (sect.sct_type == SCT_WATER)
284 pr("Your %s sink like a rock!\n", ip->i_name);
286 pr("Your %s vanish without a trace.\n", ip->i_name);
289 if (sect.sct_own != player->cnum
290 && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
291 pr("You don't own %s! Cargo jettisoned...\n",
292 xyas(tx, ty, player->cnum));
295 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
296 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
297 xyas(tx, ty, player->cnum));
300 there = sect.sct_item[ip->i_uid];
304 there = ship.shp_item[ip->i_uid];
305 max = mchr[ship.shp_type].m_item[ip->i_uid];
309 pr("%d excess %s discarded\n", max - there, ip->i_name);
313 pr("%d %s landed safely", amt, ip->i_name);
315 sect.sct_item[ip->i_uid] = there;
316 if (sect.sct_own != player->cnum)
317 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
318 cname(player->cnum), amt, ip->i_name,
319 xyas(tx, ty, sect.sct_own));
320 pr(" at %s\n", xyas(tx, ty, player->cnum));
323 ship.shp_item[ip->i_uid] = there;
324 if (ship.shp_own != player->cnum)
325 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
326 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
327 pr(" on carrier #%d\n", ship.shp_uid);
328 putship(ship.shp_uid, &ship);
333 pln_mine(struct emp_qelem *list, coord tx, coord ty)
335 struct emp_qelem *qp;
341 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
342 plp = (struct plist *)qp;
347 getsect(tx, ty, §);
348 if (sect.sct_type != SCT_WATER) {
349 pr("Your seamines have no effect here.\n");
352 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
353 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
354 if (map_set(player->cnum, tx, ty, 'X', 0))
355 writemap(player->cnum);
361 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
362 * A plane type is capable unless
363 * - it lacks all of the P_B, P_T in WANTFLAGS, or
364 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
365 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
366 * - it lacks any of the other capabilities in WANTFLAGS, or
367 * - it has any of the capabilities in NOWANTFLAGS.
370 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
372 int flags = plchr[(int)pp->pln_type].pl_flags;
374 if (wantflags & (P_B | P_T)) {
375 if ((flags & wantflags & (P_B | P_T)) == 0)
377 wantflags &= ~(P_B | P_T);
380 if (wantflags & (P_F | P_ESC)) {
381 if ((flags & wantflags & (P_F | P_ESC)) == 0)
383 wantflags &= ~(P_F | P_ESC);
386 if (wantflags & (P_E | P_L | P_K)) {
387 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
389 wantflags &= ~(P_E | P_L | P_K);
392 if ((flags & wantflags) != wantflags)
395 if (flags & nowantflags)
402 * Return union of capabilities of planes in LIST.
405 pln_caps(struct emp_qelem *list)
407 struct emp_qelem *qp;
412 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
413 plp = (struct plist *)qp;
414 fl |= plp->pcp->pl_flags;
421 * Find plane types that can operate from carrier SP.
422 * If MSL find missile types, else non-missile types.
423 * Return a combination of P_L, P_K, P_E.
424 * It's zero if SP can't support air operations due to its type or
425 * state (low efficiency).
428 carrier_planes(struct shpstr *sp, int msl)
430 struct mchrstr *mcp = mchr + sp->shp_type;
433 if (sp->shp_effic < SHP_AIROPS_EFF)
437 if (mcp->m_flags & M_FLY)
439 if ((mcp->m_flags & M_MSL) && msl)
441 if (mcp->m_nchoppers && !msl)
449 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
454 struct plchrstr *pcp = plchr + pp->pln_type;
456 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
459 if (pp->pln_ship >= 0) {
460 /* ship: needs to be own or allied, efficient */
461 if (!getship(pp->pln_ship, &ship)) {
465 if (ship.shp_own != pp->pln_own
466 && getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED) {
468 pr("(note) An ally does not own the ship %s is on\n",
472 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
475 } else if (pp->pln_land >= 0) {
476 /* land: needs to be own or allied, efficient, not embarked */
477 if (!getland(pp->pln_land, &land)) {
481 if (land.lnd_own != pp->pln_own
482 && getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED) {
484 pr("(note) An ally does not own the unit %s is on\n",
488 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
490 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
494 /* sector: needs to be own or allied, efficient airfield */
495 if (!getsect(pp->pln_x, pp->pln_y, §)) {
500 if (sect.sct_own != pp->pln_own
501 && getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED) {
503 pr("(note) An ally does not own the sector %s is in\n",
507 /* need airfield unless VTOL */
508 if ((pcp->pl_flags & P_V) == 0) {
509 if (sect.sct_type != SCT_AIRPT) {
511 pr("%s not at airport\n", prplane(pp));
514 if (sect.sct_effic < 40) {
516 pr("%s is not 40%% efficient, %s can't take off from there.\n",
517 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
521 if (!oneway && sect.sct_effic < 60) {
523 pr("%s is not 60%% efficient, %s can't land there.\n",
524 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
535 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
536 int ap_to_target, int rangemult, int wantflags, int nowantflags)
540 struct plchrstr *pcp;
544 while (nxtitem(ni, &plane)) {
547 if (plane.pln_mobil <= 0)
549 if (plane.pln_effic < 40) {
550 pr("%s not efficient enough (must be 40%%)\n",
554 if (!pln_capable(&plane, wantflags, nowantflags))
557 if (ontradingblock(EF_PLANE, &plane)) {
558 pr("plane #%d inelligible - it's for sale.\n",
564 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
566 pr("%s too far from assembly point\n", prplane(&plane));
569 range += ap_to_target;
571 pcp = &plchr[(int)plane.pln_type];
572 if (plane.pln_range < range) {
573 pr("%s out of range (%d:%d)\n",
574 prplane(&plane), plane.pln_range, range);
577 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
579 pr("%s standing by\n", prplane(&plane));
580 plane.pln_mission = 0;
581 putplane(plane.pln_uid, &plane);
582 plp = malloc(sizeof(struct plist));
586 emp_insque(&plp->queue, list);
591 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
593 struct emp_qelem *qp;
594 struct emp_qelem *next;
598 for (qp = list->q_forw; qp != list; qp = next) {
600 plp = (struct plist *)qp;
602 getplane(pp->pln_uid, pp);
603 if ((pp->pln_flags & PLN_LAUNCHED)
604 || pln_equip(plp, ip, mission) < 0) {
609 pp->pln_flags |= PLN_LAUNCHED;
610 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
611 putplane(pp->pln_uid, pp);
612 pr("%s equipped\n", prplane(pp));
617 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
619 struct plchrstr *pcp;
632 if (pp->pln_ship >= 0) {
633 getship(pp->pln_ship, &ship);
634 item = ship.shp_item;
636 } else if (pp->pln_land >= 0) {
637 getland(pp->pln_land, &land);
638 item = land.lnd_item;
641 getsect(pp->pln_x, pp->pln_y, §);
642 item = sect.sct_item;
643 own = sect.sct_oldown;
645 if (pcp->pl_fuel > item[I_PETROL]) {
646 pr("%s not enough petrol there!\n", prplane(pp));
649 item[I_PETROL] -= pcp->pl_fuel;
653 case 's': /* strategic bomb */
654 case 'p': /* pinpoint bomb */
655 if (nuk_on_plane(pp) >= 0)
659 case 't': /* transport */
660 if (!(pcp->pl_flags & P_C) || !ip)
666 if ((pcp->pl_flags & P_MINE) == 0)
672 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
675 if (pcp->pl_flags & P_V)
678 case 'a': /* paradrop */
679 if (!(pcp->pl_flags & P_P))
682 if (pcp->pl_flags & P_V)
685 case 'r': /* reconnaissance */
686 case 'e': /* escort */
694 if (itype != I_NONE) {
695 needed = load / ichr[itype].i_lbs;
697 pr("%s can't contribute to mission\n", prplane(pp));
700 if (itype == I_CIVIL && pp->pln_own != own) {
701 pr("You don't control those civilians!\n");
705 /* Supply is broken somewhere, so don't use it for now */
706 if (itype == I_SHELL && item[itype] < needed)
707 item[itype] += supply_commod(plp->plane.pln_own,
712 abandon_needed = !!would_abandon(§, itype, needed, NULL);
713 if (item[itype] < needed + abandon_needed) {
714 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
717 item[itype] -= needed;
721 if (pp->pln_ship >= 0) {
722 if (pp->pln_own != ship.shp_own) {
724 "%s %s prepares for takeoff from ship %s\n",
725 cname(pp->pln_own), prplane(pp), prship(&ship));
727 putship(ship.shp_uid, &ship);
728 } else if (pp->pln_land >= 0) {
729 if (pp->pln_own != land.lnd_own) {
731 "%s %s prepares for takeoff from unit %s\n",
732 cname(pp->pln_own), prplane(pp), prland(&land));
734 putland(land.lnd_uid, &land);
736 if (pp->pln_own != sect.sct_own) {
737 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
738 cname(pp->pln_own), prplane(pp),
739 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
747 pln_put(struct emp_qelem *list)
749 struct emp_qelem *qp, *next;
751 for (qp = list->q_forw; qp != list; qp = next) {
753 pln_put1((struct plist *)qp);
758 pln_put1(struct plist *plp)
766 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
767 && (plchr[pp->pln_type].pl_flags & P_M)
768 && pp->pln_effic >= PLANE_MINEFF))
769 pp->pln_effic = 0; /* bug: missile launched but not used up */
771 if (!(pp->pln_flags & PLN_LAUNCHED))
772 ; /* never took off */
773 else if (pp->pln_effic < PLANE_MINEFF) {
775 } else if (pp->pln_ship >= 0) {
776 /* It is landing on a carrier */
777 getship(pp->pln_ship, &ship);
778 /* We should do more, like make sure it's really
779 a carrier, etc. but for now just make sure it's
781 if (ship.shp_effic < SHIP_MINEFF) {
783 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
784 "splashes into the sea.\n",
785 pp->pln_ship, pp->pln_uid);
789 /* Presume we are landing back in a sector. */
790 getsect(pp->pln_x, pp->pln_y, §);
791 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
793 "Nowhere to land at %s, plane #%d crashes and burns...\n",
794 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
798 pp->pln_flags &= ~PLN_LAUNCHED;
799 putplane(pp->pln_uid, pp);
800 emp_remque(&plp->queue);
805 * Can PP be loaded on a ship of SP's type?
806 * Assume that it already carries N planes, of which NCH are choppers,
807 * NXL xlight, NMSL light missiles, and the rest are light fixed-wing
811 could_be_on_ship(struct plnstr *pp, struct shpstr *sp,
812 int n, int nch, int nxl, int nmsl)
814 struct plchrstr *pcp = &plchr[pp->pln_type];
815 struct mchrstr *mcp = &mchr[sp->shp_type];
817 if (pcp->pl_flags & P_K)
819 else if (pcp->pl_flags & P_E)
821 else if (!(pcp->pl_flags & P_L))
823 else if (pcp->pl_flags & P_M)
827 n -= MIN(nch, mcp->m_nchoppers);
828 n -= MIN(nxl, mcp->m_nxlight);
829 if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
830 return 0; /* missile slots wanted */
831 if (nmsl < n && !(mcp->m_flags & M_FLY))
832 return 0; /* fixed-wing slots wanted */
833 return n <= mcp->m_nplanes;
837 * Fit a plane of PP's type on ship SP.
838 * Updating the plane accordingly is the caller's job.
839 * Return whether it fits.
842 fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
844 int n, nch, nxl, nmsl;
846 n = shp_nplane(sp, &nch, &nxl, &nmsl);
847 return could_be_on_ship(pp, sp, n, nch, nxl, nmsl);
851 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
853 if (plane->pln_ship == ship->shp_uid)
854 return 1; /* Already on ship */
856 if (!fit_plane_on_ship(plane, ship))
859 plane->pln_x = ship->shp_x;
860 plane->pln_y = ship->shp_y;
861 plane->pln_ship = ship->shp_uid;
862 putplane(plane->pln_uid, plane);
867 * Fit a plane of PP's type on land unit LP.
868 * Updating the plane accordingly is the caller's job.
869 * Return whether it fits.
872 fit_plane_on_land(struct plnstr *pp, struct lndstr *lp)
874 struct plchrstr *pcp = plchr + pp->pln_type;
875 struct lchrstr *lcp = lchr + lp->lnd_type;
877 return (pcp->pl_flags & P_E) && lnd_nxlight(lp) < lcp->l_nxlight;
881 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
883 if (plane->pln_land == land->lnd_uid)
884 return 1; /* Already on unit */
886 if (!fit_plane_on_land(plane, land))
889 plane->pln_x = land->lnd_x;
890 plane->pln_y = land->lnd_y;
891 plane->pln_land = land->lnd_uid;
892 putplane(plane->pln_uid, plane);
897 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
900 struct plchrstr *pcp;
901 struct emp_qelem *qp;
902 struct emp_qelem *next;
908 getsect(x, y, §);
909 mines_there = sect.sct_mines;
911 if (mines_there == 0)
914 if (sect.sct_type != SCT_WATER)
917 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
920 ip = (struct plist *)qp;
923 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
926 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
928 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
934 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
935 writemap(player->cnum);
936 sect.sct_mines = mines_there;
941 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
943 struct plchrstr *pcp = plchr + pp->pln_type;
944 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
945 (pp->pln_tech - pcp->pl_tech / 2);
946 int acc = pln_acc(pp);
949 if (type == EF_SHIP) {
950 if (pcp->pl_flags & P_A)
952 if (!(pcp->pl_flags & P_T))
955 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
956 (1.0 - acc / 100.0)) - hardtarget;
958 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
960 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
966 /* return 0 if there was a nuclear detonation */
969 pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
973 struct plchrstr *pcp = plchr + pp->pln_type;
981 if (getnuke(nuk_on_plane(pp), &nuke)) {
982 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
983 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
984 *nukedamp = detonate(&nuke, x, y,
985 pp->pln_flags & PLN_AIRBURST);
991 if (!load) /* e.g. ab, blowing up on launch pad */
998 if (pcp->pl_flags & P_M) {
999 if (pcp->pl_flags & P_MAR)
1001 } else if (pcp->pl_flags & P_T)
1006 effective = !pinbomber;
1007 aim = 30 + (pinbomber ? aim : 100 - aim);
1009 effective = pinbomber;
1015 hitroll = roll(100);
1016 if (hitroll >= 90) {
1019 mpr(pp->pln_own, "BLAM");
1020 } else if (hitroll < aim) {
1023 mpr(pp->pln_own, "Blam");
1027 mpr(pp->pln_own, "blam");
1030 mpr(pp->pln_own, "-");
1033 mpr(pp->pln_own, "\n");
1040 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1043 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1044 return (int)(100 - 100 * misschance * misschance);
1048 pln_mobcost(int dist, struct plnstr *pp, char mission)
1052 cost = 20.0 / (pp->pln_effic / 100.0);
1053 if (mission == 'e' || mission == 0)
1054 cost /= 2; /* escort or intercept */
1056 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1060 pln_is_in_orbit(struct plnstr *pp)
1062 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1063 && (pp->pln_flags & PLN_LAUNCHED);
1067 * Set PP's tech to TLEV along with everything else that depends on it.
1070 pln_set_tech(struct plnstr *pp, int tlev)
1072 struct plchrstr *pcp = plchr + pp->pln_type;
1073 int limited_range = pp->pln_range < pln_range_max(pp);
1076 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1077 tlev = pcp->pl_tech;
1078 pp->pln_tech = tlev;
1080 range_max = pln_range_max(pp);
1081 if (!limited_range || pp->pln_range > range_max)
1082 pp->pln_range = range_max;