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 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 (ap_sect->sct_own == player->cnum
106 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
109 /* over own or allied ship is fine */
110 snxtitem_xy(&ni, EF_SHIP, x, y);
111 while (nxtitem(&ni, &ship)) {
112 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
114 if (ship.shp_own == player->cnum
115 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
119 pr("Assembly point not owned by you or an ally!\n");
124 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
136 nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
139 p = getstring("Carrier #? ", buf);
146 || !getship(cno, &ship)
148 && (getrel(getnatp(ship.shp_own), player->cnum)
153 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
154 pr("Ship #%d not in %s\n", cno,
155 xyas(target->sct_x, target->sct_y, player->cnum));
158 fl = carrier_planes(&ship, 0);
160 pr("Can't land on %s.\n", prship(&ship));
163 /* clear to land on ship#CNO */
164 pr("landing on carrier %d\n", cno);
172 /* try to land at sector */
173 if (target->sct_own != player->cnum
174 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
175 pr("Nowhere to land at sector %s!\n",
176 xyas(target->sct_x, target->sct_y, player->cnum));
179 if (target->sct_type == SCT_MOUNT) {
180 pr("Nowhere to land at sector %s!\n",
181 xyas(target->sct_x, target->sct_y, player->cnum));
184 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
187 /* clear to land at sector */
194 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
195 struct emp_qelem *esc_list, int cno)
197 struct emp_qelem *list, *qp;
201 if (cno < 0 || !getship(cno, &ship))
205 for (list = bomb_list;
207 list = list == bomb_list ? esc_list : NULL) {
208 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
209 plp = (struct plist *)qp;
210 if (plp->plane.pln_ship == ship.shp_uid)
212 if (!fit_plane_on_ship(&plp->plane, &ship))
220 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
222 struct emp_qelem *qp;
229 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
230 plp = (struct plist *)qp;
232 if (!could_be_on_ship(&plp->plane, &ship, 0, 0, 0, 0))
233 pr("\t%s cannot land on ship #%d! %s aborts!\n",
234 prplane(&plp->plane), cno, prplane(&plp->plane));
235 else if (!put_plane_on_ship(&plp->plane, &ship))
236 pr("\tNo room on ship #%d! %s aborts!\n",
237 cno, prplane(&plp->plane));
239 if (plp->plane.pln_own != ship.shp_own) {
240 wu(0, ship.shp_own, "%s %s lands on your %s\n",
241 cname(player->cnum), prplane(&plp->plane),
246 plp->plane.pln_x = tx;
247 plp->plane.pln_y = ty;
248 getsect(tx, ty, §);
249 if (plp->plane.pln_own != sect.sct_own) {
251 "%s %s lands at your sector %s\n",
253 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
255 plp->plane.pln_ship = cno;
261 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
264 struct emp_qelem *qp;
275 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
276 plp = (struct plist *)qp;
280 getsect(tx, ty, §);
282 if (sect.sct_type == SCT_WATER)
283 pr("Your %s sink like a rock!\n", ip->i_name);
285 pr("Your %s vanish without a trace.\n", ip->i_name);
288 if (sect.sct_own != player->cnum
289 && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
290 pr("You don't own %s! Cargo jettisoned...\n",
291 xyas(tx, ty, player->cnum));
294 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
295 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
296 xyas(tx, ty, player->cnum));
299 there = sect.sct_item[ip->i_uid];
303 there = ship.shp_item[ip->i_uid];
304 max = mchr[ship.shp_type].m_item[ip->i_uid];
308 pr("%d excess %s discarded\n", max - there, ip->i_name);
312 pr("%d %s landed safely", amt, ip->i_name);
314 sect.sct_item[ip->i_uid] = there;
315 if (sect.sct_own != player->cnum)
316 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
317 cname(player->cnum), amt, ip->i_name,
318 xyas(tx, ty, sect.sct_own));
319 pr(" at %s\n", xyas(tx, ty, player->cnum));
322 ship.shp_item[ip->i_uid] = there;
323 if (ship.shp_own != player->cnum)
324 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
325 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
326 pr(" on carrier #%d\n", ship.shp_uid);
327 putship(ship.shp_uid, &ship);
332 pln_mine(struct emp_qelem *list, coord tx, coord ty)
334 struct emp_qelem *qp;
340 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
341 plp = (struct plist *)qp;
346 getsect(tx, ty, §);
347 if (sect.sct_type != SCT_WATER) {
348 pr("Your seamines have no effect here.\n");
351 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
352 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
353 if (map_set(player->cnum, tx, ty, 'X', 0))
354 writemap(player->cnum);
360 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
361 * A plane type is capable unless
362 * - it lacks all of the P_B, P_T in WANTFLAGS, or
363 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
364 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
365 * - it lacks any of the other capabilities in WANTFLAGS, or
366 * - it has any of the capabilities in NOWANTFLAGS.
369 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
371 int flags = plchr[(int)pp->pln_type].pl_flags;
373 if (wantflags & (P_B | P_T)) {
374 if ((flags & wantflags & (P_B | P_T)) == 0)
376 wantflags &= ~(P_B | P_T);
379 if (wantflags & (P_F | P_ESC)) {
380 if ((flags & wantflags & (P_F | P_ESC)) == 0)
382 wantflags &= ~(P_F | P_ESC);
385 if (wantflags & (P_E | P_L | P_K)) {
386 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
388 wantflags &= ~(P_E | P_L | P_K);
391 if ((flags & wantflags) != wantflags)
394 if (flags & nowantflags)
401 * Return union of capabilities of planes in LIST.
404 pln_caps(struct emp_qelem *list)
406 struct emp_qelem *qp;
411 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
412 plp = (struct plist *)qp;
413 fl |= plp->pcp->pl_flags;
420 * Find plane types that can operate from carrier SP.
421 * If MSL find missile types, else non-missile types.
422 * Return a combination of P_L, P_K, P_E.
423 * It's zero if SP can't support air operations due to its type or
424 * state (low efficiency).
427 carrier_planes(struct shpstr *sp, int msl)
429 struct mchrstr *mcp = mchr + sp->shp_type;
432 if (sp->shp_effic < SHP_AIROPS_EFF)
436 if (mcp->m_flags & M_FLY)
438 if ((mcp->m_flags & M_MSL) && msl)
440 if (mcp->m_nchoppers && !msl)
448 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
453 struct plchrstr *pcp = plchr + pp->pln_type;
455 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
458 if (pp->pln_ship >= 0) {
459 /* ship: needs to be own or allied, efficient */
460 if (!getship(pp->pln_ship, &ship)) {
464 if (ship.shp_own != pp->pln_own
465 && getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED) {
467 pr("(note) An ally does not own the ship %s is on\n",
471 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
474 } else if (pp->pln_land >= 0) {
475 /* land: needs to be own or allied, efficient, not embarked */
476 if (!getland(pp->pln_land, &land)) {
480 if (land.lnd_own != pp->pln_own
481 && getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED) {
483 pr("(note) An ally does not own the unit %s is on\n",
487 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
489 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
493 /* sector: needs to be own or allied, efficient airfield */
494 if (!getsect(pp->pln_x, pp->pln_y, §)) {
499 if (sect.sct_own != pp->pln_own
500 && getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED) {
502 pr("(note) An ally does not own the sector %s is in\n",
506 /* need airfield unless VTOL */
507 if ((pcp->pl_flags & P_V) == 0) {
508 if (sect.sct_type != SCT_AIRPT) {
510 pr("%s not at airport\n", prplane(pp));
513 if (sect.sct_effic < 40) {
515 pr("%s is not 40%% efficient, %s can't take off from there.\n",
516 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
520 if (!oneway && sect.sct_effic < 60) {
522 pr("%s is not 60%% efficient, %s can't land there.\n",
523 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
534 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
535 int ap_to_target, int rangemult, int wantflags, int nowantflags)
539 struct plchrstr *pcp;
543 while (nxtitem(ni, &plane)) {
546 if (plane.pln_mobil <= 0)
548 if (plane.pln_effic < 40) {
549 pr("%s not efficient enough (must be 40%%)\n",
553 if (!pln_capable(&plane, wantflags, nowantflags))
556 if (ontradingblock(EF_PLANE, &plane)) {
557 pr("plane #%d inelligible - it's for sale.\n",
563 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
565 pr("%s too far from assembly point\n", prplane(&plane));
568 range += ap_to_target;
570 pcp = &plchr[(int)plane.pln_type];
571 if (plane.pln_range < range) {
572 pr("%s out of range (%d:%d)\n",
573 prplane(&plane), plane.pln_range, range);
576 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
578 pr("%s standing by\n", prplane(&plane));
579 plane.pln_mission = 0;
580 putplane(plane.pln_uid, &plane);
581 plp = malloc(sizeof(struct plist));
585 emp_insque(&plp->queue, list);
590 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
592 struct emp_qelem *qp;
593 struct emp_qelem *next;
597 for (qp = list->q_forw; qp != list; qp = next) {
599 plp = (struct plist *)qp;
601 getplane(pp->pln_uid, pp);
602 if ((pp->pln_flags & PLN_LAUNCHED)
603 || pln_equip(plp, ip, mission) < 0) {
608 pp->pln_flags |= PLN_LAUNCHED;
609 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
610 putplane(pp->pln_uid, pp);
611 pr("%s equipped\n", prplane(pp));
616 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
618 struct plchrstr *pcp;
631 if (pp->pln_ship >= 0) {
632 getship(pp->pln_ship, &ship);
633 item = ship.shp_item;
635 } else if (pp->pln_land >= 0) {
636 getland(pp->pln_land, &land);
637 item = land.lnd_item;
640 getsect(pp->pln_x, pp->pln_y, §);
641 item = sect.sct_item;
642 own = sect.sct_oldown;
644 if (pcp->pl_fuel > item[I_PETROL]) {
645 pr("%s not enough petrol there!\n", prplane(pp));
648 item[I_PETROL] -= pcp->pl_fuel;
652 case 's': /* strategic bomb */
653 case 'p': /* pinpoint bomb */
654 if (nuk_on_plane(pp) >= 0)
658 case 't': /* transport */
659 if (!(pcp->pl_flags & P_C) || !ip)
665 if ((pcp->pl_flags & P_MINE) == 0)
671 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
674 if (pcp->pl_flags & P_V)
677 case 'a': /* paradrop */
678 if (!(pcp->pl_flags & P_P))
681 if (pcp->pl_flags & P_V)
684 case 'r': /* reconnaissance */
685 case 'e': /* escort */
686 case 'i': /* missile interception */
687 if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
688 || !(pcp->pl_flags & (P_N | P_O))))
698 if (itype != I_NONE) {
699 needed = load / ichr[itype].i_lbs;
701 pr("%s can't contribute to mission\n", prplane(pp));
704 if (itype == I_CIVIL && pp->pln_own != own) {
705 pr("You don't control those civilians!\n");
709 /* Supply is broken somewhere, so don't use it for now */
710 if (itype == I_SHELL && item[itype] < needed)
711 item[itype] += supply_commod(plp->plane.pln_own,
716 abandon_needed = !!would_abandon(§, itype, needed, NULL);
717 if (item[itype] < needed + abandon_needed) {
718 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
721 item[itype] -= needed;
725 if (pp->pln_ship >= 0) {
726 if (pp->pln_own != ship.shp_own) {
728 "%s %s prepares for takeoff from ship %s\n",
729 cname(pp->pln_own), prplane(pp), prship(&ship));
731 putship(ship.shp_uid, &ship);
732 } else if (pp->pln_land >= 0) {
733 if (pp->pln_own != land.lnd_own) {
735 "%s %s prepares for takeoff from unit %s\n",
736 cname(pp->pln_own), prplane(pp), prland(&land));
738 putland(land.lnd_uid, &land);
740 if (pp->pln_own != sect.sct_own) {
741 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
742 cname(pp->pln_own), prplane(pp),
743 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
751 pln_put(struct emp_qelem *list)
753 struct emp_qelem *qp, *next;
755 for (qp = list->q_forw; qp != list; qp = next) {
757 pln_put1((struct plist *)qp);
762 pln_put1(struct plist *plp)
770 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
771 && (plchr[pp->pln_type].pl_flags & P_M)
772 && pp->pln_effic >= PLANE_MINEFF))
773 pp->pln_effic = 0; /* bug: missile launched but not used up */
775 if (!(pp->pln_flags & PLN_LAUNCHED))
776 ; /* never took off */
777 else if (pp->pln_effic < PLANE_MINEFF) {
779 } else if (pp->pln_ship >= 0) {
780 /* It is landing on a carrier */
781 getship(pp->pln_ship, &ship);
782 /* We should do more, like make sure it's really
783 a carrier, etc. but for now just make sure it's
785 if (ship.shp_effic < SHIP_MINEFF) {
787 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
788 "splashes into the sea.\n",
789 pp->pln_ship, pp->pln_uid);
793 /* Presume we are landing back in a sector. */
794 getsect(pp->pln_x, pp->pln_y, §);
795 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
797 "Nowhere to land at %s, plane #%d crashes and burns...\n",
798 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
802 pp->pln_flags &= ~PLN_LAUNCHED;
803 putplane(pp->pln_uid, pp);
804 emp_remque(&plp->queue);
809 * Can PP be loaded on a ship of SP's type?
810 * Assume that it already carries N planes, of which NCH are choppers,
811 * NXL xlight, NMSL light missiles, and the rest are light fixed-wing
815 could_be_on_ship(struct plnstr *pp, struct shpstr *sp,
816 int n, int nch, int nxl, int nmsl)
818 struct plchrstr *pcp = &plchr[pp->pln_type];
819 struct mchrstr *mcp = &mchr[sp->shp_type];
821 if (pcp->pl_flags & P_K)
823 else if (pcp->pl_flags & P_E)
825 else if (!(pcp->pl_flags & P_L))
827 else if (pcp->pl_flags & P_M)
831 n -= MIN(nch, mcp->m_nchoppers);
832 n -= MIN(nxl, mcp->m_nxlight);
833 if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
834 return 0; /* missile slots wanted */
835 if (nmsl < n && !(mcp->m_flags & M_FLY))
836 return 0; /* fixed-wing slots wanted */
837 return n <= mcp->m_nplanes;
841 * Fit a plane of PP's type on ship SP.
842 * Updating the plane accordingly is the caller's job.
843 * Return whether it fits.
846 fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
848 int n, nch, nxl, nmsl;
850 n = shp_nplane(sp, &nch, &nxl, &nmsl);
851 return could_be_on_ship(pp, sp, n, nch, nxl, nmsl);
855 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
857 if (plane->pln_ship == ship->shp_uid)
858 return 1; /* Already on ship */
860 if (!fit_plane_on_ship(plane, ship))
863 plane->pln_x = ship->shp_x;
864 plane->pln_y = ship->shp_y;
865 plane->pln_ship = ship->shp_uid;
866 putplane(plane->pln_uid, plane);
871 * Fit a plane of PP's type on land unit LP.
872 * Updating the plane accordingly is the caller's job.
873 * Return whether it fits.
876 fit_plane_on_land(struct plnstr *pp, struct lndstr *lp)
878 struct plchrstr *pcp = plchr + pp->pln_type;
879 struct lchrstr *lcp = lchr + lp->lnd_type;
881 return (pcp->pl_flags & P_E) && lnd_nxlight(lp) < lcp->l_nxlight;
885 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
887 if (plane->pln_land == land->lnd_uid)
888 return 1; /* Already on unit */
890 if (!fit_plane_on_land(plane, land))
893 plane->pln_x = land->lnd_x;
894 plane->pln_y = land->lnd_y;
895 plane->pln_land = land->lnd_uid;
896 putplane(plane->pln_uid, plane);
901 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
904 struct plchrstr *pcp;
905 struct emp_qelem *qp;
906 struct emp_qelem *next;
912 getsect(x, y, §);
913 mines_there = sect.sct_mines;
915 if (mines_there == 0)
918 if (sect.sct_type != SCT_WATER)
921 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
924 ip = (struct plist *)qp;
927 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
930 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
932 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
938 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
939 writemap(player->cnum);
940 sect.sct_mines = mines_there;
945 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
947 struct plchrstr *pcp = plchr + pp->pln_type;
948 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
949 (pp->pln_tech - pcp->pl_tech / 2);
950 int acc = pln_acc(pp);
953 if (type == EF_SHIP) {
954 if (pcp->pl_flags & P_A)
956 if (!(pcp->pl_flags & P_T))
959 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
960 (1.0 - acc / 100.0)) - hardtarget;
962 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
964 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
970 /* return 0 if there was a nuclear detonation */
973 pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
977 struct plchrstr *pcp = plchr + pp->pln_type;
985 if (getnuke(nuk_on_plane(pp), &nuke)) {
986 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
987 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
988 *nukedamp = detonate(&nuke, x, y,
989 pp->pln_flags & PLN_AIRBURST);
995 if (!load) /* e.g. ab, blowing up on launch pad */
1002 if (pcp->pl_flags & P_M) {
1003 if (pcp->pl_flags & P_MAR)
1005 } else if (pcp->pl_flags & P_T)
1010 effective = !pinbomber;
1011 aim = 30 + (pinbomber ? aim : 100 - aim);
1013 effective = pinbomber;
1019 hitroll = roll(100);
1020 if (hitroll >= 90) {
1023 mpr(pp->pln_own, "BLAM");
1024 } else if (hitroll < aim) {
1027 mpr(pp->pln_own, "Blam");
1031 mpr(pp->pln_own, "blam");
1034 mpr(pp->pln_own, "-");
1037 mpr(pp->pln_own, "\n");
1044 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1047 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1048 return (int)(100 - 100 * misschance * misschance);
1052 pln_mobcost(int dist, struct plnstr *pp, char mission)
1056 cost = 20.0 / (pp->pln_effic / 100.0);
1057 if (mission == 'e' || mission == 0)
1058 cost /= 2; /* escort or intercept */
1060 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1064 pln_is_in_orbit(struct plnstr *pp)
1066 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1067 && (pp->pln_flags & PLN_LAUNCHED);
1071 * Set PP's tech to TLEV along with everything else that depends on it.
1074 pln_set_tech(struct plnstr *pp, int tlev)
1076 struct plchrstr *pcp = plchr + pp->pln_type;
1077 int limited_range = pp->pln_range < pln_range_max(pp);
1080 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1081 tlev = pcp->pl_tech;
1082 pp->pln_tech = tlev;
1084 range_max = pln_range_max(pp);
1085 if (!limited_range || pp->pln_range > range_max)
1086 pp->pln_range = range_max;