2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2013, 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
51 #include "prototypes.h"
56 static int ship_can_carry(struct shpstr *, int, int, int, int);
57 static int inc_shp_nplane(struct plnstr *, int *, int *, int *);
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 * Find out whether planes can fly one-way to X,Y.
123 * Offer the player any carriers there. If he chooses one, read it
124 * into TARGET->ship. Else read the target sector into TARGET->sect.
125 * If planes can land there, set required plane flags in *FLAGSP, and
126 * return 0. Else return -1.
129 pln_where_to_land(coord x, coord y,
130 union empobj_storage *target, int *flagsp)
139 nships = carriersatxy(x, y, player->cnum);
142 p = getstring("Carrier #? ", buf);
148 if (!getship(cno, &target->ship)
150 && (relations_with(target->ship.shp_own, player->cnum)
155 if (target->ship.shp_x != x || target->ship.shp_y != y) {
156 pr("Ship #%d not in %s\n", cno, xyas(x, y, player->cnum));
159 fl = carrier_planes(&target->ship, 0);
161 pr("Can't land on %s.\n", prship(&target->ship));
164 /* clear to land on ship#CNO */
165 pr("landing on carrier %d\n", cno);
171 /* try to land at sector */
172 getsect(x, y, &target->sect);
173 if (relations_with(target->sect.sct_own, player->cnum) != ALLIED) {
174 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
177 if (target->sect.sct_type == SCT_MOUNT) {
178 pr("Nowhere to land at sector %s!\n", xyas(x, y, player->cnum));
181 /* clear to land at sector */
182 if (target->sect.sct_type != SCT_AIRPT || target->sect.sct_effic < 60)
188 pln_can_land_on_carrier(struct emp_qelem *bomb_list,
189 struct emp_qelem *esc_list,
193 int n, nch, nxl, nmsl;
194 struct emp_qelem *list, *qp;
197 n = shp_nplane(sp, &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 == sp->shp_uid)
208 if (!inc_shp_nplane(&plp->plane, &nch, &nxl, &nmsl))
212 return ship_can_carry(sp, 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),
240 if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
241 && ship.shp_pstage == PLG_HEALTHY)
242 ship.shp_pstage = PLG_EXPOSED;
245 plp->plane.pln_x = tx;
246 plp->plane.pln_y = ty;
247 getsect(tx, ty, §);
248 if (plp->plane.pln_own != sect.sct_own) {
250 "%s %s lands at your sector %s\n",
252 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
254 if (plp->pcp->pl_crew && plp->pstage == PLG_INFECT
255 && sect.sct_pstage == PLG_HEALTHY)
256 sect.sct_pstage = PLG_EXPOSED;
257 plp->plane.pln_ship = cno;
263 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
266 struct emp_qelem *qp;
278 getsect(tx, ty, §);
280 if (sect.sct_type == SCT_WATER)
281 pr("Your %s sink like a rock!\n", ip->i_name);
283 pr("Your %s vanish without a trace.\n", ip->i_name);
286 if (relations_with(sect.sct_own, player->cnum) != ALLIED) {
287 pr("You don't own %s! Cargo jettisoned...\n",
288 xyas(tx, ty, player->cnum));
291 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
292 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
293 xyas(tx, ty, player->cnum));
296 there = sect.sct_item[ip->i_uid];
298 pstage = sect.sct_pstage;
301 there = ship.shp_item[ip->i_uid];
302 max = mchr[ship.shp_type].m_item[ip->i_uid];
303 pstage = ship.shp_pstage;
307 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
308 plp = (struct plist *)qp;
311 && plp->pstage == PLG_INFECT && pstage == PLG_HEALTHY)
312 pstage = PLG_EXPOSED;
317 pr("%d excess %s discarded\n", there - max, ip->i_name);
321 pr("%d %s landed safely", amt, ip->i_name);
323 sect.sct_item[ip->i_uid] = there;
324 sect.sct_pstage = pstage;
325 if (sect.sct_own != player->cnum)
326 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
327 cname(player->cnum), amt, ip->i_name,
328 xyas(tx, ty, sect.sct_own));
329 pr(" at %s\n", xyas(tx, ty, player->cnum));
332 ship.shp_item[ip->i_uid] = there;
333 ship.shp_pstage = pstage;
334 if (ship.shp_own != player->cnum)
335 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
336 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
337 pr(" on carrier #%d\n", ship.shp_uid);
338 putship(ship.shp_uid, &ship);
343 pln_mine(struct emp_qelem *list, coord tx, coord ty)
345 struct emp_qelem *qp;
351 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
352 plp = (struct plist *)qp;
357 getsect(tx, ty, §);
358 if (sect.sct_type != SCT_WATER) {
359 pr("Your seamines have no effect here.\n");
362 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
363 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
364 if (map_set(player->cnum, tx, ty, 'X', 0))
365 writemap(player->cnum);
371 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
372 * A plane type is capable unless
373 * - it lacks all of the P_B, P_T in WANTFLAGS, or
374 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
375 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
376 * - it lacks any of the other capabilities in WANTFLAGS, or
377 * - it has any of the capabilities in NOWANTFLAGS.
380 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
382 int flags = plchr[(int)pp->pln_type].pl_flags;
384 if (wantflags & (P_B | P_T)) {
385 if ((flags & wantflags & (P_B | P_T)) == 0)
387 wantflags &= ~(P_B | P_T);
390 if (wantflags & (P_F | P_ESC)) {
391 if ((flags & wantflags & (P_F | P_ESC)) == 0)
393 wantflags &= ~(P_F | P_ESC);
396 if (wantflags & (P_E | P_L | P_K)) {
397 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
399 wantflags &= ~(P_E | P_L | P_K);
402 if ((flags & wantflags) != wantflags)
405 if (flags & nowantflags)
412 * Return union of capabilities of planes in LIST.
415 pln_caps(struct emp_qelem *list)
417 struct emp_qelem *qp;
422 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
423 plp = (struct plist *)qp;
424 fl |= plp->pcp->pl_flags;
431 * Find plane types that can operate from carrier SP.
432 * If MSL find missile types, else non-missile types.
433 * Return a combination of P_L, P_K, P_E.
434 * It's zero if SP can't support air operations due to its type or
435 * state (low efficiency).
438 carrier_planes(struct shpstr *sp, int msl)
440 struct mchrstr *mcp = mchr + sp->shp_type;
443 if (sp->shp_effic < SHP_AIROPS_EFF)
447 if (mcp->m_flags & M_FLY)
449 if ((mcp->m_flags & M_MSL) && msl)
451 if (mcp->m_nchoppers && !msl)
459 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
464 struct plchrstr *pcp = plchr + pp->pln_type;
466 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
469 if (pp->pln_ship >= 0) {
470 /* ship: needs to be own or allied, efficient */
471 if (!getship(pp->pln_ship, &ship)) {
475 if (relations_with(ship.shp_own, pp->pln_own) != ALLIED) {
477 pr("(note) An ally does not own the ship %s is on\n",
481 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
484 } else if (pp->pln_land >= 0) {
485 /* land: needs to be own or allied, efficient, not embarked */
486 if (!getland(pp->pln_land, &land)) {
490 if (relations_with(land.lnd_own, pp->pln_own) != ALLIED) {
492 pr("(note) An ally does not own the unit %s is on\n",
496 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
498 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
502 /* sector: needs to be own or allied, efficient airfield */
503 if (!getsect(pp->pln_x, pp->pln_y, §)) {
508 if (relations_with(sect.sct_own, pp->pln_own) != ALLIED) {
510 pr("(note) An ally does not own the sector %s is in\n",
514 /* need airfield unless VTOL */
515 if ((pcp->pl_flags & P_V) == 0) {
516 if (sect.sct_type != SCT_AIRPT) {
518 pr("%s not at airport\n", prplane(pp));
521 if (sect.sct_effic < 40) {
523 pr("%s is not 40%% efficient, %s can't take off from there.\n",
524 xyas(sect.sct_x, sect.sct_y, player->cnum),
528 if (!oneway && sect.sct_effic < 60) {
530 pr("%s is not 60%% efficient, %s can't land there.\n",
531 xyas(sect.sct_x, sect.sct_y, player->cnum),
542 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
543 int ap_to_target, int rangemult, int wantflags, int nowantflags)
547 struct plchrstr *pcp;
551 while (nxtitem(ni, &plane)) {
553 * It would be nice to let deities fly foreign planes, but
554 * much of the code assumes that only the plane's owner can
557 if (!plane.pln_own || plane.pln_own != player->cnum)
559 if (plane.pln_mobil <= 0)
561 if (plane.pln_effic < 40) {
562 pr("%s not efficient enough (must be 40%%)\n",
566 if (!pln_capable(&plane, wantflags, nowantflags))
569 if (ontradingblock(EF_PLANE, &plane)) {
570 pr("plane #%d inelligible - it's for sale.\n",
576 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
578 pr("%s too far from assembly point\n", prplane(&plane));
581 range += ap_to_target;
583 pcp = &plchr[(int)plane.pln_type];
584 if (plane.pln_range < range) {
585 pr("%s out of range (%d:%d)\n",
586 prplane(&plane), plane.pln_range, range);
589 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
591 pr("%s standing by\n", prplane(&plane));
592 plane.pln_mission = 0;
593 putplane(plane.pln_uid, &plane);
594 plp = malloc(sizeof(struct plist));
596 plp->pstage = PLG_HEALTHY;
599 emp_insque(&plp->queue, list);
604 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip)
606 struct emp_qelem *qp;
607 struct emp_qelem *next;
611 for (qp = list->q_forw; qp != list; qp = next) {
613 plp = (struct plist *)qp;
615 getplane(pp->pln_uid, pp);
616 if ((pp->pln_flags & PLN_LAUNCHED)
617 || pln_equip(plp, ip, mission) < 0) {
622 pp->pln_flags |= PLN_LAUNCHED;
623 pp->pln_mobil -= pln_mobcost(dist, pp, mission);
624 putplane(pp->pln_uid, pp);
625 pr("%s equipped\n", prplane(pp));
630 pln_equip(struct plist *plp, struct ichrstr *ip, char mission)
632 struct plchrstr *pcp;
645 if (pp->pln_ship >= 0) {
646 getship(pp->pln_ship, &ship);
647 plp->pstage = ship.shp_pstage;
648 item = ship.shp_item;
650 } else if (pp->pln_land >= 0) {
651 getland(pp->pln_land, &land);
652 plp->pstage = land.lnd_pstage;
653 item = land.lnd_item;
656 getsect(pp->pln_x, pp->pln_y, §);
657 plp->pstage = sect.sct_pstage;
658 item = sect.sct_item;
659 own = sect.sct_oldown;
661 if (pcp->pl_fuel > item[I_PETROL]) {
662 pr("%s not enough petrol there!\n", prplane(pp));
665 item[I_PETROL] -= pcp->pl_fuel;
669 case 's': /* strategic bomb */
670 case 'p': /* pinpoint bomb */
673 case 't': /* transport */
674 if (!(pcp->pl_flags & P_C) || !ip)
680 if ((pcp->pl_flags & P_MINE) == 0)
686 if (!(pcp->pl_flags & P_C) || CANT_HAPPEN(!ip))
689 if (pcp->pl_flags & P_V)
692 case 'a': /* paradrop */
693 if (!(pcp->pl_flags & P_P))
696 if (pcp->pl_flags & P_V)
699 case 'r': /* reconnaissance */
700 case 'e': /* escort */
703 case 'i': /* missile interception */
704 if (CANT_HAPPEN(!(pcp->pl_flags & P_M)
705 || !(pcp->pl_flags & (P_N | P_O))))
715 if (itype != I_NONE) {
716 needed = load / ichr[itype].i_lbs;
718 pr("%s can't contribute to mission\n", prplane(pp));
721 if (nuk_on_plane(pp) >= 0) {
722 if (mission == 's' || mission == 't')
725 pr("%s can't fly this mission"
726 " while it is carrying a nuclear weapon",
731 if (itype == I_CIVIL && pp->pln_own != own) {
732 pr("You don't control those civilians!\n");
736 /* Supply is broken somewhere, so don't use it for now */
737 if (itype == I_SHELL && item[itype] < needed)
738 item[itype] += supply_commod(plp->plane.pln_own,
743 if (pp->pln_ship >= 0 || pp->pln_land >= 0)
746 abandon_needed = !!would_abandon(§, itype, needed, NULL);
747 if (item[itype] < needed + abandon_needed) {
748 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
751 item[itype] -= needed;
755 if (pp->pln_ship >= 0) {
756 if (pp->pln_own != ship.shp_own) {
758 "%s %s prepares for takeoff from ship %s\n",
759 cname(pp->pln_own), prplane(pp), prship(&ship));
761 putship(ship.shp_uid, &ship);
762 } else if (pp->pln_land >= 0) {
763 if (pp->pln_own != land.lnd_own) {
765 "%s %s prepares for takeoff from unit %s\n",
766 cname(pp->pln_own), prplane(pp), prland(&land));
768 putland(land.lnd_uid, &land);
770 if (pp->pln_own != sect.sct_own) {
771 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
772 cname(pp->pln_own), prplane(pp),
773 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
781 pln_put(struct emp_qelem *list)
783 struct emp_qelem *qp, *next;
785 for (qp = list->q_forw; qp != list; qp = next) {
787 pln_put1((struct plist *)qp);
792 pln_put1(struct plist *plp)
800 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
801 && (plchr[pp->pln_type].pl_flags & P_M)
802 && pp->pln_effic >= PLANE_MINEFF))
803 pp->pln_effic = 0; /* bug: missile launched but not used up */
805 if (!(pp->pln_flags & PLN_LAUNCHED))
806 ; /* never took off */
807 else if (pp->pln_effic < PLANE_MINEFF) {
809 } else if (pp->pln_ship >= 0) {
810 /* It is landing on a carrier */
811 getship(pp->pln_ship, &ship);
812 /* We should do more, like make sure it's really
813 a carrier, etc. but for now just make sure it's
815 if (ship.shp_effic < SHIP_MINEFF) {
817 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
818 "splashes into the sea.\n",
819 pp->pln_ship, pp->pln_uid);
823 /* Presume we are landing back in a sector. */
824 getsect(pp->pln_x, pp->pln_y, §);
825 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
827 "Nowhere to land at %s, plane #%d crashes and burns...\n",
828 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
832 pp->pln_flags &= ~PLN_LAUNCHED;
833 putplane(pp->pln_uid, pp);
834 emp_remque(&plp->queue);
839 * Can a carrier of SP's type carry this load of planes?
840 * The load consists of N planes, of which NCH are choppers, NXL
841 * xlight, NMSL light missiles, and the rest are light fixed-wing
845 ship_can_carry(struct shpstr *sp, int n, int nch, int nxl, int nmsl)
847 struct mchrstr *mcp = &mchr[sp->shp_type];
848 int nfw = n - nch - nxl - nmsl;
850 if (nch > mcp->m_nchoppers) /* overflow into fixed-wing slots */
851 nfw += nch - mcp->m_nchoppers;
852 if (nxl > mcp->m_nxlight) /* overflow into missile slots */
853 nmsl += nxl - mcp->m_nxlight;
854 if (nmsl && !(mcp->m_flags & (M_MSL | M_FLY)))
855 return 0; /* missile slots wanted */
856 if (nfw && !(mcp->m_flags & M_FLY))
857 return 0; /* fixed-wing slots wanted */
858 return nfw + nmsl <= mcp->m_nplanes;
862 * Increment carrier plane counters for PP.
863 * If it's a chopper, increment *NCH.
864 * Else, if it's x-light, increment *NXL.
865 * Else, if it's a light missile, increment *MSL.
866 * Return non-zero if it's a chopper, x-light or light.
869 inc_shp_nplane(struct plnstr *pp, int *nch, int *nxl, int *nmsl)
871 struct plchrstr *pcp = &plchr[pp->pln_type];
873 if (pcp->pl_flags & P_K)
875 else if (pcp->pl_flags & P_E)
877 else if (!(pcp->pl_flags & P_L))
879 else if (pcp->pl_flags & P_M)
885 * Can PP be loaded on a ship of SP's type?
888 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
890 int nch = 0, nxl = 0, nmsl = 0;
892 if (!inc_shp_nplane(pp, &nch, &nxl, &nmsl))
894 return ship_can_carry(sp, 1, nch, nxl, nmsl);
898 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
900 int n, nch, nxl, nmsl;
902 if (plane->pln_ship == ship->shp_uid)
903 return 1; /* Already on ship */
905 n = shp_nplane(ship, &nch, &nxl, &nmsl);
906 if (!inc_shp_nplane(plane, &nch, &nxl, &nmsl))
907 return 0; /* not a carrier plane */
908 if (!ship_can_carry(ship, n + 1, nch, nxl, nmsl))
909 return 0; /* no space */
911 plane->pln_x = ship->shp_x;
912 plane->pln_y = ship->shp_y;
913 plane->pln_ship = ship->shp_uid;
914 putplane(plane->pln_uid, plane);
919 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
921 if (plane->pln_land == land->lnd_uid)
922 return 1; /* Already on unit */
923 if (!(plchr[plane->pln_type].pl_flags & P_E))
925 if (lnd_nxlight(land) >= lchr[land->lnd_type].l_nxlight)
928 plane->pln_x = land->lnd_x;
929 plane->pln_y = land->lnd_y;
930 plane->pln_land = land->lnd_uid;
931 putplane(plane->pln_uid, plane);
936 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
939 struct plchrstr *pcp;
940 struct emp_qelem *qp;
941 struct emp_qelem *next;
947 getsect(x, y, §);
948 mines_there = sect.sct_mines;
950 if (mines_there == 0)
953 if (sect.sct_type != SCT_WATER)
956 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
959 ip = (struct plist *)qp;
962 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
965 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
967 xyas(sect.sct_x, sect.sct_y, player->cnum));
973 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
974 writemap(player->cnum);
975 sect.sct_mines = mines_there;
980 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
982 struct plchrstr *pcp = plchr + pp->pln_type;
983 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
984 (pp->pln_tech - pcp->pl_tech / 2);
985 int acc = pln_acc(pp);
988 if (type == EF_SHIP) {
989 if (pcp->pl_flags & P_A)
991 if (!(pcp->pl_flags & P_T))
994 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
995 (1.0 - acc / 100.0)) - hardtarget;
997 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
999 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1000 if (hitchance > 100)
1006 pln_damage(struct plnstr *pp, char type, int noisy)
1008 struct plchrstr *pcp = plchr + pp->pln_type;
1009 int load, i, hitroll, aim, len;
1015 if (CANT_HAPPEN(nuk_on_plane(pp) >= 0))
1018 load = pln_load(pp);
1019 if (!load) /* e.g. ab, blowing up on launch pad */
1026 if (pcp->pl_flags & P_M) {
1027 if (pcp->pl_flags & P_MAR)
1029 } else if (pcp->pl_flags & P_T)
1034 effective = !pinbomber;
1035 aim = 30 + (pinbomber ? aim : 100 - aim);
1037 effective = pinbomber;
1044 hitroll = roll(100);
1045 if (hitroll >= 90) {
1048 len += sprintf(buf + len, "BLAM");
1049 } else if (hitroll < aim) {
1052 len += sprintf(buf + len, "Blam");
1056 len += sprintf(buf + len, "blam");
1060 mpr(pp->pln_own, "%s\n", buf);
1064 len += sprintf(buf + len, "-");
1068 mpr(pp->pln_own, "%s\n", buf);
1075 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1078 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1079 return (int)(100 - 100 * misschance * misschance);
1083 pln_mobcost(int dist, struct plnstr *pp, char mission)
1087 cost = 20.0 / (pp->pln_effic / 100.0);
1088 if (mission == 'e' || mission == 0)
1089 cost /= 2; /* escort or intercept */
1091 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1095 pln_is_in_orbit(struct plnstr *pp)
1097 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1098 && (pp->pln_flags & PLN_LAUNCHED);
1102 * Set PP's tech to TLEV along with everything else that depends on it.
1105 pln_set_tech(struct plnstr *pp, int tlev)
1107 struct plchrstr *pcp = plchr + pp->pln_type;
1108 int limited_range = pp->pln_range < pln_range_max(pp);
1111 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1112 tlev = pcp->pl_tech;
1113 pp->pln_tech = tlev;
1115 range_max = pln_range_max(pp);
1116 if (!limited_range || pp->pln_range > range_max)
1117 pp->pln_range = range_max;