2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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-2008
52 #include "prototypes.h"
57 static int pln_equip(struct plist *, struct ichrstr *, int, char);
58 static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
61 * Get assembly point argument.
62 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
63 * If this yields a valid assembly point, read it into *AP_SECT and
65 * Else complain and return NULL.
66 * *AP_SECT and BUF[1024] may be modified in either case.
69 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
76 p = getstarg(input, "assembly point? ", buf);
79 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
82 /* over own or allied sector is fine */
83 if (ap_sect->sct_own == player->cnum
84 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
87 /* over own or allied ship is fine */
88 snxtitem_xy(&ni, EF_SHIP, x, y);
89 while (nxtitem(&ni, &ship)) {
90 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
92 if (ship.shp_own == player->cnum
93 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
97 pr("Assembly point not owned by you or an ally!\n");
102 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
114 nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
117 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
121 || !getship(cno, &ship)
123 && (getrel(getnatp(ship.shp_own), player->cnum)
128 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
129 pr("Ship #%d not in %s\n", cno,
130 xyas(target->sct_x, target->sct_y, player->cnum));
133 fl = carrier_planes(&ship, 0);
135 pr("Can't land on %s.\n", prship(&ship));
138 /* clear to land on ship#CNO */
139 pr("landing on carrier %d\n", cno);
147 /* try to land at sector */
148 if (target->sct_own != player->cnum
149 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
150 pr("Nowhere to land at sector %s!\n",
151 xyas(target->sct_x, target->sct_y, player->cnum));
154 if (target->sct_type == SCT_MOUNT) {
155 pr("Nowhere to land at sector %s!\n",
156 xyas(target->sct_x, target->sct_y, player->cnum));
159 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
162 /* clear to land at sector */
169 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
170 struct emp_qelem *esc_list, int cno)
172 struct emp_qelem *list, *qp;
176 if (cno < 0 || !getship(cno, &ship))
182 for (list = bomb_list;
184 list = list == bomb_list ? esc_list : NULL) {
185 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
186 plp = (struct plist *)qp;
187 if (plp->plane.pln_ship == ship.shp_uid)
189 if (!fit_plane_on_ship(&plp->plane, &ship))
197 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
199 struct emp_qelem *qp;
206 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
207 plp = (struct plist *)qp;
210 if (!could_be_on_ship(&plp->plane, &ship))
211 pr("\t%s cannot land on ship #%d! %s aborts!\n",
212 prplane(&plp->plane), cno, prplane(&plp->plane));
213 else if (!put_plane_on_ship(&plp->plane, &ship))
214 pr("\tNo room on ship #%d! %s aborts!\n",
215 cno, prplane(&plp->plane));
217 if (plp->plane.pln_own != ship.shp_own) {
218 wu(0, ship.shp_own, "%s %s lands on your %s\n",
219 cname(player->cnum), prplane(&plp->plane),
224 plp->plane.pln_x = tx;
225 plp->plane.pln_y = ty;
226 getsect(tx, ty, §);
227 if (plp->plane.pln_own != sect.sct_own) {
229 "%s %s lands at your sector %s\n",
231 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
233 plp->plane.pln_ship = cno;
237 putship(ship.shp_uid, &ship);
241 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
244 struct emp_qelem *qp;
247 struct sctstr *sectp;
256 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
257 plp = (struct plist *)qp;
260 if (type == EF_SECTOR) {
262 if (!sectp->sct_own) {
263 if (sectp->sct_type == SCT_WATER)
264 pr("Your %s sink like a rock!\n", ip->i_name);
266 pr("Your %s vanish without a trace.\n", ip->i_name);
269 if (sectp->sct_own != player->cnum
270 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
271 pr("You don't own %s! Cargo jettisoned...\n",
272 xyas(tx, ty, player->cnum));
275 if (ip->i_uid == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
276 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
277 xyas(tx, ty, player->cnum));
280 there = sectp->sct_item[ip->i_uid];
284 there = sp->shp_item[ip->i_uid];
285 mp = &mchr[(int)sp->shp_type];
286 max = mp->m_item[ip->i_uid];
290 pr("%d excess %s discarded\n", max - there, ip->i_name);
294 pr("%d %s landed safely", amt, ip->i_name);
295 if (type == EF_SECTOR) {
297 sectp->sct_item[ip->i_uid] = there;
298 if (sectp->sct_own != player->cnum)
299 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
300 cname(player->cnum), amt, ip->i_name,
301 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
302 pr(" at %s\n", xyas(tx, ty, player->cnum));
303 putsect((struct sctstr *)ptr);
305 struct shpstr *sp = (struct shpstr *)ptr;
306 sp->shp_item[ip->i_uid] = there;
307 if (sp->shp_own != player->cnum)
308 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
309 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
310 pr(" on carrier #%d\n", sp->shp_uid);
311 putship(sp->shp_uid, sp);
316 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
318 struct emp_qelem *qp;
323 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
324 plp = (struct plist *)qp;
329 if (sectp->sct_type != SCT_WATER) {
330 pr("Your seamines have no effect here.\n");
333 sectp->sct_mines = MIN(sectp->sct_mines + amt, MINES_MAX);
334 pr("%d mines laid in %s.\n", amt,
335 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
336 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
337 writemap(player->cnum);
343 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
344 * A plane type is capable unless
345 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
346 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
347 * - it lacks any of the other capabilities in WANTFLAGS, or
348 * - it has any of the capabilities in NOWANTFLAGS.
351 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
353 int flags = plchr[(int)pp->pln_type].pl_flags;
355 if (wantflags & (P_F | P_ESC)) {
356 if ((flags & wantflags & (P_F | P_ESC)) == 0)
358 wantflags &= ~(P_F | P_ESC);
361 if (wantflags & (P_E | P_L | P_K)) {
362 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
364 wantflags &= ~(P_E | P_L | P_K);
367 if ((flags & wantflags) != wantflags)
370 if (flags & nowantflags)
377 * Find plane types that can operate from carrier SP.
378 * If MSL find missile types, else non-missile types.
379 * Return a combination of P_L, P_K, P_E.
380 * It's zero if SP can't support air operations due to its type or
381 * state (low efficiency).
384 carrier_planes(struct shpstr *sp, int msl)
386 struct mchrstr *mcp = mchr + sp->shp_type;
389 if (sp->shp_effic < SHP_AIROPS_EFF)
393 if (mcp->m_flags & M_FLY)
395 if ((mcp->m_flags & M_MSL) && msl)
397 if (mcp->m_nchoppers && !msl)
405 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
410 struct plchrstr *pcp = plchr + pp->pln_type;
412 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
415 if (pp->pln_ship >= 0) {
416 /* ship: needs to be own or allied, efficient */
417 if (!getship(pp->pln_ship, &ship)) {
421 if (ship.shp_own != pp->pln_own
422 && getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED) {
424 pr("(note) An ally does not own the ship %s is on\n",
428 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
431 } else if (pp->pln_land >= 0) {
432 /* land: needs to be own or allied, efficient, not embarked */
433 if (!getland(pp->pln_land, &land)) {
437 if (land.lnd_own != pp->pln_own
438 && getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED) {
440 pr("(note) An ally does not own the unit %s is on\n",
444 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
446 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
450 /* sector: needs to be own or allied, efficient airfield */
451 if (!getsect(pp->pln_x, pp->pln_y, §)) {
456 if (sect.sct_own != pp->pln_own
457 && getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED) {
459 pr("(note) An ally does not own the sector %s is in\n",
463 /* need airfield unless VTOL */
464 if ((pcp->pl_flags & P_V) == 0) {
465 if (sect.sct_type != SCT_AIRPT) {
467 pr("%s not at airport\n", prplane(pp));
470 if (sect.sct_effic < 40) {
472 pr("%s is not 40%% efficient, %s can't take off from there.\n",
473 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
477 if (!oneway && sect.sct_effic < 60) {
479 pr("%s is not 60%% efficient, %s can't land there.\n",
480 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
491 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
492 int ap_to_target, int rangemult, int wantflags, int nowantflags)
496 struct plchrstr *pcp;
500 while (nxtitem(ni, &plane)) {
503 if (plane.pln_mobil <= 0)
505 if (plane.pln_effic < 40) {
506 pr("%s not efficient enough (must be 40%%)\n",
510 if (!pln_capable(&plane, wantflags, nowantflags))
513 if (ontradingblock(EF_PLANE, &plane)) {
514 pr("plane #%d inelligible - it's for sale.\n",
520 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
522 pr("%s too far from assembly point\n", prplane(&plane));
525 range += ap_to_target;
527 pcp = &plchr[(int)plane.pln_type];
528 if (plane.pln_range < range) {
529 pr("%s out of range (%d:%d)\n",
530 prplane(&plane), plane.pln_range, range);
533 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
535 pr("%s standing by\n", prplane(&plane));
536 plane.pln_mission = 0;
537 putplane(plane.pln_uid, &plane);
538 plp = malloc(sizeof(struct plist));
543 emp_insque(&plp->queue, list);
548 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip,
549 int flags, int mission_flags)
551 struct emp_qelem *qp;
552 struct emp_qelem *next;
556 for (qp = list->q_forw; qp != list; qp = next) {
558 plp = (struct plist *)qp;
560 getplane(pp->pln_uid, pp);
561 if ((pp->pln_flags & PLN_LAUNCHED)
562 || pln_equip(plp, ip, flags, mission) < 0) {
567 if (flags & (P_S | P_I)) {
568 if (plp->pcp->pl_flags & P_S)
569 mission_flags |= P_S;
570 if (plp->pcp->pl_flags & P_I)
571 mission_flags |= P_I;
573 if (!(plp->pcp->pl_flags & P_H))
574 /* no stealth on this mission */
575 mission_flags &= ~P_H;
576 if (!(plp->pcp->pl_flags & P_X))
577 /* no stealth on this mission */
578 mission_flags &= ~P_X;
579 if (!(plp->pcp->pl_flags & P_A)) {
580 /* no asw on this mission */
581 mission_flags &= ~P_A;
582 /* FIXME escorts turn ASW patrol into ordinary recon */
584 if (!(plp->pcp->pl_flags & P_MINE)) {
585 /* no asw on this mission */
586 mission_flags &= ~P_MINE;
587 /* FIXME no effect */
589 pp->pln_flags |= PLN_LAUNCHED;
590 pp->pln_mobil -= pln_mobcost(dist, pp, flags);
591 putplane(pp->pln_uid, pp);
592 pr("%s equipped\n", prplane(pp));
594 return mission_flags;
598 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
600 struct plchrstr *pcp;
613 if (pp->pln_ship >= 0) {
614 getship(pp->pln_ship, &ship);
615 item = ship.shp_item;
617 } else if (pp->pln_land >= 0) {
618 getland(pp->pln_land, &land);
619 item = land.lnd_item;
622 getsect(pp->pln_x, pp->pln_y, §);
623 item = sect.sct_item;
624 own = sect.sct_oldown;
627 if (ip->i_uid == I_CIVIL) {
628 if (pp->pln_own != own) {
629 pr("You don't control those civilians!\n");
634 if (pcp->pl_fuel > item[I_PETROL]) {
635 pr("%s not enough petrol there!\n", prplane(pp));
638 item[I_PETROL] -= pcp->pl_fuel;
639 if ((flags & P_F) == 0) {
644 case 's': /* strategic bomb */
645 case 'p': /* pinpoint bomb */
646 if (pp->pln_nuketype == -1) {
651 case 't': /* transport */
653 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
656 needed = (load * 2) / ip->i_lbs;
659 if ((pcp->pl_flags & P_MINE) == 0)
662 needed = (load * 2) / ip->i_lbs;
664 case 'a': /* paradrop */
665 if ((pcp->pl_flags & (P_V | P_C)) == 0)
668 needed = load / ip->i_lbs;
670 case 'r': /* reconnaissance */
675 if (itype != I_NONE && needed <= 0) {
676 pr("%s can't contribute to mission\n", prplane(pp));
679 if (itype != I_NONE) {
681 /* Supply is broken somewhere, so don't use it for now */
682 if (itype == I_SHELL && item[itype] < needed)
683 item[itype] += supply_commod(plp->plane.pln_own,
688 abandon_needed = !!would_abandon(§, itype, needed, NULL);
689 if (item[itype] < needed + abandon_needed) {
690 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
693 item[itype] -= needed;
695 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
700 if (pp->pln_ship >= 0) {
701 if (pp->pln_own != ship.shp_own) {
703 "%s %s prepares for takeoff from ship %s\n",
704 cname(pp->pln_own), prplane(pp), prship(&ship));
706 putship(ship.shp_uid, &ship);
707 } else if (pp->pln_land >= 0) {
708 if (pp->pln_own != land.lnd_own) {
710 "%s %s prepares for takeoff from unit %s\n",
711 cname(pp->pln_own), prplane(pp), prland(&land));
713 putland(land.lnd_uid, &land);
715 if (pp->pln_own != sect.sct_own) {
716 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
717 cname(pp->pln_own), prplane(pp),
718 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
726 pln_put(struct emp_qelem *list)
728 struct emp_qelem *qp, *next;
730 for (qp = list->q_forw; qp != list; qp = next) {
732 pln_put1((struct plist *)qp);
737 pln_put1(struct plist *plp)
746 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
747 && (plchr[pp->pln_type].pl_flags & P_M)
748 && pp->pln_effic >= PLANE_MINEFF))
749 pp->pln_effic = 0; /* bug: missile launched but not used up */
751 if (!(pp->pln_flags & PLN_LAUNCHED))
752 ; /* never took off */
753 else if (pp->pln_effic < PLANE_MINEFF) {
755 if (pp->pln_ship >= 0) {
756 getship(pp->pln_ship, &ship);
757 take_plane_off_ship(pp, &ship);
759 if (pp->pln_land >= 0) {
760 getland(pp->pln_land, &land);
761 take_plane_off_land(pp, &land);
763 } else if (pp->pln_ship >= 0) {
764 /* It is landing on a carrier */
765 getship(pp->pln_ship, &ship);
766 /* We should do more, like make sure it's really
767 a carrier, etc. but for now just make sure it's
769 if (ship.shp_effic < SHIP_MINEFF) {
771 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
772 "splashes into the sea.\n",
773 pp->pln_ship, pp->pln_uid);
777 /* Presume we are landing back in a sector. */
778 getsect(pp->pln_x, pp->pln_y, §);
779 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
781 "Nowhere to land at %s, plane #%d crashes and burns...\n",
782 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
786 pp->pln_flags &= ~PLN_LAUNCHED;
787 putplane(pp->pln_uid, pp);
788 emp_remque(&plp->queue);
793 * Fit a plane of PP's type on ship SP.
794 * Adjust SP's plane counters.
795 * Updating the plane accordingly is the caller's job.
796 * Return whether it fits.
799 fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
801 struct plchrstr *pcp = plchr + pp->pln_type;
802 struct mchrstr *mcp = mchr + sp->shp_type;
805 if (pcp->pl_flags & P_K) {
806 /* chopper, try chopper slot first */
807 if (sp->shp_nchoppers < mcp->m_nchoppers)
808 return ++sp->shp_nchoppers;
809 /* else try plane slot */
811 } else if (pcp->pl_flags & P_E) {
812 /* x-light, try x-light slot first */
813 if (sp->shp_nxlight < mcp->m_nxlight)
814 return ++sp->shp_nxlight;
815 /* else try plane slot */
816 wanted = M_MSL | M_FLY;
817 } else if (!(pcp->pl_flags & P_L)) {
818 /* not light, no go */
820 } else if (pcp->pl_flags & P_M) {
821 /* missile, use plane slot */
822 wanted = M_MSL | M_FLY;
824 /* fixed-wing plane, use plane slot */
828 if ((mcp->m_flags & wanted) == 0)
829 return 0; /* ship not capable */
831 if (sp->shp_nplane < mcp->m_nplanes)
832 return ++sp->shp_nplane;
838 * Fit a plane of PP's type off ship SP.
839 * Adjust SP's plane counters, badly. You need to run count_planes()
840 * before the next fit_plane_on_ship().
841 * Updating the plane accordingly is the caller's job.
844 fit_plane_off_ship(struct plnstr *pp, struct shpstr *sp)
847 * Frees chopper and nxlight slots first, which is why we need to
848 * run count_planes() before fit_plane_on_ship().
850 struct plchrstr *pcp = plchr + pp->pln_type;
852 if (pcp->pl_flags & P_K) {
853 if (sp->shp_nchoppers) {
857 } else if (pcp->pl_flags & P_E) {
858 if (sp->shp_nxlight) {
864 if (CANT_HAPPEN(sp->shp_nplane == 0))
870 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
872 if (plane->pln_ship == ship->shp_uid)
873 return 1; /* Already on ship */
875 if (!fit_plane_on_ship(plane, ship))
878 plane->pln_x = ship->shp_x;
879 plane->pln_y = ship->shp_y;
880 plane->pln_ship = ship->shp_uid;
881 putplane(plane->pln_uid, plane);
882 putship(ship->shp_uid, ship);
887 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
889 if (CANT_HAPPEN(plane->pln_ship != ship->shp_uid))
892 fit_plane_off_ship(plane, ship);
893 plane->pln_ship = -1;
894 putship(ship->shp_uid, ship);
895 putplane(plane->pln_uid, plane);
899 * Fit a plane of PP's type on land unit LP.
900 * Adjust LP's plane counters.
901 * Updating the plane accordingly is the caller's job.
902 * Return whether it fits.
905 fit_plane_on_land(struct plnstr *pp, struct lndstr *lp)
907 struct plchrstr *pcp = plchr + pp->pln_type;
908 struct lchrstr *lcp = lchr + lp->lnd_type;
910 if ((pcp->pl_flags & P_E) && lp->lnd_nxlight < lcp->l_nxlight)
911 return ++lp->lnd_nxlight;
917 * Fit a plane of PP's type off land unit LP.
918 * Adjust LP's plane counters.
919 * Updating the plane accordingly is the caller's job.
922 fit_plane_off_land(struct plnstr *pp, struct lndstr *lp)
924 if (CANT_HAPPEN(lp->lnd_nxlight == 0))
930 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
932 if (plane->pln_land == land->lnd_uid)
933 return 1; /* Already on unit */
935 if (!fit_plane_on_land(plane, land))
938 plane->pln_x = land->lnd_x;
939 plane->pln_y = land->lnd_y;
940 plane->pln_land = land->lnd_uid;
941 putplane(plane->pln_uid, plane);
942 putland(land->lnd_uid, land);
947 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
949 if (CANT_HAPPEN(plane->pln_land != land->lnd_uid))
952 fit_plane_off_land(plane, land);
953 plane->pln_land = -1;
954 putland(land->lnd_uid, land);
955 putplane(plane->pln_uid, plane);
959 * Could a plane of PP's type be on on ship SP?
962 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
967 ship.shp_nplane = ship.shp_nchoppers = ship.shp_nxlight = 0;
968 return fit_plane_on_ship(pp, &ship);
972 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
975 struct plchrstr *pcp;
976 struct emp_qelem *qp;
977 struct emp_qelem *next;
983 getsect(x, y, §);
984 mines_there = sect.sct_mines;
986 if (mines_there == 0)
989 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
992 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
995 ip = (struct plist *)qp;
998 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
1001 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
1002 pr("Sweep! in %s\n",
1003 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1009 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1010 writemap(player->cnum);
1011 sect.sct_mines = mines_there;
1016 count_planes(struct shpstr *sp)
1018 struct nstr_item ni;
1019 struct plnstr plane;
1020 int nplane, nchoppers, nxlight;
1022 if (sp->shp_effic < SHIP_MINEFF)
1025 nplane = sp->shp_nplane;
1027 nchoppers = sp->shp_nchoppers;
1028 sp->shp_nchoppers = 0;
1029 nxlight = sp->shp_nxlight;
1030 sp->shp_nxlight = 0;
1032 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1033 while (nxtitem(&ni, &plane)) {
1034 if (plane.pln_own == 0)
1036 if (plane.pln_ship == sp->shp_uid) {
1037 if (!fit_plane_on_ship(&plane, sp))
1042 if (nplane != sp->shp_nplane ||
1043 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1044 putship(sp->shp_uid, sp);
1049 count_land_planes(struct lndstr *lp)
1051 struct nstr_item ni;
1052 struct plnstr plane;
1055 if (lp->lnd_effic < LAND_MINEFF)
1058 nplane = lp->lnd_nxlight;
1059 lp->lnd_nxlight = 0;
1061 snxtitem_all(&ni, EF_PLANE);
1062 while (nxtitem(&ni, &plane)) {
1063 if (plane.pln_own == 0)
1065 if (plane.pln_land == lp->lnd_uid)
1066 if (!fit_plane_on_land(&plane, lp))
1070 if (lp->lnd_nxlight != nplane)
1071 putland(lp->lnd_uid, lp);
1075 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1077 struct plchrstr *pcp = plchr + pp->pln_type;
1078 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
1079 (pp->pln_tech - pcp->pl_tech / 2);
1080 int acc = pln_acc(pp);
1083 if (type == EF_SHIP) {
1084 if (pcp->pl_flags & P_A)
1086 if (!(pcp->pl_flags & P_T))
1089 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1090 (1.0 - acc / 100.0)) - hardtarget;
1092 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1094 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1095 if (hitchance > 100)
1100 /* return 0 if there was a nuclear detonation */
1103 pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
1107 struct plchrstr *pcp = plchr + pp->pln_type;
1115 if (pp->pln_nuketype != -1) {
1116 if (nuk_on_plane(&nuke, pp->pln_uid) >= 0) {
1117 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1118 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1119 pp->pln_nuketype = -1;
1120 *nukedamp = detonate(&nuke, x, y,
1121 pp->pln_flags & PLN_AIRBURST);
1128 load = pln_load(pp);
1129 if (!load) /* e.g. ab, blowing up on launch pad */
1136 if (pcp->pl_flags & P_M) {
1137 if (pcp->pl_flags & P_MAR)
1139 } else if (pcp->pl_flags & P_T)
1144 effective = !pinbomber;
1145 aim = 30 + (pinbomber ? aim : 100 - aim);
1147 effective = pinbomber;
1153 hitroll = roll(100);
1154 if (hitroll >= 90) {
1157 mpr(pp->pln_own, "BLAM");
1158 } else if (hitroll < aim) {
1161 mpr(pp->pln_own, "Blam");
1165 mpr(pp->pln_own, "blam");
1168 mpr(pp->pln_own, "-");
1171 mpr(pp->pln_own, "\n");
1178 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1181 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1182 return (int)(100 - 100 * misschance * misschance);
1186 pln_mobcost(int dist, struct plnstr *pp, int flags)
1190 cost = 20.0 / (pp->pln_effic / 100.0);
1191 if ((flags & P_F) || (flags & P_ESC))
1194 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1198 pln_is_in_orbit(struct plnstr *pp)
1200 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1201 && (pp->pln_flags & PLN_LAUNCHED);
1205 * Set PP's tech to TLEV along with everything else that depends on it.
1208 pln_set_tech(struct plnstr *pp, int tlev)
1210 struct plchrstr *pcp = plchr + pp->pln_type;
1211 int limited_range = pp->pln_range < pln_range_max(pp);
1214 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1215 tlev = pcp->pl_tech;
1216 pp->pln_tech = tlev;
1218 range_max = pln_range_max(pp);
1219 if (!limited_range || pp->pln_range > range_max)
1220 pp->pln_range = range_max;