2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * plnsub.c: Plane subroutine stuff
29 * Known contributors to this file:
32 * Steve McClure, 1998-2000
33 * Markus Armbruster, 2004-2010
49 #include "prototypes.h"
54 static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
57 * Get planes and escorts argument.
58 * Read planes into *NI_BOMB, and (optional) escorts into *NI_ESC.
59 * If INPUT_BOMB is not empty, use it, else prompt for more input.
61 * If we got a plane argument, initialize *NI_BOMB and *NI_ESC, and
63 * Else return -1 (*NI_BOMB and *NI_ESC may be modified).
66 get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc,
67 char *input_bomb, char *input_esc)
69 if (!snxtitem(ni_bomb, EF_PLANE, input_bomb, NULL))
71 if (!snxtitem(ni_esc, EF_PLANE, input_esc, "escort(s)? ")) {
74 pr("No escorts...\n");
80 * Get assembly point argument.
81 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
82 * If this yields a valid assembly point, read it into *AP_SECT and
84 * Else complain and return NULL.
85 * *AP_SECT and BUF[1024] may be modified in either case.
88 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
95 p = getstarg(input, "assembly point? ", buf);
98 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
101 /* over own or allied sector is fine */
102 if (relations_with(ap_sect->sct_own, player->cnum) == ALLIED)
105 /* over own or allied ship is fine */
106 snxtitem_xy(&ni, EF_SHIP, x, y);
107 while (nxtitem(&ni, &ship)) {
108 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
110 if (relations_with(ship.shp_own, player->cnum) == ALLIED)
114 pr("Assembly point not owned by you or an ally!\n");
119 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
131 nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
134 p = getstring("Carrier #? ", buf);
141 || !getship(cno, &ship)
143 && (relations_with(ship.shp_own, player->cnum)
148 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
149 pr("Ship #%d not in %s\n", cno,
150 xyas(target->sct_x, target->sct_y, player->cnum));
153 fl = carrier_planes(&ship, 0);
155 pr("Can't land on %s.\n", prship(&ship));
158 /* clear to land on ship#CNO */
159 pr("landing on carrier %d\n", cno);
167 /* try to land at sector */
168 if (relations_with(target->sct_own, player->cnum) != ALLIED) {
169 pr("Nowhere to land at sector %s!\n",
170 xyas(target->sct_x, target->sct_y, player->cnum));
173 if (target->sct_type == SCT_MOUNT) {
174 pr("Nowhere to land at sector %s!\n",
175 xyas(target->sct_x, target->sct_y, player->cnum));
178 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
181 /* clear to land at sector */
188 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
189 struct emp_qelem *esc_list, int cno)
191 struct emp_qelem *list, *qp;
195 if (cno < 0 || !getship(cno, &ship))
199 for (list = bomb_list;
201 list = list == bomb_list ? esc_list : NULL) {
202 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
203 plp = (struct plist *)qp;
204 if (plp->plane.pln_ship == ship.shp_uid)
206 if (!fit_plane_on_ship(&plp->plane, &ship))
214 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
216 struct emp_qelem *qp;
223 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
224 plp = (struct plist *)qp;
226 if (!could_be_on_ship(&plp->plane, &ship, 0, 0, 0, 0))
227 pr("\t%s cannot land on ship #%d! %s aborts!\n",
228 prplane(&plp->plane), cno, prplane(&plp->plane));
229 else if (!put_plane_on_ship(&plp->plane, &ship))
230 pr("\tNo room on ship #%d! %s aborts!\n",
231 cno, prplane(&plp->plane));
233 if (plp->plane.pln_own != ship.shp_own) {
234 wu(0, ship.shp_own, "%s %s lands on your %s\n",
235 cname(player->cnum), prplane(&plp->plane),
240 plp->plane.pln_x = tx;
241 plp->plane.pln_y = ty;
242 getsect(tx, ty, §);
243 if (plp->plane.pln_own != sect.sct_own) {
245 "%s %s lands at your sector %s\n",
247 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
249 plp->plane.pln_ship = cno;
255 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
258 struct emp_qelem *qp;
269 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
270 plp = (struct plist *)qp;
274 getsect(tx, ty, §);
276 if (sect.sct_type == SCT_WATER)
277 pr("Your %s sink like a rock!\n", ip->i_name);
279 pr("Your %s vanish without a trace.\n", ip->i_name);
282 if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
283 pr("You don't own %s! Cargo jettisoned...\n",
284 xyas(tx, ty, player->cnum));
287 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
288 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
289 xyas(tx, ty, player->cnum));
292 there = sect.sct_item[ip->i_uid];
296 there = ship.shp_item[ip->i_uid];
297 max = mchr[ship.shp_type].m_item[ip->i_uid];
301 pr("%d excess %s discarded\n", there - max, ip->i_name);
305 pr("%d %s landed safely", amt, ip->i_name);
307 sect.sct_item[ip->i_uid] = there;
308 if (sect.sct_own != player->cnum)
309 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
310 cname(player->cnum), amt, ip->i_name,
311 xyas(tx, ty, sect.sct_own));
312 pr(" at %s\n", xyas(tx, ty, player->cnum));
315 ship.shp_item[ip->i_uid] = there;
316 if (ship.shp_own != player->cnum)
317 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
318 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
319 pr(" on carrier #%d\n", ship.shp_uid);
320 putship(ship.shp_uid, &ship);
325 pln_mine(struct emp_qelem *list, coord tx, coord ty)
327 struct emp_qelem *qp;
333 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
334 plp = (struct plist *)qp;
339 getsect(tx, ty, §);
340 if (sect.sct_type != SCT_WATER) {
341 pr("Your seamines have no effect here.\n");
344 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
345 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
346 if (map_set(player->cnum, tx, ty, 'X', 0))
347 writemap(player->cnum);
353 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
354 * A plane type is capable unless
355 * - it lacks all of the P_B, P_T in WANTFLAGS, or
356 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
357 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
358 * - it lacks any of the other capabilities in WANTFLAGS, or
359 * - it has any of the capabilities in NOWANTFLAGS.
362 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
364 int flags = plchr[(int)pp->pln_type].pl_flags;
366 if (wantflags & (P_B | P_T)) {
367 if ((flags & wantflags & (P_B | P_T)) == 0)
369 wantflags &= ~(P_B | P_T);
372 if (wantflags & (P_F | P_ESC)) {
373 if ((flags & wantflags & (P_F | P_ESC)) == 0)
375 wantflags &= ~(P_F | P_ESC);
378 if (wantflags & (P_E | P_L | P_K)) {
379 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
381 wantflags &= ~(P_E | P_L | P_K);
384 if ((flags & wantflags) != wantflags)
387 if (flags & nowantflags)
394 * Return union of capabilities of planes in LIST.
397 pln_caps(struct emp_qelem *list)
399 struct emp_qelem *qp;
404 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
405 plp = (struct plist *)qp;
406 fl |= plp->pcp->pl_flags;
413 * Find plane types that can operate from carrier SP.
414 * If MSL find missile types, else non-missile types.
415 * Return a combination of P_L, P_K, P_E.
416 * It's zero if SP can't support air operations due to its type or
417 * state (low efficiency).
420 carrier_planes(struct shpstr *sp, int msl)
422 struct mchrstr *mcp = mchr + sp->shp_type;
425 if (sp->shp_effic < SHP_AIROPS_EFF)
429 if (mcp->m_flags & M_FLY)
431 if ((mcp->m_flags & M_MSL) && msl)
433 if (mcp->m_nchoppers && !msl)
441 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
446 struct plchrstr *pcp = plchr + pp->pln_type;
448 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
451 if (pp->pln_ship >= 0) {
452 /* ship: needs to be own or allied, efficient */
453 if (!getship(pp->pln_ship, &ship)) {
457 if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
459 pr("(note) An ally does not own the ship %s is on\n",
463 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
466 } else if (pp->pln_land >= 0) {
467 /* land: needs to be own or allied, efficient, not embarked */
468 if (!getland(pp->pln_land, &land)) {
472 if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
474 pr("(note) An ally does not own the unit %s is on\n",
478 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
480 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
484 /* sector: needs to be own or allied, efficient airfield */
485 if (!getsect(pp->pln_x, pp->pln_y, §)) {
490 if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
492 pr("(note) An ally does not own the sector %s is in\n",
496 /* need airfield unless VTOL */
497 if ((pcp->pl_flags & P_V) == 0) {
498 if (sect.sct_type != SCT_AIRPT) {
500 pr("%s not at airport\n", prplane(pp));
503 if (sect.sct_effic < 40) {
505 pr("%s is not 40%% efficient, %s can't take off from there.\n",
506 xyas(sect.sct_x, sect.sct_y, player->cnum),
510 if (!oneway && sect.sct_effic < 60) {
512 pr("%s is not 60%% efficient, %s can't land there.\n",
513 xyas(sect.sct_x, sect.sct_y, player->cnum),
524 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
525 int ap_to_target, int rangemult, int wantflags, int nowantflags)
529 struct plchrstr *pcp;
533 while (nxtitem(ni, &plane)) {
535 * It would be nice to let deities fly foreign planes, but
536 * much of the code assumes that only the plane's owner can
539 if (!plane.pln_own || plane.pln_own != player->cnum)
541 if (plane.pln_mobil <= 0)
543 if (plane.pln_effic < 40) {
544 pr("%s not efficient enough (must be 40%%)\n",
548 if (!pln_capable(&plane, wantflags, nowantflags))
551 if (ontradingblock(EF_PLANE, &plane)) {
552 pr("plane #%d inelligible - it's for sale.\n",
558 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
560 pr("%s too far from assembly point\n", prplane(&plane));
563 range += ap_to_target;
565 pcp = &plchr[(int)plane.pln_type];
566 if (plane.pln_range < range) {
567 pr("%s out of range (%d:%d)\n",
568 prplane(&plane), plane.pln_range, range);
571 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
573 pr("%s standing by\n", prplane(&plane));
574 plane.pln_mission = 0;
575 putplane(plane.pln_uid, &plane);
576 plp = malloc(sizeof(struct plist));
580 emp_insque(&plp->queue, list);
585 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
587 struct emp_qelem *qp;
588 struct emp_qelem *next;
592 for (qp = list->q_forw; qp != list; qp = next) {
594 plp = (struct plist *)qp;
596 getplane(pp->pln_uid, pp);
597 if ((pp->pln_flags & PLN_LAUNCHED)
598 || pln_equip(plp, ip, mission) < 0) {
603 pp->pln_flags |= PLN_LAUNCHED;
604 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
605 putplane(pp->pln_uid, pp);
606 pr("%s equipped\n", prplane(pp));
611 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
613 struct plchrstr *pcp;
626 if (pp->pln_ship >= 0) {
627 getship(pp->pln_ship, &ship);
628 item = ship.shp_item;
630 } else if (pp->pln_land >= 0) {
631 getland(pp->pln_land, &land);
632 item = land.lnd_item;
635 getsect(pp->pln_x, pp->pln_y, §);
636 item = sect.sct_item;
637 own = sect.sct_oldown;
639 if (pcp->pl_fuel > item[I_PETROL]) {
640 pr("%s not enough petrol there!\n", prplane(pp));
643 item[I_PETROL] -= pcp->pl_fuel;
647 case 's': /* strategic bomb */
648 case 'p': /* pinpoint bomb */
651 case 't': /* transport */
652 if (!(pcp->pl_flags & P_C) || !ip)
658 if ((pcp->pl_flags & P_MINE) == 0)
664 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
667 if (pcp->pl_flags & P_V)
670 case 'a': /* paradrop */
671 if (!(pcp->pl_flags & P_P))
674 if (pcp->pl_flags & P_V)
677 case 'r': /* reconnaissance */
678 case 'e': /* escort */
681 case 'i': /* missile interception */
682 if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
683 || !(pcp->pl_flags & (P_N | P_O))))
693 if (itype != I_NONE) {
694 needed = load / ichr[itype].i_lbs;
696 pr("%s can't contribute to mission\n", prplane(pp));
699 if (nuk_on_plane(pp) >= 0) {
700 if (mission == 's' || mission == 't')
703 pr("%s can't fly this mission"
704 " while it is carrying a nuclear weapon",
709 if (itype == I_CIVIL && pp->pln_own != own) {
710 pr("You don't control those civilians!\n");
714 /* Supply is broken somewhere, so don't use it for now */
715 if (itype == I_SHELL && item[itype] < needed)
716 item[itype] += supply_commod(plp->plane.pln_own,
721 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
724 abandon_needed = !!would_abandon(§, itype, needed, NULL);
725 if (item[itype] < needed + abandon_needed) {
726 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
729 item[itype] -= needed;
733 if (pp->pln_ship >= 0) {
734 if (pp->pln_own != ship.shp_own) {
736 "%s %s prepares for takeoff from ship %s\n",
737 cname(pp->pln_own), prplane(pp), prship(&ship));
739 putship(ship.shp_uid, &ship);
740 } else if (pp->pln_land >= 0) {
741 if (pp->pln_own != land.lnd_own) {
743 "%s %s prepares for takeoff from unit %s\n",
744 cname(pp->pln_own), prplane(pp), prland(&land));
746 putland(land.lnd_uid, &land);
748 if (pp->pln_own != sect.sct_own) {
749 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
750 cname(pp->pln_own), prplane(pp),
751 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
759 pln_put(struct emp_qelem *list)
761 struct emp_qelem *qp, *next;
763 for (qp = list->q_forw; qp != list; qp = next) {
765 pln_put1((struct plist *)qp);
770 pln_put1(struct plist *plp)
778 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
779 && (plchr[pp->pln_type].pl_flags & P_M)
780 && pp->pln_effic >= PLANE_MINEFF))
781 pp->pln_effic = 0; /* bug: missile launched but not used up */
783 if (!(pp->pln_flags & PLN_LAUNCHED))
784 ; /* never took off */
785 else if (pp->pln_effic < PLANE_MINEFF) {
787 } else if (pp->pln_ship >= 0) {
788 /* It is landing on a carrier */
789 getship(pp->pln_ship, &ship);
790 /* We should do more, like make sure it's really
791 a carrier, etc. but for now just make sure it's
793 if (ship.shp_effic < SHIP_MINEFF) {
795 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
796 "splashes into the sea.\n",
797 pp->pln_ship, pp->pln_uid);
801 /* Presume we are landing back in a sector. */
802 getsect(pp->pln_x, pp->pln_y, §);
803 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
805 "Nowhere to land at %s, plane #%d crashes and burns...\n",
806 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
810 pp->pln_flags &= ~PLN_LAUNCHED;
811 putplane(pp->pln_uid, pp);
812 emp_remque(&plp->queue);
817 * Can PP be loaded on a ship of SP's type?
818 * Assume that it already carries N planes, of which NCH are choppers,
819 * NXL xlight, NMSL light missiles, and the rest are light fixed-wing
823 could_be_on_ship(struct plnstr *pp, struct shpstr *sp,
824 int n, int nch, int nxl, int nmsl)
826 struct plchrstr *pcp = &plchr[pp->pln_type];
827 struct mchrstr *mcp = &mchr[sp->shp_type];
830 if (pcp->pl_flags & P_K)
832 else if (pcp->pl_flags & P_E)
834 else if (!(pcp->pl_flags & P_L))
836 else if (pcp->pl_flags & P_M)
839 nfw = n - nch - nxl - nmsl;
841 if (nch > mcp->m_nchoppers) /* overflow into fixed-wing slots */
842 nfw += nch - mcp->m_nchoppers;
843 if (nxl > mcp->m_nxlight) /* overflow into missile slots */
844 nmsl += nxl - mcp->m_nxlight;
845 if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
846 return 0; /* missile slots wanted */
847 if (nfw && !(mcp->m_flags & M_FLY))
848 return 0; /* fixed-wing slots wanted */
849 return nfw + nmsl <= mcp->m_nplanes;
853 * Fit a plane of PP's type on ship SP.
854 * Updating the plane accordingly is the caller's job.
855 * Return whether it fits.
858 fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
860 int n, nch, nxl, nmsl;
862 n = shp_nplane(sp, &nch, &nxl, &nmsl);
863 return could_be_on_ship(pp, sp, n, nch, nxl, nmsl);
867 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
869 if (plane->pln_ship == ship->shp_uid)
870 return 1; /* Already on ship */
872 if (!fit_plane_on_ship(plane, ship))
875 plane->pln_x = ship->shp_x;
876 plane->pln_y = ship->shp_y;
877 plane->pln_ship = ship->shp_uid;
878 putplane(plane->pln_uid, plane);
883 * Fit a plane of PP's type on land unit LP.
884 * Updating the plane accordingly is the caller's job.
885 * Return whether it fits.
888 fit_plane_on_land(struct plnstr *pp, struct lndstr *lp)
890 struct plchrstr *pcp = plchr + pp->pln_type;
891 struct lchrstr *lcp = lchr + lp->lnd_type;
893 return (pcp->pl_flags & P_E) && lnd_nxlight(lp) < lcp->l_nxlight;
897 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
899 if (plane->pln_land == land->lnd_uid)
900 return 1; /* Already on unit */
902 if (!fit_plane_on_land(plane, land))
905 plane->pln_x = land->lnd_x;
906 plane->pln_y = land->lnd_y;
907 plane->pln_land = land->lnd_uid;
908 putplane(plane->pln_uid, plane);
913 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
916 struct plchrstr *pcp;
917 struct emp_qelem *qp;
918 struct emp_qelem *next;
924 getsect(x, y, §);
925 mines_there = sect.sct_mines;
927 if (mines_there == 0)
930 if (sect.sct_type != SCT_WATER)
933 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
936 ip = (struct plist *)qp;
939 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
942 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
944 xyas(sect.sct_x, sect.sct_y, player->cnum));
950 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
951 writemap(player->cnum);
952 sect.sct_mines = mines_there;
957 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
959 struct plchrstr *pcp = plchr + pp->pln_type;
960 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
961 (pp->pln_tech - pcp->pl_tech / 2);
962 int acc = pln_acc(pp);
965 if (type == EF_SHIP) {
966 if (pcp->pl_flags & P_A)
968 if (!(pcp->pl_flags & P_T))
971 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
972 (1.0 - acc / 100.0)) - hardtarget;
974 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
976 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
983 pln_damage(struct plnstr *pp, char type, int noisy)
985 struct plchrstr *pcp = plchr + pp->pln_type;
986 int load, i, hitroll, aim, len;
992 if (CANT_HAPPEN(nuk_on_plane(pp) >= 0))
996 if (!load) /* e.g. ab, blowing up on launch pad */
1003 if (pcp->pl_flags & P_M) {
1004 if (pcp->pl_flags & P_MAR)
1006 } else if (pcp->pl_flags & P_T)
1011 effective = !pinbomber;
1012 aim = 30 + (pinbomber ? aim : 100 - aim);
1014 effective = pinbomber;
1021 hitroll = roll(100);
1022 if (hitroll >= 90) {
1025 len += sprintf(buf + len, "BLAM");
1026 } else if (hitroll < aim) {
1029 len += sprintf(buf + len, "Blam");
1033 len += sprintf(buf + len, "blam");
1037 mpr(pp->pln_own, "%s\n", buf);
1041 len += sprintf(buf + len, "-");
1045 mpr(pp->pln_own, "%s\n", buf);
1052 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1055 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1056 return (int)(100 - 100 * misschance * misschance);
1060 pln_mobcost(int dist, struct plnstr *pp, char mission)
1064 cost = 20.0 / (pp->pln_effic / 100.0);
1065 if (mission == 'e' || mission == 0)
1066 cost /= 2; /* escort or intercept */
1068 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1072 pln_is_in_orbit(struct plnstr *pp)
1074 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1075 && (pp->pln_flags & PLN_LAUNCHED);
1079 * Set PP's tech to TLEV along with everything else that depends on it.
1082 pln_set_tech(struct plnstr *pp, int tlev)
1084 struct plchrstr *pcp = plchr + pp->pln_type;
1085 int limited_range = pp->pln_range < pln_range_max(pp);
1088 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1089 tlev = pcp->pl_tech;
1090 pp->pln_tech = tlev;
1092 range_max = pln_range_max(pp);
1093 if (!limited_range || pp->pln_range > range_max)
1094 pp->pln_range = range_max;