2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2015, 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.
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, else prompt for more input using PROMPT.
86 * If this yields a valid assembly point, read it into *AP_SECT and
88 * Else complain and return NULL.
89 * *AP_SECT and BUF[1024] may be modified in either case.
92 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
99 p = getstarg(input, "assembly point? ", buf);
102 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
105 /* over own or allied sector is fine */
106 if (relations_with(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 (relations_with(ship.shp_own, player->cnum) == ALLIED)
118 pr("Assembly point not owned by you or an ally!\n");
123 * Find out whether planes can fly one-way to X,Y.
124 * Offer the player any carriers there. If he chooses one, read it
125 * into TARGET->ship. Else read the target sector into TARGET->sect.
126 * If planes can land there, set required plane flags in *FLAGSP, and
127 * return 0. Else return -1.
130 pln_where_to_land(coord x, coord y,
131 union empobj_storage *target, int *flagsp)
140 nships = carriersatxy(x, y, player->cnum);
143 p = getstring("Carrier #? ", buf);
149 if (!getship(cno, &target->ship)
151 && (relations_with(target->ship.shp_own, player->cnum)
156 if (target->ship.shp_x != x || target->ship.shp_y != y) {
157 pr("Ship #%d not in %s\n", cno, xyas(x, y, player->cnum));
160 fl = carrier_planes(&target->ship, 0);
162 pr("Can't land on %s.\n", prship(&target->ship));
165 /* clear to land on ship#CNO */
166 pr("landing on carrier %d\n", cno);
172 /* try to land at sector */
173 getsect(x, y, &target->sect);
174 if (relations_with(target->sect.sct_own, player->cnum) != ALLIED) {
175 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
178 if (target->sect.sct_type == SCT_MOUNT) {
179 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
182 /* clear to land at sector */
183 if (target->sect.sct_type != SCT_AIRPT || target->sect.sct_effic < 60)
189 pln_can_land_on_carrier(struct emp_qelem *bomb_list,
190 struct emp_qelem *esc_list,
194 int n, nch, nxl, nmsl;
195 struct emp_qelem *list, *qp;
198 n = shp_nplane(sp, &nch, &nxl, &nmsl);
201 for (list = bomb_list;
203 list = list == bomb_list ? esc_list : NULL) {
204 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
205 plp = (struct plist *)qp;
206 if (plp->plane.pln_ship == sp->shp_uid)
209 if (!inc_shp_nplane(&plp->plane, &nch, &nxl, &nmsl))
213 return ship_can_carry(sp, n, nch, nxl, nmsl);
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))
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),
241 if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
242 && ship.shp_pstage == PLG_HEALTHY)
243 ship.shp_pstage = PLG_EXPOSED;
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 if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
256 && sect.sct_pstage == PLG_HEALTHY)
257 sect.sct_pstage = PLG_EXPOSED;
258 plp->plane.pln_ship = cno;
264 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
267 struct emp_qelem *qp;
279 getsect(tx, ty, §);
281 if (sect.sct_type == SCT_WATER)
282 pr("Your %s sink like a rock!\n", ip->i_name);
284 pr("Your %s vanish without a trace.\n", ip->i_name);
287 if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
288 pr("You don't own %s! Cargo jettisoned...\n",
289 xyas(tx, ty, player->cnum));
292 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
293 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
294 xyas(tx, ty, player->cnum));
297 there = sect.sct_item[ip->i_uid];
299 pstage = sect.sct_pstage;
302 there = ship.shp_item[ip->i_uid];
303 max = mchr[ship.shp_type].m_item[ip->i_uid];
304 pstage = ship.shp_pstage;
308 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
309 plp = (struct plist *)qp;
312 && plp->pstage == PLG_INFECT && pstage == PLG_HEALTHY)
313 pstage = PLG_EXPOSED;
318 pr("%d excess %s discarded\n", there - max, ip->i_name);
322 pr("%d %s landed safely", amt, ip->i_name);
324 sect.sct_item[ip->i_uid] = there;
325 sect.sct_pstage = pstage;
326 if (sect.sct_own != player->cnum)
327 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
328 cname(player->cnum), amt, ip->i_name,
329 xyas(tx, ty, sect.sct_own));
330 pr(" at %s\n", xyas(tx, ty, player->cnum));
333 ship.shp_item[ip->i_uid] = there;
334 ship.shp_pstage = pstage;
335 if (ship.shp_own != player->cnum)
336 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
337 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
338 pr(" on carrier #%d\n", ship.shp_uid);
339 putship(ship.shp_uid, &ship);
344 pln_mine(struct emp_qelem *list, coord tx, coord ty)
346 struct emp_qelem *qp;
352 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
353 plp = (struct plist *)qp;
358 getsect(tx, ty, §);
359 if (sect.sct_type != SCT_WATER) {
360 pr("Your seamines have no effect here.\n");
363 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
364 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
365 if (map_set(player->cnum, tx, ty, 'X', 0))
366 writemap(player->cnum);
372 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
373 * A plane type is capable unless
374 * - it lacks all of the P_B, P_T in WANTFLAGS, or
375 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
376 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
377 * - it lacks any of the other capabilities in WANTFLAGS, or
378 * - it has any of the capabilities in NOWANTFLAGS.
381 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
383 int flags = plchr[(int)pp->pln_type].pl_flags;
385 if (wantflags & (P_B | P_T)) {
386 if ((flags & wantflags & (P_B | P_T)) == 0)
388 wantflags &= ~(P_B | P_T);
391 if (wantflags & (P_F | P_ESC)) {
392 if ((flags & wantflags & (P_F | P_ESC)) == 0)
394 wantflags &= ~(P_F | P_ESC);
397 if (wantflags & (P_E | P_L | P_K)) {
398 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
400 wantflags &= ~(P_E | P_L | P_K);
403 if ((flags & wantflags) != wantflags)
406 if (flags & nowantflags)
413 * Return union of capabilities of planes in LIST.
416 pln_caps(struct emp_qelem *list)
418 struct emp_qelem *qp;
423 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
424 plp = (struct plist *)qp;
425 fl |= plp->pcp->pl_flags;
432 * Find plane types that can operate from carrier SP.
433 * If MSL find missile types, else non-missile types.
434 * Return a combination of P_L, P_K, P_E.
435 * It's zero if SP can't support air operations due to its type or
436 * state (low efficiency).
439 carrier_planes(struct shpstr *sp, int msl)
441 struct mchrstr *mcp = mchr + sp->shp_type;
444 if (sp->shp_effic < SHP_AIROPS_EFF)
448 if (mcp->m_flags & M_FLY)
450 if ((mcp->m_flags & M_MSL) && msl)
452 if (mcp->m_nchoppers && !msl)
460 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
465 struct plchrstr *pcp = plchr + pp->pln_type;
467 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
470 if (pp->pln_ship >= 0) {
471 /* ship: needs to be own or allied, efficient */
472 if (!getship(pp->pln_ship, &ship)) {
476 if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
478 pr("(note) An ally does not own the ship %s is on\n",
482 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
485 } else if (pp->pln_land >= 0) {
486 /* land: needs to be own or allied, efficient, not embarked */
487 if (!getland(pp->pln_land, &land)) {
491 if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
493 pr("(note) An ally does not own the unit %s is on\n",
497 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
499 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
503 /* sector: needs to be own or allied, efficient airfield */
504 if (!getsect(pp->pln_x, pp->pln_y, §)) {
509 if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
511 pr("(note) An ally does not own the sector %s is in\n",
515 /* need airfield unless VTOL */
516 if ((pcp->pl_flags & P_V) == 0) {
517 if (sect.sct_type != SCT_AIRPT) {
519 pr("%s not at airport\n", prplane(pp));
522 if (sect.sct_effic < 40) {
524 pr("%s is not 40%% efficient, %s can't take off from there.\n",
525 xyas(sect.sct_x, sect.sct_y, player->cnum),
529 if (!oneway && sect.sct_effic < 60) {
531 pr("%s is not 60%% efficient, %s can't land there.\n",
532 xyas(sect.sct_x, sect.sct_y, player->cnum),
543 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
544 int ap_to_target, int rangemult, int wantflags, int nowantflags)
548 struct plchrstr *pcp;
552 while (nxtitem(ni, &plane)) {
554 * It would be nice to let deities fly foreign planes, but
555 * much of the code assumes that only the plane's owner can
558 if (!plane.pln_own || plane.pln_own != player->cnum)
560 if (plane.pln_mobil <= 0)
562 if (plane.pln_effic < 40) {
563 pr("%s not efficient enough (must be 40%%)\n",
567 if (!pln_capable(&plane, wantflags, nowantflags))
570 if (ontradingblock(EF_PLANE, &plane)) {
571 pr("plane #%d inelligible - it's for sale.\n",
577 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
579 pr("%s too far from assembly point\n", prplane(&plane));
582 range += ap_to_target;
584 pcp = &plchr[(int)plane.pln_type];
585 if (plane.pln_range < range) {
586 pr("%s out of range (%d:%d)\n",
587 prplane(&plane), plane.pln_range, range);
590 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
592 pr("%s standing by\n", prplane(&plane));
593 plane.pln_mission = 0;
594 putplane(plane.pln_uid, &plane);
595 plp = malloc(sizeof(struct plist));
597 plp->pstage = PLG_HEALTHY;
600 emp_insque(&plp->queue, list);
605 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
607 struct emp_qelem *qp;
608 struct emp_qelem *next;
612 for (qp = list->q_forw; qp != list; qp = next) {
614 plp = (struct plist *)qp;
616 getplane(pp->pln_uid, pp);
617 if ((pp->pln_flags & PLN_LAUNCHED)
618 || pln_equip(plp, ip, mission) < 0) {
623 pp->pln_flags |= PLN_LAUNCHED;
624 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
625 putplane(pp->pln_uid, pp);
626 pr("%s equipped\n", prplane(pp));
631 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
633 struct plchrstr *pcp;
646 if (pp->pln_ship >= 0) {
647 getship(pp->pln_ship, &ship);
648 plp->pstage = ship.shp_pstage;
649 item = ship.shp_item;
651 } else if (pp->pln_land >= 0) {
652 getland(pp->pln_land, &land);
653 plp->pstage = land.lnd_pstage;
654 item = land.lnd_item;
657 getsect(pp->pln_x, pp->pln_y, §);
658 plp->pstage = sect.sct_pstage;
659 item = sect.sct_item;
660 own = sect.sct_oldown;
662 if (pcp->pl_fuel > item[I_PETROL]) {
663 pr("%s not enough petrol there!\n", prplane(pp));
666 item[I_PETROL] -= pcp->pl_fuel;
670 case 's': /* strategic bomb */
671 case 'p': /* pinpoint bomb */
674 case 't': /* transport */
675 if (!(pcp->pl_flags & P_C) || !ip)
681 if ((pcp->pl_flags & P_MINE) == 0)
687 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
690 if (pcp->pl_flags & P_V)
693 case 'a': /* paradrop */
694 if (!(pcp->pl_flags & P_P))
697 if (pcp->pl_flags & P_V)
700 case 'r': /* reconnaissance */
701 case 'e': /* escort */
704 case 'i': /* missile interception */
705 if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
706 || !(pcp->pl_flags & (P_N | P_O))))
716 if (itype != I_NONE) {
717 needed = load / ichr[itype].i_lbs;
719 pr("%s can't contribute to mission\n", prplane(pp));
722 if (nuk_on_plane(pp) >= 0) {
723 if (mission == 's' || mission == 't')
726 pr("%s can't fly this mission"
727 " while it is carrying a nuclear weapon",
732 if (itype == I_CIVIL && pp->pln_own != own) {
733 pr("You don't control those civilians!\n");
737 /* Supply is broken somewhere, so don't use it for now */
738 if (itype == I_SHELL && item[itype] < needed)
739 item[itype] += supply_commod(plp->plane.pln_own,
744 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
747 abandon_needed = !!would_abandon(§, itype, needed, NULL);
748 if (item[itype] < needed + abandon_needed) {
749 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
752 item[itype] -= needed;
756 if (pp->pln_ship >= 0) {
757 if (pp->pln_own != ship.shp_own) {
759 "%s %s prepares for takeoff from ship %s\n",
760 cname(pp->pln_own), prplane(pp), prship(&ship));
762 putship(ship.shp_uid, &ship);
763 } else if (pp->pln_land >= 0) {
764 if (pp->pln_own != land.lnd_own) {
766 "%s %s prepares for takeoff from unit %s\n",
767 cname(pp->pln_own), prplane(pp), prland(&land));
769 putland(land.lnd_uid, &land);
771 if (pp->pln_own != sect.sct_own) {
772 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
773 cname(pp->pln_own), prplane(pp),
774 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
782 pln_put(struct emp_qelem *list)
784 struct emp_qelem *qp, *next;
786 for (qp = list->q_forw; qp != list; qp = next) {
788 pln_put1((struct plist *)qp);
793 pln_put1(struct plist *plp)
801 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
802 && (plchr[pp->pln_type].pl_flags & P_M)
803 && pp->pln_effic >= PLANE_MINEFF))
804 pp->pln_effic = 0; /* bug: missile launched but not used up */
806 if (!(pp->pln_flags & PLN_LAUNCHED))
807 ; /* never took off */
808 else if (pp->pln_effic < PLANE_MINEFF) {
810 } else if (pp->pln_ship >= 0) {
811 /* It is landing on a carrier */
812 getship(pp->pln_ship, &ship);
813 /* We should do more, like make sure it's really
814 a carrier, etc. but for now just make sure it's
816 if (ship.shp_effic < SHIP_MINEFF) {
818 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
819 "splashes into the sea.\n",
820 pp->pln_ship, pp->pln_uid);
824 /* Presume we are landing back in a sector. */
825 getsect(pp->pln_x, pp->pln_y, §);
826 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
828 "Nowhere to land at %s, plane #%d crashes and burns...\n",
829 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
833 pp->pln_flags &= ~PLN_LAUNCHED;
834 putplane(pp->pln_uid, pp);
835 emp_remque(&plp->queue);
840 * Can a carrier of SP's type carry this load of planes?
841 * The load consists of N planes, of which NCH are choppers, NXL
842 * xlight, NMSL light missiles, and the rest are light fixed-wing
846 ship_can_carry(struct shpstr *sp, int n, int nch, int nxl, int nmsl)
848 struct mchrstr *mcp = &mchr[sp->shp_type];
849 int nfw = n - nch - nxl - nmsl;
851 if (nch > mcp->m_nchoppers) /* overflow into fixed-wing slots */
852 nfw += nch - mcp->m_nchoppers;
853 if (nxl > mcp->m_nxlight) /* overflow into missile slots */
854 nmsl += nxl - mcp->m_nxlight;
855 if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
856 return 0; /* missile slots wanted */
857 if (nfw && !(mcp->m_flags & M_FLY))
858 return 0; /* fixed-wing slots wanted */
859 return nfw + nmsl <= mcp->m_nplanes;
863 * Increment carrier plane counters for PP.
864 * If it's a chopper, increment *NCH.
865 * Else, if it's x-light, increment *NXL.
866 * Else, if it's a light missile, increment *MSL.
867 * Return non-zero if it's a chopper, x-light or light.
870 inc_shp_nplane(struct plnstr *pp, int *nch, int *nxl, int *nmsl)
872 struct plchrstr *pcp = &plchr[pp->pln_type];
874 if (pcp->pl_flags & P_K)
876 else if (pcp->pl_flags & P_E)
878 else if (!(pcp->pl_flags & P_L))
880 else if (pcp->pl_flags & P_M)
886 * Can PP be loaded on a ship of SP's type?
889 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
891 int nch = 0, nxl = 0, nmsl = 0;
893 if (!inc_shp_nplane(pp, &nch, &nxl, &nmsl))
895 return ship_can_carry(sp, 1, nch, nxl, nmsl);
899 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
901 int n, nch, nxl, nmsl;
903 if (plane->pln_ship == ship->shp_uid)
904 return 1; /* Already on ship */
906 n = shp_nplane(ship, &nch, &nxl, &nmsl);
907 if (!inc_shp_nplane(plane, &nch, &nxl, &nmsl))
908 return 0; /* not a carrier plane */
909 if (!ship_can_carry(ship, n + 1, nch, nxl, nmsl))
910 return 0; /* no space */
912 plane->pln_x = ship->shp_x;
913 plane->pln_y = ship->shp_y;
914 plane->pln_ship = ship->shp_uid;
915 putplane(plane->pln_uid, plane);
920 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
922 if (plane->pln_land == land->lnd_uid)
923 return 1; /* Already on unit */
924 if (!(plchr[plane->pln_type].pl_flags & P_E))
926 if (lnd_nxlight(land) >= lchr[land->lnd_type].l_nxlight)
929 plane->pln_x = land->lnd_x;
930 plane->pln_y = land->lnd_y;
931 plane->pln_land = land->lnd_uid;
932 putplane(plane->pln_uid, plane);
937 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
940 struct plchrstr *pcp;
941 struct emp_qelem *qp;
942 struct emp_qelem *next;
948 getsect(x, y, §);
949 mines_there = sect.sct_mines;
951 if (mines_there == 0)
954 if (sect.sct_type != SCT_WATER)
957 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
960 ip = (struct plist *)qp;
963 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
966 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
968 xyas(sect.sct_x, sect.sct_y, player->cnum));
974 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
975 writemap(player->cnum);
976 sect.sct_mines = mines_there;
981 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
983 struct plchrstr *pcp = plchr + pp->pln_type;
984 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
985 (pp->pln_tech - pcp->pl_tech / 2);
986 int acc = pln_acc(pp);
989 if (type == EF_SHIP) {
990 if (pcp->pl_flags & P_A)
992 if (!(pcp->pl_flags & P_T))
995 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
996 (1.0 - acc / 100.0)) - hardtarget;
998 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1000 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1001 if (hitchance > 100)
1007 pln_damage(struct plnstr *pp, char type, char *noisy)
1009 struct plchrstr *pcp = plchr + pp->pln_type;
1010 int load, i, hitroll, aim, len;
1016 if (CANT_HAPPEN(nuk_on_plane(pp) >= 0))
1019 load = pln_load(pp);
1020 if (!load) /* e.g. ab, blowing up on launch pad */
1027 if (pcp->pl_flags & P_M) {
1028 if (pcp->pl_flags & P_MAR)
1030 } else if (pcp->pl_flags & P_T)
1035 effective = !pinbomber;
1036 aim = 30 + (pinbomber ? aim : 100 - aim);
1038 effective = pinbomber;
1042 len = snprintf(buf, sizeof(buf), "%s", noisy);
1046 mpr(pp->pln_own, "%s\n", buf);
1051 hitroll = roll(100);
1052 if (hitroll >= 90) {
1055 len += sprintf(buf + len, "BLAM");
1056 } else if (hitroll < aim) {
1059 len += sprintf(buf + len, "Blam");
1063 len += sprintf(buf + len, "blam");
1067 len += sprintf(buf + len, "-");
1071 mpr(pp->pln_own, "%s\n", buf);
1078 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1081 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1082 return (int)(100 - 100 * misschance * misschance);
1086 pln_mobcost(int dist, struct plnstr *pp, char mission)
1090 cost = 20.0 / (pp->pln_effic / 100.0);
1091 if (mission == 'e' || mission == 0)
1092 cost /= 2; /* escort or intercept */
1094 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1098 pln_is_in_orbit(struct plnstr *pp)
1100 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1101 && (pp->pln_flags & PLN_LAUNCHED);
1105 * Set PP's tech to TLEV along with everything else that depends on it.
1108 pln_set_tech(struct plnstr *pp, int tlev)
1110 struct plchrstr *pcp = plchr + pp->pln_type;
1111 int limited_range = pp->pln_range < pln_range_max(pp);
1114 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1115 tlev = pcp->pl_tech;
1116 pp->pln_tech = tlev;
1118 range_max = pln_range_max(pp);
1119 if (!limited_range || pp->pln_range > range_max)
1120 pp->pln_range = range_max;