2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2012, 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-2012
50 #include "prototypes.h"
55 static int ship_can_carry(struct shpstr *, int, int, int, int);
56 static int inc_shp_nplane(struct plnstr *, int *, int *, int *);
59 * Get planes and escorts argument.
60 * Read planes into *NI_BOMB, and (optional) escorts into *NI_ESC.
61 * If INPUT_BOMB is not empty, use it, else prompt for more input.
63 * If we got a plane argument, initialize *NI_BOMB and *NI_ESC, and
65 * Else return -1 (*NI_BOMB and *NI_ESC may be modified).
68 get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc,
69 char *input_bomb, char *input_esc)
71 if (!snxtitem(ni_bomb, EF_PLANE, input_bomb, NULL))
73 if (!snxtitem(ni_esc, EF_PLANE, input_esc, "escort(s)? ")) {
76 pr("No escorts...\n");
82 * Get assembly point argument.
83 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
84 * If this yields a valid assembly point, read it into *AP_SECT and
86 * Else complain and return NULL.
87 * *AP_SECT and BUF[1024] may be modified in either case.
90 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
97 p = getstarg(input, "assembly point? ", buf);
100 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
103 /* over own or allied sector is fine */
104 if (relations_with(ap_sect->sct_own, player->cnum) == ALLIED)
107 /* over own or allied ship is fine */
108 snxtitem_xy(&ni, EF_SHIP, x, y);
109 while (nxtitem(&ni, &ship)) {
110 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
112 if (relations_with(ship.shp_own, player->cnum) == ALLIED)
116 pr("Assembly point not owned by you or an ally!\n");
121 * Find out whether planes can fly one-way to X,Y.
122 * Offer the player any carriers there. If he chooses one, read it
123 * into TARGET->ship. Else read the target sector into TARGET->sect.
124 * If planes can land there, set required plane flags in *FLAGSP, and
125 * return 0. Else return -1.
128 pln_where_to_land(coord x, coord y,
129 union empobj_storage *target, int *flagsp)
138 nships = carriersatxy(x, y, player->cnum);
141 p = getstring("Carrier #? ", buf);
147 if (!getship(cno, &target->ship)
149 && (relations_with(target->ship.shp_own, player->cnum)
154 if (target->ship.shp_x != x || target->ship.shp_y != y) {
155 pr("Ship #%d not in %s\n", cno, xyas(x, y, player->cnum));
158 fl = carrier_planes(&target->ship, 0);
160 pr("Can't land on %s.\n", prship(&target->ship));
163 /* clear to land on ship#CNO */
164 pr("landing on carrier %d\n", cno);
170 /* try to land at sector */
171 getsect(x, y, &target->sect);
172 if (relations_with(target->sect.sct_own, player->cnum) != ALLIED) {
173 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
176 if (target->sect.sct_type == SCT_MOUNT) {
177 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
180 /* clear to land at sector */
181 if (target->sect.sct_type != SCT_AIRPT || target->sect.sct_effic < 60)
187 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
188 struct emp_qelem *esc_list, int cno)
190 int n, nch, nxl, nmsl;
191 struct emp_qelem *list, *qp;
195 if (cno < 0 || !getship(cno, &ship))
197 n = shp_nplane(&ship, &nch, &nxl, &nmsl);
200 for (list = bomb_list;
202 list = list == bomb_list ? esc_list : NULL) {
203 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
204 plp = (struct plist *)qp;
205 if (plp->plane.pln_ship == ship.shp_uid)
208 if (!inc_shp_nplane(&plp->plane, &nch, &nxl, &nmsl))
212 return ship_can_carry(&ship, n, nch, nxl, nmsl);
216 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
218 struct emp_qelem *qp;
225 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
226 plp = (struct plist *)qp;
228 if (!could_be_on_ship(&plp->plane, &ship))
229 pr("\t%s cannot land on ship #%d! %s aborts!\n",
230 prplane(&plp->plane), cno, prplane(&plp->plane));
231 else if (!put_plane_on_ship(&plp->plane, &ship))
232 pr("\tNo room on ship #%d! %s aborts!\n",
233 cno, prplane(&plp->plane));
235 if (plp->plane.pln_own != ship.shp_own) {
236 wu(0, ship.shp_own, "%s %s lands on your %s\n",
237 cname(player->cnum), prplane(&plp->plane),
242 plp->plane.pln_x = tx;
243 plp->plane.pln_y = ty;
244 getsect(tx, ty, §);
245 if (plp->plane.pln_own != sect.sct_own) {
247 "%s %s lands at your sector %s\n",
249 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
251 plp->plane.pln_ship = cno;
257 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
260 struct emp_qelem *qp;
271 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
272 plp = (struct plist *)qp;
276 getsect(tx, ty, §);
278 if (sect.sct_type == SCT_WATER)
279 pr("Your %s sink like a rock!\n", ip->i_name);
281 pr("Your %s vanish without a trace.\n", ip->i_name);
284 if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
285 pr("You don't own %s! Cargo jettisoned...\n",
286 xyas(tx, ty, player->cnum));
289 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
290 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
291 xyas(tx, ty, player->cnum));
294 there = sect.sct_item[ip->i_uid];
298 there = ship.shp_item[ip->i_uid];
299 max = mchr[ship.shp_type].m_item[ip->i_uid];
303 pr("%d excess %s discarded\n", there - max, ip->i_name);
307 pr("%d %s landed safely", amt, ip->i_name);
309 sect.sct_item[ip->i_uid] = there;
310 if (sect.sct_own != player->cnum)
311 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
312 cname(player->cnum), amt, ip->i_name,
313 xyas(tx, ty, sect.sct_own));
314 pr(" at %s\n", xyas(tx, ty, player->cnum));
317 ship.shp_item[ip->i_uid] = there;
318 if (ship.shp_own != player->cnum)
319 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
320 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
321 pr(" on carrier #%d\n", ship.shp_uid);
322 putship(ship.shp_uid, &ship);
327 pln_mine(struct emp_qelem *list, coord tx, coord ty)
329 struct emp_qelem *qp;
335 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
336 plp = (struct plist *)qp;
341 getsect(tx, ty, §);
342 if (sect.sct_type != SCT_WATER) {
343 pr("Your seamines have no effect here.\n");
346 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
347 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
348 if (map_set(player->cnum, tx, ty, 'X', 0))
349 writemap(player->cnum);
355 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
356 * A plane type is capable unless
357 * - it lacks all of the P_B, P_T in WANTFLAGS, or
358 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
359 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
360 * - it lacks any of the other capabilities in WANTFLAGS, or
361 * - it has any of the capabilities in NOWANTFLAGS.
364 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
366 int flags = plchr[(int)pp->pln_type].pl_flags;
368 if (wantflags & (P_B | P_T)) {
369 if ((flags & wantflags & (P_B | P_T)) == 0)
371 wantflags &= ~(P_B | P_T);
374 if (wantflags & (P_F | P_ESC)) {
375 if ((flags & wantflags & (P_F | P_ESC)) == 0)
377 wantflags &= ~(P_F | P_ESC);
380 if (wantflags & (P_E | P_L | P_K)) {
381 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
383 wantflags &= ~(P_E | P_L | P_K);
386 if ((flags & wantflags) != wantflags)
389 if (flags & nowantflags)
396 * Return union of capabilities of planes in LIST.
399 pln_caps(struct emp_qelem *list)
401 struct emp_qelem *qp;
406 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
407 plp = (struct plist *)qp;
408 fl |= plp->pcp->pl_flags;
415 * Find plane types that can operate from carrier SP.
416 * If MSL find missile types, else non-missile types.
417 * Return a combination of P_L, P_K, P_E.
418 * It's zero if SP can't support air operations due to its type or
419 * state (low efficiency).
422 carrier_planes(struct shpstr *sp, int msl)
424 struct mchrstr *mcp = mchr + sp->shp_type;
427 if (sp->shp_effic < SHP_AIROPS_EFF)
431 if (mcp->m_flags & M_FLY)
433 if ((mcp->m_flags & M_MSL) && msl)
435 if (mcp->m_nchoppers && !msl)
443 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
448 struct plchrstr *pcp = plchr + pp->pln_type;
450 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
453 if (pp->pln_ship >= 0) {
454 /* ship: needs to be own or allied, efficient */
455 if (!getship(pp->pln_ship, &ship)) {
459 if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
461 pr("(note) An ally does not own the ship %s is on\n",
465 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
468 } else if (pp->pln_land >= 0) {
469 /* land: needs to be own or allied, efficient, not embarked */
470 if (!getland(pp->pln_land, &land)) {
474 if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
476 pr("(note) An ally does not own the unit %s is on\n",
480 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
482 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
486 /* sector: needs to be own or allied, efficient airfield */
487 if (!getsect(pp->pln_x, pp->pln_y, §)) {
492 if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
494 pr("(note) An ally does not own the sector %s is in\n",
498 /* need airfield unless VTOL */
499 if ((pcp->pl_flags & P_V) == 0) {
500 if (sect.sct_type != SCT_AIRPT) {
502 pr("%s not at airport\n", prplane(pp));
505 if (sect.sct_effic < 40) {
507 pr("%s is not 40%% efficient, %s can't take off from there.\n",
508 xyas(sect.sct_x, sect.sct_y, player->cnum),
512 if (!oneway && sect.sct_effic < 60) {
514 pr("%s is not 60%% efficient, %s can't land there.\n",
515 xyas(sect.sct_x, sect.sct_y, player->cnum),
526 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
527 int ap_to_target, int rangemult, int wantflags, int nowantflags)
531 struct plchrstr *pcp;
535 while (nxtitem(ni, &plane)) {
537 * It would be nice to let deities fly foreign planes, but
538 * much of the code assumes that only the plane's owner can
541 if (!plane.pln_own || plane.pln_own != player->cnum)
543 if (plane.pln_mobil <= 0)
545 if (plane.pln_effic < 40) {
546 pr("%s not efficient enough (must be 40%%)\n",
550 if (!pln_capable(&plane, wantflags, nowantflags))
553 if (ontradingblock(EF_PLANE, &plane)) {
554 pr("plane #%d inelligible - it's for sale.\n",
560 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
562 pr("%s too far from assembly point\n", prplane(&plane));
565 range += ap_to_target;
567 pcp = &plchr[(int)plane.pln_type];
568 if (plane.pln_range < range) {
569 pr("%s out of range (%d:%d)\n",
570 prplane(&plane), plane.pln_range, range);
573 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
575 pr("%s standing by\n", prplane(&plane));
576 plane.pln_mission = 0;
577 putplane(plane.pln_uid, &plane);
578 plp = malloc(sizeof(struct plist));
582 emp_insque(&plp->queue, list);
587 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
589 struct emp_qelem *qp;
590 struct emp_qelem *next;
594 for (qp = list->q_forw; qp != list; qp = next) {
596 plp = (struct plist *)qp;
598 getplane(pp->pln_uid, pp);
599 if ((pp->pln_flags & PLN_LAUNCHED)
600 || pln_equip(plp, ip, mission) < 0) {
605 pp->pln_flags |= PLN_LAUNCHED;
606 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
607 putplane(pp->pln_uid, pp);
608 pr("%s equipped\n", prplane(pp));
613 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
615 struct plchrstr *pcp;
628 if (pp->pln_ship >= 0) {
629 getship(pp->pln_ship, &ship);
630 item = ship.shp_item;
632 } else if (pp->pln_land >= 0) {
633 getland(pp->pln_land, &land);
634 item = land.lnd_item;
637 getsect(pp->pln_x, pp->pln_y, §);
638 item = sect.sct_item;
639 own = sect.sct_oldown;
641 if (pcp->pl_fuel > item[I_PETROL]) {
642 pr("%s not enough petrol there!\n", prplane(pp));
645 item[I_PETROL] -= pcp->pl_fuel;
649 case 's': /* strategic bomb */
650 case 'p': /* pinpoint bomb */
653 case 't': /* transport */
654 if (!(pcp->pl_flags & P_C) || !ip)
660 if ((pcp->pl_flags & P_MINE) == 0)
666 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
669 if (pcp->pl_flags & P_V)
672 case 'a': /* paradrop */
673 if (!(pcp->pl_flags & P_P))
676 if (pcp->pl_flags & P_V)
679 case 'r': /* reconnaissance */
680 case 'e': /* escort */
683 case 'i': /* missile interception */
684 if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
685 || !(pcp->pl_flags & (P_N | P_O))))
695 if (itype != I_NONE) {
696 needed = load / ichr[itype].i_lbs;
698 pr("%s can't contribute to mission\n", prplane(pp));
701 if (nuk_on_plane(pp) >= 0) {
702 if (mission == 's' || mission == 't')
705 pr("%s can't fly this mission"
706 " while it is carrying a nuclear weapon",
711 if (itype == I_CIVIL && pp->pln_own != own) {
712 pr("You don't control those civilians!\n");
716 /* Supply is broken somewhere, so don't use it for now */
717 if (itype == I_SHELL && item[itype] < needed)
718 item[itype] += supply_commod(plp->plane.pln_own,
723 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
726 abandon_needed = !!would_abandon(§, itype, needed, NULL);
727 if (item[itype] < needed + abandon_needed) {
728 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
731 item[itype] -= needed;
735 if (pp->pln_ship >= 0) {
736 if (pp->pln_own != ship.shp_own) {
738 "%s %s prepares for takeoff from ship %s\n",
739 cname(pp->pln_own), prplane(pp), prship(&ship));
741 putship(ship.shp_uid, &ship);
742 } else if (pp->pln_land >= 0) {
743 if (pp->pln_own != land.lnd_own) {
745 "%s %s prepares for takeoff from unit %s\n",
746 cname(pp->pln_own), prplane(pp), prland(&land));
748 putland(land.lnd_uid, &land);
750 if (pp->pln_own != sect.sct_own) {
751 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
752 cname(pp->pln_own), prplane(pp),
753 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
761 pln_put(struct emp_qelem *list)
763 struct emp_qelem *qp, *next;
765 for (qp = list->q_forw; qp != list; qp = next) {
767 pln_put1((struct plist *)qp);
772 pln_put1(struct plist *plp)
780 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
781 && (plchr[pp->pln_type].pl_flags & P_M)
782 && pp->pln_effic >= PLANE_MINEFF))
783 pp->pln_effic = 0; /* bug: missile launched but not used up */
785 if (!(pp->pln_flags & PLN_LAUNCHED))
786 ; /* never took off */
787 else if (pp->pln_effic < PLANE_MINEFF) {
789 } else if (pp->pln_ship >= 0) {
790 /* It is landing on a carrier */
791 getship(pp->pln_ship, &ship);
792 /* We should do more, like make sure it's really
793 a carrier, etc. but for now just make sure it's
795 if (ship.shp_effic < SHIP_MINEFF) {
797 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
798 "splashes into the sea.\n",
799 pp->pln_ship, pp->pln_uid);
803 /* Presume we are landing back in a sector. */
804 getsect(pp->pln_x, pp->pln_y, §);
805 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
807 "Nowhere to land at %s, plane #%d crashes and burns...\n",
808 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
812 pp->pln_flags &= ~PLN_LAUNCHED;
813 putplane(pp->pln_uid, pp);
814 emp_remque(&plp->queue);
819 * Can a carrier of SP's type carry this load of planes?
820 * The load consists of N planes, of which NCH are choppers, NXL
821 * xlight, NMSL light missiles, and the rest are light fixed-wing
825 ship_can_carry(struct shpstr *sp, int n, int nch, int nxl, int nmsl)
827 struct mchrstr *mcp = &mchr[sp->shp_type];
828 int nfw = n - nch - nxl - nmsl;
830 if (nch > mcp->m_nchoppers) /* overflow into fixed-wing slots */
831 nfw += nch - mcp->m_nchoppers;
832 if (nxl > mcp->m_nxlight) /* overflow into missile slots */
833 nmsl += nxl - mcp->m_nxlight;
834 if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
835 return 0; /* missile slots wanted */
836 if (nfw && !(mcp->m_flags & M_FLY))
837 return 0; /* fixed-wing slots wanted */
838 return nfw + nmsl <= mcp->m_nplanes;
842 * Increment carrier plane counters for PP.
843 * If it's a chopper, increment *NCH.
844 * Else, if it's x-light, increment *NXL.
845 * Else, if it's a light missile, increment *MSL.
846 * Return non-zero if it's a chopper, x-light or light.
849 inc_shp_nplane(struct plnstr *pp, int *nch, int *nxl, int *nmsl)
851 struct plchrstr *pcp = &plchr[pp->pln_type];
853 if (pcp->pl_flags & P_K)
855 else if (pcp->pl_flags & P_E)
857 else if (!(pcp->pl_flags & P_L))
859 else if (pcp->pl_flags & P_M)
865 * Can PP be loaded on a ship of SP's type?
868 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
870 int nch = 0, nxl = 0, nmsl = 0;
872 if (!inc_shp_nplane(pp, &nch, &nxl, &nmsl))
874 return ship_can_carry(sp, 1, nch, nxl, nmsl);
878 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
880 int n, nch, nxl, nmsl;
882 if (plane->pln_ship == ship->shp_uid)
883 return 1; /* Already on ship */
885 n = shp_nplane(ship, &nch, &nxl, &nmsl);
886 if (!inc_shp_nplane(plane, &nch, &nxl, &nmsl))
887 return 0; /* not a carrier plane */
888 if (!ship_can_carry(ship, n + 1, nch, nxl, nmsl))
889 return 0; /* no space */
891 plane->pln_x = ship->shp_x;
892 plane->pln_y = ship->shp_y;
893 plane->pln_ship = ship->shp_uid;
894 putplane(plane->pln_uid, plane);
899 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
901 if (plane->pln_land == land->lnd_uid)
902 return 1; /* Already on unit */
903 if (!(plchr[plane->pln_type].pl_flags & P_E))
905 if (lnd_nxlight(land) >= lchr[land->lnd_type].l_nxlight)
908 plane->pln_x = land->lnd_x;
909 plane->pln_y = land->lnd_y;
910 plane->pln_land = land->lnd_uid;
911 putplane(plane->pln_uid, plane);
916 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
919 struct plchrstr *pcp;
920 struct emp_qelem *qp;
921 struct emp_qelem *next;
927 getsect(x, y, §);
928 mines_there = sect.sct_mines;
930 if (mines_there == 0)
933 if (sect.sct_type != SCT_WATER)
936 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
939 ip = (struct plist *)qp;
942 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
945 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
947 xyas(sect.sct_x, sect.sct_y, player->cnum));
953 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
954 writemap(player->cnum);
955 sect.sct_mines = mines_there;
960 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
962 struct plchrstr *pcp = plchr + pp->pln_type;
963 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
964 (pp->pln_tech - pcp->pl_tech / 2);
965 int acc = pln_acc(pp);
968 if (type == EF_SHIP) {
969 if (pcp->pl_flags & P_A)
971 if (!(pcp->pl_flags & P_T))
974 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
975 (1.0 - acc / 100.0)) - hardtarget;
977 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
979 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
986 pln_damage(struct plnstr *pp, char type, int noisy)
988 struct plchrstr *pcp = plchr + pp->pln_type;
989 int load, i, hitroll, aim, len;
995 if (CANT_HAPPEN(nuk_on_plane(pp) >= 0))
999 if (!load) /* e.g. ab, blowing up on launch pad */
1006 if (pcp->pl_flags & P_M) {
1007 if (pcp->pl_flags & P_MAR)
1009 } else if (pcp->pl_flags & P_T)
1014 effective = !pinbomber;
1015 aim = 30 + (pinbomber ? aim : 100 - aim);
1017 effective = pinbomber;
1024 hitroll = roll(100);
1025 if (hitroll >= 90) {
1028 len += sprintf(buf + len, "BLAM");
1029 } else if (hitroll < aim) {
1032 len += sprintf(buf + len, "Blam");
1036 len += sprintf(buf + len, "blam");
1040 mpr(pp->pln_own, "%s\n", buf);
1044 len += sprintf(buf + len, "-");
1048 mpr(pp->pln_own, "%s\n", buf);
1055 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1058 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1059 return (int)(100 - 100 * misschance * misschance);
1063 pln_mobcost(int dist, struct plnstr *pp, char mission)
1067 cost = 20.0 / (pp->pln_effic / 100.0);
1068 if (mission == 'e' || mission == 0)
1069 cost /= 2; /* escort or intercept */
1071 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1075 pln_is_in_orbit(struct plnstr *pp)
1077 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1078 && (pp->pln_flags & PLN_LAUNCHED);
1082 * Set PP's tech to TLEV along with everything else that depends on it.
1085 pln_set_tech(struct plnstr *pp, int tlev)
1087 struct plchrstr *pcp = plchr + pp->pln_type;
1088 int limited_range = pp->pln_range < pln_range_max(pp);
1091 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1092 tlev = pcp->pl_tech;
1093 pp->pln_tech = tlev;
1095 range_max = pln_range_max(pp);
1096 if (!limited_range || pp->pln_range > range_max)
1097 pp->pln_range = range_max;