2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, 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-2015
52 #include "prototypes.h"
57 static int ship_can_carry(struct shpstr *, int, int, int, int);
58 static int inc_shp_nplane(struct plnstr *, int *, int *, int *);
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.
64 * Same for @input_esc.
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.
86 * Else prompt for more input using @prompt.
87 * If this yields a valid assembly point, read it into *@ap_sect and
89 * Else complain and return NULL.
90 * *@ap_sect and @buf[1024] may be modified in either case.
93 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
100 p = getstarg(input, "assembly point? ", buf);
103 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
106 /* over own or allied sector is fine */
107 if (relations_with(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 (relations_with(ship.shp_own, player->cnum) == ALLIED)
119 pr("Assembly point not owned by you or an ally!\n");
124 * Find out whether planes can fly one-way to @x,@y.
125 * Offer the player any carriers there. If he chooses one, read it
126 * into @target->ship. Else read the target sector into @target->sect.
127 * If planes can land there, set required plane flags in *@flagsp, and
128 * return 0. Else return -1.
131 pln_where_to_land(coord x, coord y,
132 union empobj_storage *target, int *flagsp)
141 nships = carriersatxy(x, y, player->cnum);
144 p = getstring("Carrier #? ", buf);
150 if (!getship(cno, &target->ship)
152 && (relations_with(target->ship.shp_own, player->cnum)
157 if (target->ship.shp_x != x || target->ship.shp_y != y) {
158 pr("Ship #%d not in %s\n", cno, xyas(x, y, player->cnum));
161 fl = carrier_planes(&target->ship, 0);
163 pr("Can't land on %s.\n", prship(&target->ship));
166 /* clear to land on ship#CNO */
167 pr("landing on carrier %d\n", cno);
173 /* try to land at sector */
174 getsect(x, y, &target->sect);
175 if (relations_with(target->sect.sct_own, player->cnum) != ALLIED) {
176 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
179 if (target->sect.sct_type == SCT_MOUNT) {
180 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
183 /* clear to land at sector */
184 if (target->sect.sct_type != SCT_AIRPT || target->sect.sct_effic < 60)
190 pln_can_land_on_carrier(struct emp_qelem *bomb_list,
191 struct emp_qelem *esc_list,
195 int n, nch, nxl, nmsl;
196 struct emp_qelem *list, *qp;
199 n = shp_nplane(sp, &nch, &nxl, &nmsl);
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 == sp->shp_uid)
210 if (!inc_shp_nplane(&plp->plane, &nch, &nxl, &nmsl))
214 return ship_can_carry(sp, n, nch, nxl, nmsl);
218 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
220 struct emp_qelem *qp;
227 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
228 plp = (struct plist *)qp;
230 if (!could_be_on_ship(&plp->plane, &ship))
231 pr("\t%s cannot land on ship #%d! %s aborts!\n",
232 prplane(&plp->plane), cno, prplane(&plp->plane));
233 else if (!put_plane_on_ship(&plp->plane, &ship))
234 pr("\tNo room on ship #%d! %s aborts!\n",
235 cno, prplane(&plp->plane));
237 if (plp->plane.pln_own != ship.shp_own) {
238 wu(0, ship.shp_own, "%s %s lands on your %s\n",
239 cname(player->cnum), prplane(&plp->plane),
242 if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
243 && ship.shp_pstage == PLG_HEALTHY)
244 ship.shp_pstage = PLG_EXPOSED;
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 if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
257 && sect.sct_pstage == PLG_HEALTHY)
258 sect.sct_pstage = PLG_EXPOSED;
259 plp->plane.pln_ship = cno;
265 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
268 struct emp_qelem *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 (relations_with(sect.sct_own, player->cnum) != ALLIED) {
289 pr("You don't own %s! Cargo jettisoned...\n",
290 xyas(tx, ty, player->cnum));
293 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
294 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
295 xyas(tx, ty, player->cnum));
298 there = sect.sct_item[ip->i_uid];
300 pstage = sect.sct_pstage;
303 there = ship.shp_item[ip->i_uid];
304 max = mchr[ship.shp_type].m_item[ip->i_uid];
305 pstage = ship.shp_pstage;
309 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
310 plp = (struct plist *)qp;
313 && plp->pstage == PLG_INFECT && pstage == PLG_HEALTHY)
314 pstage = PLG_EXPOSED;
319 pr("%d excess %s discarded\n", there - max, ip->i_name);
323 pr("%d %s landed safely", amt, ip->i_name);
325 sect.sct_item[ip->i_uid] = there;
326 sect.sct_pstage = pstage;
327 if (sect.sct_own != player->cnum)
328 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
329 cname(player->cnum), amt, ip->i_name,
330 xyas(tx, ty, sect.sct_own));
331 pr(" at %s\n", xyas(tx, ty, player->cnum));
334 ship.shp_item[ip->i_uid] = there;
335 ship.shp_pstage = pstage;
336 if (ship.shp_own != player->cnum)
337 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
338 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
339 pr(" on carrier #%d\n", ship.shp_uid);
340 putship(ship.shp_uid, &ship);
345 pln_mine(struct emp_qelem *list, coord tx, coord ty)
347 struct emp_qelem *qp;
353 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
354 plp = (struct plist *)qp;
359 getsect(tx, ty, §);
360 if (sect.sct_type != SCT_WATER) {
361 pr("Your seamines have no effect here.\n");
364 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
365 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
366 if (map_set(player->cnum, tx, ty, 'X', 0))
367 writemap(player->cnum);
373 * Has @pp's type capabilities satisfying @wantflags and @nowantflags?
374 * A plane type is capable unless
375 * - it lacks all of the P_B, P_T in @wantflags, or
376 * - it lacks all of the P_F, P_ESC in @wantflags, or
377 * - it lacks all of the P_E, P_L, P_K in @wantflags, or
378 * - it lacks any of the other capabilities in @wantflags, or
379 * - it has any of the capabilities in @nowantflags.
382 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
384 int flags = plchr[(int)pp->pln_type].pl_flags;
386 if (wantflags & (P_B | P_T)) {
387 if ((flags & wantflags & (P_B | P_T)) == 0)
389 wantflags &= ~(P_B | P_T);
392 if (wantflags & (P_F | P_ESC)) {
393 if ((flags & wantflags & (P_F | P_ESC)) == 0)
395 wantflags &= ~(P_F | P_ESC);
398 if (wantflags & (P_E | P_L | P_K)) {
399 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
401 wantflags &= ~(P_E | P_L | P_K);
404 if ((flags & wantflags) != wantflags)
407 if (flags & nowantflags)
414 * Return union of capabilities of planes in @list.
417 pln_caps(struct emp_qelem *list)
419 struct emp_qelem *qp;
424 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
425 plp = (struct plist *)qp;
426 fl |= plp->pcp->pl_flags;
433 * Find plane types that can operate from carrier @sp.
434 * If @msl find missile types, else non-missile types.
435 * Return a combination of P_L, P_K, P_E.
436 * It's zero if @sp can't support air operations due to its type or
437 * state (low efficiency).
440 carrier_planes(struct shpstr *sp, int msl)
442 struct mchrstr *mcp = mchr + sp->shp_type;
445 if (sp->shp_effic < SHP_AIROPS_EFF)
449 if (mcp->m_flags & M_FLY)
451 if ((mcp->m_flags & M_MSL) && msl)
453 if (mcp->m_nchoppers && !msl)
461 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
466 struct plchrstr *pcp = plchr + pp->pln_type;
468 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
471 if (pp->pln_ship >= 0) {
472 /* ship: needs to be own or allied, efficient */
473 if (!getship(pp->pln_ship, &ship)) {
477 if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
479 pr("(note) An ally does not own the ship %s is on\n",
483 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
486 } else if (pp->pln_land >= 0) {
487 /* land: needs to be own or allied, efficient, not embarked */
488 if (!getland(pp->pln_land, &land)) {
492 if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
494 pr("(note) An ally does not own the unit %s is on\n",
498 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
500 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
504 /* sector: needs to be own or allied, efficient airfield */
505 if (!getsect(pp->pln_x, pp->pln_y, §)) {
510 if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
512 pr("(note) An ally does not own the sector %s is in\n",
516 /* need airfield unless VTOL */
517 if ((pcp->pl_flags & P_V) == 0) {
518 if (sect.sct_type != SCT_AIRPT) {
520 pr("%s not at airport\n", prplane(pp));
523 if (sect.sct_effic < 40) {
525 pr("%s is not 40%% efficient, %s can't take off from there.\n",
526 xyas(sect.sct_x, sect.sct_y, player->cnum),
530 if (!oneway && sect.sct_effic < 60) {
532 pr("%s is not 60%% efficient, %s can't land there.\n",
533 xyas(sect.sct_x, sect.sct_y, player->cnum),
544 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
545 int ap_to_target, int rangemult, int wantflags, int nowantflags)
549 struct plchrstr *pcp;
553 while (nxtitem(ni, &plane)) {
555 * It would be nice to let deities fly foreign planes, but
556 * much of the code assumes that only the plane's owner can
559 if (!plane.pln_own || plane.pln_own != player->cnum)
561 if (plane.pln_mobil <= 0)
563 if (plane.pln_effic < 40) {
564 pr("%s not efficient enough (must be 40%%)\n",
568 if (!pln_capable(&plane, wantflags, nowantflags))
571 if (ontradingblock(EF_PLANE, &plane)) {
572 pr("plane #%d inelligible - it's for sale.\n",
578 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
580 pr("%s too far from assembly point\n", prplane(&plane));
583 range += ap_to_target;
585 pcp = &plchr[(int)plane.pln_type];
586 if (plane.pln_range < range) {
587 pr("%s out of range (%d:%d)\n",
588 prplane(&plane), plane.pln_range, range);
591 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
593 pr("%s standing by\n", prplane(&plane));
594 plane.pln_mission = 0;
595 putplane(plane.pln_uid, &plane);
596 plp = malloc(sizeof(struct plist));
598 plp->pstage = PLG_HEALTHY;
601 emp_insque(&plp->queue, list);
606 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
608 struct emp_qelem *qp;
609 struct emp_qelem *next;
613 for (qp = list->q_forw; qp != list; qp = next) {
615 plp = (struct plist *)qp;
617 getplane(pp->pln_uid, pp);
618 if ((pp->pln_flags & PLN_LAUNCHED)
619 || pln_equip(plp, ip, mission) < 0) {
624 pp->pln_flags |= PLN_LAUNCHED;
625 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
626 putplane(pp->pln_uid, pp);
627 pr("%s equipped\n", prplane(pp));
632 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
634 struct plchrstr *pcp;
647 if (pp->pln_ship >= 0) {
648 getship(pp->pln_ship, &ship);
649 plp->pstage = ship.shp_pstage;
650 item = ship.shp_item;
652 } else if (pp->pln_land >= 0) {
653 getland(pp->pln_land, &land);
654 plp->pstage = land.lnd_pstage;
655 item = land.lnd_item;
658 getsect(pp->pln_x, pp->pln_y, §);
659 plp->pstage = sect.sct_pstage;
660 item = sect.sct_item;
661 own = sect.sct_oldown;
663 if (pcp->pl_fuel > item[I_PETROL]) {
664 pr("%s not enough petrol there!\n", prplane(pp));
667 item[I_PETROL] -= pcp->pl_fuel;
671 case 's': /* strategic bomb */
672 case 'p': /* pinpoint bomb */
675 case 't': /* transport */
676 if (!(pcp->pl_flags & P_C) || !ip)
682 if ((pcp->pl_flags & P_MINE) == 0)
688 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
691 if (pcp->pl_flags & P_V)
694 case 'a': /* paradrop */
695 if (!(pcp->pl_flags & P_P))
698 if (pcp->pl_flags & P_V)
701 case 'r': /* reconnaissance */
702 case 'e': /* escort */
705 case 'i': /* missile interception */
706 if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
707 || !(pcp->pl_flags & (P_N | P_O))))
717 if (itype != I_NONE) {
718 needed = load / ichr[itype].i_lbs;
720 pr("%s can't contribute to mission\n", prplane(pp));
723 if (nuk_on_plane(pp) >= 0) {
724 if (mission == 's' || mission == 't')
727 pr("%s can't fly this mission"
728 " while it is carrying a nuclear weapon",
733 if (itype == I_CIVIL && pp->pln_own != own) {
734 pr("You don't control those civilians!\n");
738 /* Supply is broken somewhere, so don't use it for now */
739 if (itype == I_SHELL && item[itype] < needed)
740 item[itype] += supply_commod(plp->plane.pln_own,
745 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
748 abandon_needed = !!would_abandon(§, itype, needed, NULL);
749 if (item[itype] < needed + abandon_needed) {
750 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
753 item[itype] -= needed;
757 if (pp->pln_ship >= 0) {
758 if (pp->pln_own != ship.shp_own) {
760 "%s %s prepares for takeoff from ship %s\n",
761 cname(pp->pln_own), prplane(pp), prship(&ship));
763 putship(ship.shp_uid, &ship);
764 } else if (pp->pln_land >= 0) {
765 if (pp->pln_own != land.lnd_own) {
767 "%s %s prepares for takeoff from unit %s\n",
768 cname(pp->pln_own), prplane(pp), prland(&land));
770 putland(land.lnd_uid, &land);
772 if (pp->pln_own != sect.sct_own) {
773 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
774 cname(pp->pln_own), prplane(pp),
775 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
783 pln_put(struct emp_qelem *list)
785 struct emp_qelem *qp, *next;
787 for (qp = list->q_forw; qp != list; qp = next) {
789 pln_put1((struct plist *)qp);
794 pln_put1(struct plist *plp)
802 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
803 && (plchr[pp->pln_type].pl_flags & P_M)
804 && pp->pln_effic >= PLANE_MINEFF))
805 pp->pln_effic = 0; /* bug: missile launched but not used up */
807 if (!(pp->pln_flags & PLN_LAUNCHED))
808 ; /* never took off */
809 else if (pp->pln_effic < PLANE_MINEFF) {
811 } else if (pp->pln_ship >= 0) {
812 /* It is landing on a carrier */
813 getship(pp->pln_ship, &ship);
814 /* We should do more, like make sure it's really
815 a carrier, etc. but for now just make sure it's
817 if (ship.shp_effic < SHIP_MINEFF) {
819 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
820 "splashes into the sea.\n",
821 pp->pln_ship, pp->pln_uid);
825 /* Presume we are landing back in a sector. */
826 getsect(pp->pln_x, pp->pln_y, §);
827 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
829 "Nowhere to land at %s, plane #%d crashes and burns...\n",
830 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
834 pp->pln_flags &= ~PLN_LAUNCHED;
835 putplane(pp->pln_uid, pp);
836 emp_remque(&plp->queue);
841 * Can a carrier of @sp's type carry this load of planes?
842 * The load consists of @n planes, of which @nch are choppers, @nxl
843 * xlight, @nmsl light missiles, and the rest are light fixed-wing
847 ship_can_carry(struct shpstr *sp, int n, int nch, int nxl, int nmsl)
849 struct mchrstr *mcp = &mchr[sp->shp_type];
850 int nfw = n - nch - nxl - nmsl;
852 if (nch > mcp->m_nchoppers) /* overflow into fixed-wing slots */
853 nfw += nch - mcp->m_nchoppers;
854 if (nxl > mcp->m_nxlight) /* overflow into missile slots */
855 nmsl += nxl - mcp->m_nxlight;
856 if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
857 return 0; /* missile slots wanted */
858 if (nfw && !(mcp->m_flags & M_FLY))
859 return 0; /* fixed-wing slots wanted */
860 return nfw + nmsl <= mcp->m_nplanes;
864 * Increment carrier plane counters for @pp.
865 * If it's a chopper, increment *@nch.
866 * Else, if it's x-light, increment *@nxl.
867 * Else, if it's a light missile, increment *@msl.
868 * Return non-zero if it's a chopper, x-light or light.
871 inc_shp_nplane(struct plnstr *pp, int *nch, int *nxl, int *nmsl)
873 struct plchrstr *pcp = &plchr[pp->pln_type];
875 if (pcp->pl_flags & P_K)
877 else if (pcp->pl_flags & P_E)
879 else if (!(pcp->pl_flags & P_L))
881 else if (pcp->pl_flags & P_M)
887 * Can @pp be loaded on a ship of @sp's type?
890 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
892 int nch = 0, nxl = 0, nmsl = 0;
894 if (!inc_shp_nplane(pp, &nch, &nxl, &nmsl))
896 return ship_can_carry(sp, 1, nch, nxl, nmsl);
900 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
902 int n, nch, nxl, nmsl;
904 if (plane->pln_ship == ship->shp_uid)
905 return 1; /* Already on ship */
907 n = shp_nplane(ship, &nch, &nxl, &nmsl);
908 if (!inc_shp_nplane(plane, &nch, &nxl, &nmsl))
909 return 0; /* not a carrier plane */
910 if (!ship_can_carry(ship, n + 1, nch, nxl, nmsl))
911 return 0; /* no space */
913 plane->pln_x = ship->shp_x;
914 plane->pln_y = ship->shp_y;
915 plane->pln_ship = ship->shp_uid;
916 putplane(plane->pln_uid, plane);
921 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
923 if (plane->pln_land == land->lnd_uid)
924 return 1; /* Already on unit */
925 if (!(plchr[plane->pln_type].pl_flags & P_E))
927 if (lnd_nxlight(land) >= lchr[land->lnd_type].l_nxlight)
930 plane->pln_x = land->lnd_x;
931 plane->pln_y = land->lnd_y;
932 plane->pln_land = land->lnd_uid;
933 putplane(plane->pln_uid, plane);
938 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
941 struct plchrstr *pcp;
942 struct emp_qelem *qp;
943 struct emp_qelem *next;
949 getsect(x, y, §);
950 mines_there = sect.sct_mines;
952 if (mines_there == 0)
955 if (sect.sct_type != SCT_WATER)
958 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
961 ip = (struct plist *)qp;
964 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
967 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
969 xyas(sect.sct_x, sect.sct_y, player->cnum));
975 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
976 writemap(player->cnum);
977 sect.sct_mines = mines_there;
982 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
984 struct plchrstr *pcp = plchr + pp->pln_type;
985 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
986 (pp->pln_tech - pcp->pl_tech / 2);
987 int acc = pln_acc(pp);
990 if (type == EF_SHIP) {
991 if (pcp->pl_flags & P_A)
993 if (!(pcp->pl_flags & P_T))
996 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
997 (1.0 - acc / 100.0)) - hardtarget;
999 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1001 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1002 if (hitchance > 100)
1008 pln_damage(struct plnstr *pp, char type, char *noisy)
1010 struct plchrstr *pcp = plchr + pp->pln_type;
1011 int load, i, hitroll, aim, len;
1017 if (CANT_HAPPEN(nuk_on_plane(pp) >= 0))
1020 load = pln_load(pp);
1021 if (!load) /* e.g. ab, blowing up on launch pad */
1028 if (pcp->pl_flags & P_M) {
1029 if (pcp->pl_flags & P_MAR)
1031 } else if (pcp->pl_flags & P_T)
1036 effective = !pinbomber;
1037 aim = 30 + (pinbomber ? aim : 100 - aim);
1039 effective = pinbomber;
1043 len = snprintf(buf, sizeof(buf), "%s", noisy);
1047 mpr(pp->pln_own, "%s\n", buf);
1052 hitroll = roll(100);
1053 if (hitroll >= 90) {
1056 len += sprintf(buf + len, "BLAM");
1057 } else if (hitroll < aim) {
1060 len += sprintf(buf + len, "Blam");
1064 len += sprintf(buf + len, "blam");
1068 len += sprintf(buf + len, "-");
1072 mpr(pp->pln_own, "%s\n", buf);
1079 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1082 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1083 return (int)(100 - 100 * misschance * misschance);
1087 pln_mobcost(int dist, struct plnstr *pp, char mission)
1091 cost = 20.0 / (pp->pln_effic / 100.0);
1092 if (mission == 'e' || mission == 0)
1093 cost /= 2; /* escort or intercept */
1095 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1099 pln_is_in_orbit(struct plnstr *pp)
1101 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1102 && (pp->pln_flags & PLN_LAUNCHED);
1106 * Set @pp's tech to @tlev along with everything else that depends on it.
1109 pln_set_tech(struct plnstr *pp, int tlev)
1111 struct plchrstr *pcp = plchr + pp->pln_type;
1112 int limited_range = pp->pln_range < pln_range_max(pp);
1115 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1116 tlev = pcp->pl_tech;
1117 pp->pln_tech = tlev;
1119 range_max = pln_range_max(pp);
1120 if (!limited_range || pp->pln_range > range_max)
1121 pp->pln_range = range_max;