2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, 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 fit_plane_on_ship(struct plnstr *, struct shpstr *);
60 * Get planes and escorts argument.
61 * Read planes into *NI_BOMB, and (optional) escorts into *NI_ESC.
62 * If INPUT_BOMB is not empty, use it, else prompt for more input.
64 * If we got a plane argument, initialize *NI_BOMB and *NI_ESC, and
66 * Else return -1 (*NI_BOMB and *NI_ESC may be modified).
69 get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc,
70 char *input_bomb, char *input_esc)
72 if (!snxtitem(ni_bomb, EF_PLANE, input_bomb, NULL))
74 if (!snxtitem(ni_esc, EF_PLANE, input_esc, "escort(s)? ")) {
77 pr("No escorts...\n");
83 * Get assembly point argument.
84 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
85 * If this yields a valid assembly point, read it into *AP_SECT and
87 * Else complain and return NULL.
88 * *AP_SECT and BUF[1024] may be modified in either case.
91 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
98 p = getstarg(input, "assembly point? ", buf);
101 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
104 /* over own or allied sector is fine */
105 if (relations_with(ap_sect->sct_own, player->cnum) == ALLIED)
108 /* over own or allied ship is fine */
109 snxtitem_xy(&ni, EF_SHIP, x, y);
110 while (nxtitem(&ni, &ship)) {
111 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
113 if (relations_with(ship.shp_own, player->cnum) == ALLIED)
117 pr("Assembly point not owned by you or an ally!\n");
122 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
134 nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
137 p = getstring("Carrier #? ", buf);
144 || !getship(cno, &ship)
146 && (relations_with(ship.shp_own, player->cnum)
151 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
152 pr("Ship #%d not in %s\n", cno,
153 xyas(target->sct_x, target->sct_y, player->cnum));
156 fl = carrier_planes(&ship, 0);
158 pr("Can't land on %s.\n", prship(&ship));
161 /* clear to land on ship#CNO */
162 pr("landing on carrier %d\n", cno);
170 /* try to land at sector */
171 if (relations_with(target->sct_own, player->cnum) != ALLIED) {
172 pr("Nowhere to land at sector %s!\n",
173 xyas(target->sct_x, target->sct_y, player->cnum));
176 if (target->sct_type == SCT_MOUNT) {
177 pr("Nowhere to land at sector %s!\n",
178 xyas(target->sct_x, target->sct_y, player->cnum));
181 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
184 /* clear to land at sector */
191 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
192 struct emp_qelem *esc_list, int cno)
194 struct emp_qelem *list, *qp;
198 if (cno < 0 || !getship(cno, &ship))
202 for (list = bomb_list;
204 list = list == bomb_list ? esc_list : NULL) {
205 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
206 plp = (struct plist *)qp;
207 if (plp->plane.pln_ship == ship.shp_uid)
209 if (!fit_plane_on_ship(&plp->plane, &ship))
217 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
219 struct emp_qelem *qp;
226 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
227 plp = (struct plist *)qp;
229 if (!could_be_on_ship(&plp->plane, &ship, 0, 0, 0, 0))
230 pr("\t%s cannot land on ship #%d! %s aborts!\n",
231 prplane(&plp->plane), cno, prplane(&plp->plane));
232 else if (!put_plane_on_ship(&plp->plane, &ship))
233 pr("\tNo room on ship #%d! %s aborts!\n",
234 cno, prplane(&plp->plane));
236 if (plp->plane.pln_own != ship.shp_own) {
237 wu(0, ship.shp_own, "%s %s lands on your %s\n",
238 cname(player->cnum), prplane(&plp->plane),
243 plp->plane.pln_x = tx;
244 plp->plane.pln_y = ty;
245 getsect(tx, ty, §);
246 if (plp->plane.pln_own != sect.sct_own) {
248 "%s %s lands at your sector %s\n",
250 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
252 plp->plane.pln_ship = cno;
258 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
261 struct emp_qelem *qp;
272 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
273 plp = (struct plist *)qp;
277 getsect(tx, ty, §);
279 if (sect.sct_type == SCT_WATER)
280 pr("Your %s sink like a rock!\n", ip->i_name);
282 pr("Your %s vanish without a trace.\n", ip->i_name);
285 if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
286 pr("You don't own %s! Cargo jettisoned...\n",
287 xyas(tx, ty, player->cnum));
290 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
291 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
292 xyas(tx, ty, player->cnum));
295 there = sect.sct_item[ip->i_uid];
299 there = ship.shp_item[ip->i_uid];
300 max = mchr[ship.shp_type].m_item[ip->i_uid];
304 pr("%d excess %s discarded\n", there - max, ip->i_name);
308 pr("%d %s landed safely", amt, ip->i_name);
310 sect.sct_item[ip->i_uid] = there;
311 if (sect.sct_own != player->cnum)
312 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
313 cname(player->cnum), amt, ip->i_name,
314 xyas(tx, ty, sect.sct_own));
315 pr(" at %s\n", xyas(tx, ty, player->cnum));
318 ship.shp_item[ip->i_uid] = there;
319 if (ship.shp_own != player->cnum)
320 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
321 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
322 pr(" on carrier #%d\n", ship.shp_uid);
323 putship(ship.shp_uid, &ship);
328 pln_mine(struct emp_qelem *list, coord tx, coord ty)
330 struct emp_qelem *qp;
336 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
337 plp = (struct plist *)qp;
342 getsect(tx, ty, §);
343 if (sect.sct_type != SCT_WATER) {
344 pr("Your seamines have no effect here.\n");
347 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
348 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
349 if (map_set(player->cnum, tx, ty, 'X', 0))
350 writemap(player->cnum);
356 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
357 * A plane type is capable unless
358 * - it lacks all of the P_B, P_T in WANTFLAGS, or
359 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
360 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
361 * - it lacks any of the other capabilities in WANTFLAGS, or
362 * - it has any of the capabilities in NOWANTFLAGS.
365 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
367 int flags = plchr[(int)pp->pln_type].pl_flags;
369 if (wantflags & (P_B | P_T)) {
370 if ((flags & wantflags & (P_B | P_T)) == 0)
372 wantflags &= ~(P_B | P_T);
375 if (wantflags & (P_F | P_ESC)) {
376 if ((flags & wantflags & (P_F | P_ESC)) == 0)
378 wantflags &= ~(P_F | P_ESC);
381 if (wantflags & (P_E | P_L | P_K)) {
382 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
384 wantflags &= ~(P_E | P_L | P_K);
387 if ((flags & wantflags) != wantflags)
390 if (flags & nowantflags)
397 * Return union of capabilities of planes in LIST.
400 pln_caps(struct emp_qelem *list)
402 struct emp_qelem *qp;
407 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
408 plp = (struct plist *)qp;
409 fl |= plp->pcp->pl_flags;
416 * Find plane types that can operate from carrier SP.
417 * If MSL find missile types, else non-missile types.
418 * Return a combination of P_L, P_K, P_E.
419 * It's zero if SP can't support air operations due to its type or
420 * state (low efficiency).
423 carrier_planes(struct shpstr *sp, int msl)
425 struct mchrstr *mcp = mchr + sp->shp_type;
428 if (sp->shp_effic < SHP_AIROPS_EFF)
432 if (mcp->m_flags & M_FLY)
434 if ((mcp->m_flags & M_MSL) && msl)
436 if (mcp->m_nchoppers && !msl)
444 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
449 struct plchrstr *pcp = plchr + pp->pln_type;
451 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
454 if (pp->pln_ship >= 0) {
455 /* ship: needs to be own or allied, efficient */
456 if (!getship(pp->pln_ship, &ship)) {
460 if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
462 pr("(note) An ally does not own the ship %s is on\n",
466 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
469 } else if (pp->pln_land >= 0) {
470 /* land: needs to be own or allied, efficient, not embarked */
471 if (!getland(pp->pln_land, &land)) {
475 if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
477 pr("(note) An ally does not own the unit %s is on\n",
481 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
483 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
487 /* sector: needs to be own or allied, efficient airfield */
488 if (!getsect(pp->pln_x, pp->pln_y, §)) {
493 if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
495 pr("(note) An ally does not own the sector %s is in\n",
499 /* need airfield unless VTOL */
500 if ((pcp->pl_flags & P_V) == 0) {
501 if (sect.sct_type != SCT_AIRPT) {
503 pr("%s not at airport\n", prplane(pp));
506 if (sect.sct_effic < 40) {
508 pr("%s is not 40%% efficient, %s can't take off from there.\n",
509 xyas(sect.sct_x, sect.sct_y, player->cnum),
513 if (!oneway && sect.sct_effic < 60) {
515 pr("%s is not 60%% efficient, %s can't land there.\n",
516 xyas(sect.sct_x, sect.sct_y, player->cnum),
527 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
528 int ap_to_target, int rangemult, int wantflags, int nowantflags)
532 struct plchrstr *pcp;
536 while (nxtitem(ni, &plane)) {
538 * It would be nice to let deities fly foreign planes, but
539 * much of the code assumes that only the plane's owner can
542 if (plane.pln_own != player->cnum)
544 if (plane.pln_mobil <= 0)
546 if (plane.pln_effic < 40) {
547 pr("%s not efficient enough (must be 40%%)\n",
551 if (!pln_capable(&plane, wantflags, nowantflags))
554 if (ontradingblock(EF_PLANE, &plane)) {
555 pr("plane #%d inelligible - it's for sale.\n",
561 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
563 pr("%s too far from assembly point\n", prplane(&plane));
566 range += ap_to_target;
568 pcp = &plchr[(int)plane.pln_type];
569 if (plane.pln_range < range) {
570 pr("%s out of range (%d:%d)\n",
571 prplane(&plane), plane.pln_range, range);
574 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
576 pr("%s standing by\n", prplane(&plane));
577 plane.pln_mission = 0;
578 putplane(plane.pln_uid, &plane);
579 plp = malloc(sizeof(struct plist));
583 emp_insque(&plp->queue, list);
588 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
590 struct emp_qelem *qp;
591 struct emp_qelem *next;
595 for (qp = list->q_forw; qp != list; qp = next) {
597 plp = (struct plist *)qp;
599 getplane(pp->pln_uid, pp);
600 if ((pp->pln_flags & PLN_LAUNCHED)
601 || pln_equip(plp, ip, mission) < 0) {
606 pp->pln_flags |= PLN_LAUNCHED;
607 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
608 putplane(pp->pln_uid, pp);
609 pr("%s equipped\n", prplane(pp));
614 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
616 struct plchrstr *pcp;
629 if (pp->pln_ship >= 0) {
630 getship(pp->pln_ship, &ship);
631 item = ship.shp_item;
633 } else if (pp->pln_land >= 0) {
634 getland(pp->pln_land, &land);
635 item = land.lnd_item;
638 getsect(pp->pln_x, pp->pln_y, §);
639 item = sect.sct_item;
640 own = sect.sct_oldown;
642 if (pcp->pl_fuel > item[I_PETROL]) {
643 pr("%s not enough petrol there!\n", prplane(pp));
646 item[I_PETROL] -= pcp->pl_fuel;
650 case 's': /* strategic bomb */
651 case 'p': /* pinpoint bomb */
654 case 't': /* transport */
655 if (!(pcp->pl_flags & P_C) || !ip)
661 if ((pcp->pl_flags & P_MINE) == 0)
667 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
670 if (pcp->pl_flags & P_V)
673 case 'a': /* paradrop */
674 if (!(pcp->pl_flags & P_P))
677 if (pcp->pl_flags & P_V)
680 case 'r': /* reconnaissance */
681 case 'e': /* escort */
684 case 'i': /* missile interception */
685 if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
686 || !(pcp->pl_flags & (P_N | P_O))))
696 if (itype != I_NONE) {
697 needed = load / ichr[itype].i_lbs;
699 pr("%s can't contribute to mission\n", prplane(pp));
702 if (nuk_on_plane(pp) >= 0) {
703 if (mission == 's' || mission == 't')
706 pr("%s can't fly this mission"
707 " while it is carrying a nuclear weapon",
712 if (itype == I_CIVIL && pp->pln_own != own) {
713 pr("You don't control those civilians!\n");
717 /* Supply is broken somewhere, so don't use it for now */
718 if (itype == I_SHELL && item[itype] < needed)
719 item[itype] += supply_commod(plp->plane.pln_own,
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;