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 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)
75 if (!snxtitem(ni_bomb, EF_PLANE, input_bomb))
77 if (!snxtitem(ni_esc, EF_PLANE,
78 getstarg(input_esc, "escort(s)? ", buf)))
79 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 (ap_sect->sct_own == player->cnum
107 || getrel(getnatp(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 (ship.shp_own == player->cnum
116 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
120 pr("Assembly point not owned by you or an ally!\n");
125 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
137 nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
140 p = getstring("Carrier #? ", buf);
147 || !getship(cno, &ship)
149 && (getrel(getnatp(ship.shp_own), player->cnum)
154 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
155 pr("Ship #%d not in %s\n", cno,
156 xyas(target->sct_x, target->sct_y, player->cnum));
159 fl = carrier_planes(&ship, 0);
161 pr("Can't land on %s.\n", prship(&ship));
164 /* clear to land on ship#CNO */
165 pr("landing on carrier %d\n", cno);
173 /* try to land at sector */
174 if (target->sct_own != player->cnum
175 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
176 pr("Nowhere to land at sector %s!\n",
177 xyas(target->sct_x, target->sct_y, player->cnum));
180 if (target->sct_type == SCT_MOUNT) {
181 pr("Nowhere to land at sector %s!\n",
182 xyas(target->sct_x, target->sct_y, player->cnum));
185 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
188 /* clear to land at sector */
195 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
196 struct emp_qelem *esc_list, int cno)
198 struct emp_qelem *list, *qp;
202 if (cno < 0 || !getship(cno, &ship))
208 for (list = bomb_list;
210 list = list == bomb_list ? esc_list : NULL) {
211 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
212 plp = (struct plist *)qp;
213 if (plp->plane.pln_ship == ship.shp_uid)
215 if (!fit_plane_on_ship(&plp->plane, &ship))
223 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
225 struct emp_qelem *qp;
232 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
233 plp = (struct plist *)qp;
236 if (!could_be_on_ship(&plp->plane, &ship))
237 pr("\t%s cannot land on ship #%d! %s aborts!\n",
238 prplane(&plp->plane), cno, prplane(&plp->plane));
239 else if (!put_plane_on_ship(&plp->plane, &ship))
240 pr("\tNo room on ship #%d! %s aborts!\n",
241 cno, prplane(&plp->plane));
243 if (plp->plane.pln_own != ship.shp_own) {
244 wu(0, ship.shp_own, "%s %s lands on your %s\n",
245 cname(player->cnum), prplane(&plp->plane),
250 plp->plane.pln_x = tx;
251 plp->plane.pln_y = ty;
252 getsect(tx, ty, §);
253 if (plp->plane.pln_own != sect.sct_own) {
255 "%s %s lands at your sector %s\n",
257 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
259 plp->plane.pln_ship = cno;
263 putship(ship.shp_uid, &ship);
267 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
270 struct emp_qelem *qp;
281 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
282 plp = (struct plist *)qp;
286 getsect(tx, ty, §);
288 if (sect.sct_type == SCT_WATER)
289 pr("Your %s sink like a rock!\n", ip->i_name);
291 pr("Your %s vanish without a trace.\n", ip->i_name);
294 if (sect.sct_own != player->cnum
295 && getrel(getnatp(sect.sct_own), player->cnum) != ALLIED) {
296 pr("You don't own %s! Cargo jettisoned...\n",
297 xyas(tx, ty, player->cnum));
300 if (ip->i_uid == I_CIVIL && sect.sct_own != sect.sct_oldown) {
301 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
302 xyas(tx, ty, player->cnum));
305 there = sect.sct_item[ip->i_uid];
309 there = ship.shp_item[ip->i_uid];
310 max = mchr[ship.shp_type].m_item[ip->i_uid];
314 pr("%d excess %s discarded\n", max - there, ip->i_name);
318 pr("%d %s landed safely", amt, ip->i_name);
320 sect.sct_item[ip->i_uid] = there;
321 if (sect.sct_own != player->cnum)
322 wu(0, sect.sct_own, "%s planes drop %d %s in %s\n",
323 cname(player->cnum), amt, ip->i_name,
324 xyas(tx, ty, sect.sct_own));
325 pr(" at %s\n", xyas(tx, ty, player->cnum));
328 ship.shp_item[ip->i_uid] = there;
329 if (ship.shp_own != player->cnum)
330 wu(0, ship.shp_own, "%s planes land %d %s on carrier %d\n",
331 cname(player->cnum), amt, ip->i_name, ship.shp_uid);
332 pr(" on carrier #%d\n", ship.shp_uid);
333 putship(ship.shp_uid, &ship);
338 pln_mine(struct emp_qelem *list, coord tx, coord ty)
340 struct emp_qelem *qp;
346 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
347 plp = (struct plist *)qp;
352 getsect(tx, ty, §);
353 if (sect.sct_type != SCT_WATER) {
354 pr("Your seamines have no effect here.\n");
357 sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
358 pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
359 if (map_set(player->cnum, tx, ty, 'X', 0))
360 writemap(player->cnum);
366 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
367 * A plane type is capable unless
368 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
369 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
370 * - it lacks any of the other capabilities in WANTFLAGS, or
371 * - it has any of the capabilities in NOWANTFLAGS.
374 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
376 int flags = plchr[(int)pp->pln_type].pl_flags;
378 if (wantflags & (P_F | P_ESC)) {
379 if ((flags & wantflags & (P_F | P_ESC)) == 0)
381 wantflags &= ~(P_F | P_ESC);
384 if (wantflags & (P_E | P_L | P_K)) {
385 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
387 wantflags &= ~(P_E | P_L | P_K);
390 if ((flags & wantflags) != wantflags)
393 if (flags & nowantflags)
400 * Find plane types that can operate from carrier SP.
401 * If MSL find missile types, else non-missile types.
402 * Return a combination of P_L, P_K, P_E.
403 * It's zero if SP can't support air operations due to its type or
404 * state (low efficiency).
407 carrier_planes(struct shpstr *sp, int msl)
409 struct mchrstr *mcp = mchr + sp->shp_type;
412 if (sp->shp_effic < SHP_AIROPS_EFF)
416 if (mcp->m_flags & M_FLY)
418 if ((mcp->m_flags & M_MSL) && msl)
420 if (mcp->m_nchoppers && !msl)
428 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
433 struct plchrstr *pcp = plchr + pp->pln_type;
435 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
438 if (pp->pln_ship >= 0) {
439 /* ship: needs to be own or allied, efficient */
440 if (!getship(pp->pln_ship, &ship)) {
444 if (ship.shp_own != pp->pln_own
445 && getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED) {
447 pr("(note) An ally does not own the ship %s is on\n",
451 if (!(carrier_planes(&ship, pcp->pl_flags & P_M) & pcp->pl_flags))
454 } else if (pp->pln_land >= 0) {
455 /* land: needs to be own or allied, efficient, not embarked */
456 if (!getland(pp->pln_land, &land)) {
460 if (land.lnd_own != pp->pln_own
461 && getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED) {
463 pr("(note) An ally does not own the unit %s is on\n",
467 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
469 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
473 /* sector: needs to be own or allied, efficient airfield */
474 if (!getsect(pp->pln_x, pp->pln_y, §)) {
479 if (sect.sct_own != pp->pln_own
480 && getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED) {
482 pr("(note) An ally does not own the sector %s is in\n",
486 /* need airfield unless VTOL */
487 if ((pcp->pl_flags & P_V) == 0) {
488 if (sect.sct_type != SCT_AIRPT) {
490 pr("%s not at airport\n", prplane(pp));
493 if (sect.sct_effic < 40) {
495 pr("%s is not 40%% efficient, %s can't take off from there.\n",
496 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
500 if (!oneway && sect.sct_effic < 60) {
502 pr("%s is not 60%% efficient, %s can't land there.\n",
503 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
514 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
515 int ap_to_target, int rangemult, int wantflags, int nowantflags)
519 struct plchrstr *pcp;
523 while (nxtitem(ni, &plane)) {
526 if (plane.pln_mobil <= 0)
528 if (plane.pln_effic < 40) {
529 pr("%s not efficient enough (must be 40%%)\n",
533 if (!pln_capable(&plane, wantflags, nowantflags))
536 if (ontradingblock(EF_PLANE, &plane)) {
537 pr("plane #%d inelligible - it's for sale.\n",
543 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
545 pr("%s too far from assembly point\n", prplane(&plane));
548 range += ap_to_target;
550 pcp = &plchr[(int)plane.pln_type];
551 if (plane.pln_range < range) {
552 pr("%s out of range (%d:%d)\n",
553 prplane(&plane), plane.pln_range, range);
556 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
558 pr("%s standing by\n", prplane(&plane));
559 plane.pln_mission = 0;
560 putplane(plane.pln_uid, &plane);
561 plp = malloc(sizeof(struct plist));
566 emp_insque(&plp->queue, list);
571 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip,
572 int flags, int mission_flags)
574 struct emp_qelem *qp;
575 struct emp_qelem *next;
579 for (qp = list->q_forw; qp != list; qp = next) {
581 plp = (struct plist *)qp;
583 getplane(pp->pln_uid, pp);
584 if ((pp->pln_flags & PLN_LAUNCHED)
585 || pln_equip(plp, ip, flags, mission) < 0) {
590 if (flags & (P_S | P_I)) {
591 if (plp->pcp->pl_flags & P_S)
592 mission_flags |= P_S;
593 if (plp->pcp->pl_flags & P_I)
594 mission_flags |= P_I;
596 if (!(plp->pcp->pl_flags & P_H))
597 /* no stealth on this mission */
598 mission_flags &= ~P_H;
599 if (!(plp->pcp->pl_flags & P_X))
600 /* no stealth on this mission */
601 mission_flags &= ~P_X;
602 if (!(plp->pcp->pl_flags & P_A)) {
603 /* no asw on this mission */
604 mission_flags &= ~P_A;
605 /* FIXME escorts turn ASW patrol into ordinary recon */
607 if (!(plp->pcp->pl_flags & P_MINE)) {
608 /* no asw on this mission */
609 mission_flags &= ~P_MINE;
610 /* FIXME no effect */
612 pp->pln_flags |= PLN_LAUNCHED;
613 pp->pln_mobil -= pln_mobcost(dist, pp, flags);
614 putplane(pp->pln_uid, pp);
615 pr("%s equipped\n", prplane(pp));
617 return mission_flags;
621 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
623 struct plchrstr *pcp;
636 if (pp->pln_ship >= 0) {
637 getship(pp->pln_ship, &ship);
638 item = ship.shp_item;
640 } else if (pp->pln_land >= 0) {
641 getland(pp->pln_land, &land);
642 item = land.lnd_item;
645 getsect(pp->pln_x, pp->pln_y, §);
646 item = sect.sct_item;
647 own = sect.sct_oldown;
650 if (ip->i_uid == I_CIVIL) {
651 if (pp->pln_own != own) {
652 pr("You don't control those civilians!\n");
657 if (pcp->pl_fuel > item[I_PETROL]) {
658 pr("%s not enough petrol there!\n", prplane(pp));
661 item[I_PETROL] -= pcp->pl_fuel;
662 if ((flags & P_F) == 0) {
667 case 's': /* strategic bomb */
668 case 'p': /* pinpoint bomb */
669 if (pp->pln_nuketype == -1) {
674 case 't': /* transport */
676 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
679 needed = (load * 2) / ip->i_lbs;
682 if ((pcp->pl_flags & P_MINE) == 0)
685 needed = (load * 2) / ip->i_lbs;
687 case 'a': /* paradrop */
688 if ((pcp->pl_flags & (P_V | P_C)) == 0)
691 needed = load / ip->i_lbs;
693 case 'r': /* reconnaissance */
698 if (itype != I_NONE && needed <= 0) {
699 pr("%s can't contribute to mission\n", prplane(pp));
702 if (itype != I_NONE) {
704 /* Supply is broken somewhere, so don't use it for now */
705 if (itype == I_SHELL && item[itype] < needed)
706 item[itype] += supply_commod(plp->plane.pln_own,
711 abandon_needed = !!would_abandon(§, itype, needed, NULL);
712 if (item[itype] < needed + abandon_needed) {
713 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
716 item[itype] -= needed;
718 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
723 if (pp->pln_ship >= 0) {
724 if (pp->pln_own != ship.shp_own) {
726 "%s %s prepares for takeoff from ship %s\n",
727 cname(pp->pln_own), prplane(pp), prship(&ship));
729 putship(ship.shp_uid, &ship);
730 } else if (pp->pln_land >= 0) {
731 if (pp->pln_own != land.lnd_own) {
733 "%s %s prepares for takeoff from unit %s\n",
734 cname(pp->pln_own), prplane(pp), prland(&land));
736 putland(land.lnd_uid, &land);
738 if (pp->pln_own != sect.sct_own) {
739 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
740 cname(pp->pln_own), prplane(pp),
741 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
749 pln_put(struct emp_qelem *list)
751 struct emp_qelem *qp, *next;
753 for (qp = list->q_forw; qp != list; qp = next) {
755 pln_put1((struct plist *)qp);
760 pln_put1(struct plist *plp)
769 if (CANT_HAPPEN((pp->pln_flags & PLN_LAUNCHED)
770 && (plchr[pp->pln_type].pl_flags & P_M)
771 && pp->pln_effic >= PLANE_MINEFF))
772 pp->pln_effic = 0; /* bug: missile launched but not used up */
774 if (!(pp->pln_flags & PLN_LAUNCHED))
775 ; /* never took off */
776 else if (pp->pln_effic < PLANE_MINEFF) {
778 if (pp->pln_ship >= 0) {
779 getship(pp->pln_ship, &ship);
780 take_plane_off_ship(pp, &ship);
782 if (pp->pln_land >= 0) {
783 getland(pp->pln_land, &land);
784 take_plane_off_land(pp, &land);
786 } else if (pp->pln_ship >= 0) {
787 /* It is landing on a carrier */
788 getship(pp->pln_ship, &ship);
789 /* We should do more, like make sure it's really
790 a carrier, etc. but for now just make sure it's
792 if (ship.shp_effic < SHIP_MINEFF) {
794 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
795 "splashes into the sea.\n",
796 pp->pln_ship, pp->pln_uid);
800 /* Presume we are landing back in a sector. */
801 getsect(pp->pln_x, pp->pln_y, §);
802 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
804 "Nowhere to land at %s, plane #%d crashes and burns...\n",
805 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
809 pp->pln_flags &= ~PLN_LAUNCHED;
810 putplane(pp->pln_uid, pp);
811 emp_remque(&plp->queue);
816 * Fit a plane of PP's type on ship SP.
817 * Adjust SP's plane counters.
818 * Updating the plane accordingly is the caller's job.
819 * Return whether it fits.
822 fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
824 struct plchrstr *pcp = plchr + pp->pln_type;
825 struct mchrstr *mcp = mchr + sp->shp_type;
828 if (pcp->pl_flags & P_K) {
829 /* chopper, try chopper slot first */
830 if (sp->shp_nchoppers < mcp->m_nchoppers)
831 return ++sp->shp_nchoppers;
832 /* else try plane slot */
834 } else if (pcp->pl_flags & P_E) {
835 /* x-light, try x-light slot first */
836 if (sp->shp_nxlight < mcp->m_nxlight)
837 return ++sp->shp_nxlight;
838 /* else try plane slot */
839 wanted = M_MSL | M_FLY;
840 } else if (!(pcp->pl_flags & P_L)) {
841 /* not light, no go */
843 } else if (pcp->pl_flags & P_M) {
844 /* missile, use plane slot */
845 wanted = M_MSL | M_FLY;
847 /* fixed-wing plane, use plane slot */
851 if ((mcp->m_flags & wanted) == 0)
852 return 0; /* ship not capable */
854 if (sp->shp_nplane < mcp->m_nplanes)
855 return ++sp->shp_nplane;
861 * Fit a plane of PP's type off ship SP.
862 * Adjust SP's plane counters, badly. You need to run count_planes()
863 * before the next fit_plane_on_ship().
864 * Updating the plane accordingly is the caller's job.
867 fit_plane_off_ship(struct plnstr *pp, struct shpstr *sp)
870 * Frees chopper and nxlight slots first, which is why we need to
871 * run count_planes() before fit_plane_on_ship().
873 struct plchrstr *pcp = plchr + pp->pln_type;
875 if (pcp->pl_flags & P_K) {
876 if (sp->shp_nchoppers) {
880 } else if (pcp->pl_flags & P_E) {
881 if (sp->shp_nxlight) {
887 if (CANT_HAPPEN(sp->shp_nplane == 0))
893 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
895 if (plane->pln_ship == ship->shp_uid)
896 return 1; /* Already on ship */
898 if (!fit_plane_on_ship(plane, ship))
901 plane->pln_x = ship->shp_x;
902 plane->pln_y = ship->shp_y;
903 plane->pln_ship = ship->shp_uid;
904 putplane(plane->pln_uid, plane);
905 putship(ship->shp_uid, ship);
910 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
912 if (CANT_HAPPEN(plane->pln_ship != ship->shp_uid))
915 fit_plane_off_ship(plane, ship);
916 plane->pln_ship = -1;
917 putship(ship->shp_uid, ship);
918 putplane(plane->pln_uid, plane);
922 * Fit a plane of PP's type on land unit LP.
923 * Adjust LP's plane counters.
924 * Updating the plane accordingly is the caller's job.
925 * Return whether it fits.
928 fit_plane_on_land(struct plnstr *pp, struct lndstr *lp)
930 struct plchrstr *pcp = plchr + pp->pln_type;
931 struct lchrstr *lcp = lchr + lp->lnd_type;
933 if ((pcp->pl_flags & P_E) && lp->lnd_nxlight < lcp->l_nxlight)
934 return ++lp->lnd_nxlight;
940 * Fit a plane of PP's type off land unit LP.
941 * Adjust LP's plane counters.
942 * Updating the plane accordingly is the caller's job.
945 fit_plane_off_land(struct plnstr *pp, struct lndstr *lp)
947 if (CANT_HAPPEN(lp->lnd_nxlight == 0))
953 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
955 if (plane->pln_land == land->lnd_uid)
956 return 1; /* Already on unit */
958 if (!fit_plane_on_land(plane, land))
961 plane->pln_x = land->lnd_x;
962 plane->pln_y = land->lnd_y;
963 plane->pln_land = land->lnd_uid;
964 putplane(plane->pln_uid, plane);
965 putland(land->lnd_uid, land);
970 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
972 if (CANT_HAPPEN(plane->pln_land != land->lnd_uid))
975 fit_plane_off_land(plane, land);
976 plane->pln_land = -1;
977 putland(land->lnd_uid, land);
978 putplane(plane->pln_uid, plane);
982 * Could a plane of PP's type be on on ship SP?
985 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
990 ship.shp_nplane = ship.shp_nchoppers = ship.shp_nxlight = 0;
991 return fit_plane_on_ship(pp, &ship);
995 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
998 struct plchrstr *pcp;
999 struct emp_qelem *qp;
1000 struct emp_qelem *next;
1006 getsect(x, y, §);
1007 mines_there = sect.sct_mines;
1009 if (mines_there == 0)
1012 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
1015 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
1018 ip = (struct plist *)qp;
1021 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
1024 if (chance((100.0 - pln_acc(pp)) / 100.0)) {
1025 pr("Sweep! in %s\n",
1026 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1032 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1033 writemap(player->cnum);
1034 sect.sct_mines = mines_there;
1039 count_planes(struct shpstr *sp)
1041 struct nstr_item ni;
1042 struct plnstr plane;
1043 int nplane, nchoppers, nxlight;
1045 if (sp->shp_effic < SHIP_MINEFF)
1048 nplane = sp->shp_nplane;
1050 nchoppers = sp->shp_nchoppers;
1051 sp->shp_nchoppers = 0;
1052 nxlight = sp->shp_nxlight;
1053 sp->shp_nxlight = 0;
1055 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1056 while (nxtitem(&ni, &plane)) {
1057 if (plane.pln_own == 0)
1059 if (plane.pln_ship == sp->shp_uid) {
1060 if (!fit_plane_on_ship(&plane, sp))
1065 if (nplane != sp->shp_nplane ||
1066 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1067 putship(sp->shp_uid, sp);
1072 count_land_planes(struct lndstr *lp)
1074 struct nstr_item ni;
1075 struct plnstr plane;
1078 if (lp->lnd_effic < LAND_MINEFF)
1081 nplane = lp->lnd_nxlight;
1082 lp->lnd_nxlight = 0;
1084 snxtitem_all(&ni, EF_PLANE);
1085 while (nxtitem(&ni, &plane)) {
1086 if (plane.pln_own == 0)
1088 if (plane.pln_land == lp->lnd_uid)
1089 if (!fit_plane_on_land(&plane, lp))
1093 if (lp->lnd_nxlight != nplane)
1094 putland(lp->lnd_uid, lp);
1098 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1100 struct plchrstr *pcp = plchr + pp->pln_type;
1101 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
1102 (pp->pln_tech - pcp->pl_tech / 2);
1103 int acc = pln_acc(pp);
1106 if (type == EF_SHIP) {
1107 if (pcp->pl_flags & P_A)
1109 if (!(pcp->pl_flags & P_T))
1112 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1113 (1.0 - acc / 100.0)) - hardtarget;
1115 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1117 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1118 if (hitchance > 100)
1123 /* return 0 if there was a nuclear detonation */
1126 pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
1130 struct plchrstr *pcp = plchr + pp->pln_type;
1138 if (pp->pln_nuketype != -1) {
1139 if (nuk_on_plane(&nuke, pp->pln_uid) >= 0) {
1140 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1141 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1142 pp->pln_nuketype = -1;
1143 *nukedamp = detonate(&nuke, x, y,
1144 pp->pln_flags & PLN_AIRBURST);
1151 load = pln_load(pp);
1152 if (!load) /* e.g. ab, blowing up on launch pad */
1159 if (pcp->pl_flags & P_M) {
1160 if (pcp->pl_flags & P_MAR)
1162 } else if (pcp->pl_flags & P_T)
1167 effective = !pinbomber;
1168 aim = 30 + (pinbomber ? aim : 100 - aim);
1170 effective = pinbomber;
1176 hitroll = roll(100);
1177 if (hitroll >= 90) {
1180 mpr(pp->pln_own, "BLAM");
1181 } else if (hitroll < aim) {
1184 mpr(pp->pln_own, "Blam");
1188 mpr(pp->pln_own, "blam");
1191 mpr(pp->pln_own, "-");
1194 mpr(pp->pln_own, "\n");
1201 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1204 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1205 return (int)(100 - 100 * misschance * misschance);
1209 pln_mobcost(int dist, struct plnstr *pp, int flags)
1213 cost = 20.0 / (pp->pln_effic / 100.0);
1214 if ((flags & P_F) || (flags & P_ESC))
1217 return ldround(cost * dist / pln_range_max(pp) + 5, 1);
1221 pln_is_in_orbit(struct plnstr *pp)
1223 return (plchr[pp->pln_type].pl_flags & (P_M | P_O)) == P_O
1224 && (pp->pln_flags & PLN_LAUNCHED);
1228 * Set PP's tech to TLEV along with everything else that depends on it.
1231 pln_set_tech(struct plnstr *pp, int tlev)
1233 struct plchrstr *pcp = plchr + pp->pln_type;
1234 int limited_range = pp->pln_range < pln_range_max(pp);
1237 if (CANT_HAPPEN(tlev < pcp->pl_tech))
1238 tlev = pcp->pl_tech;
1239 pp->pln_tech = tlev;
1241 range_max = pln_range_max(pp);
1242 if (!limited_range || pp->pln_range > range_max)
1243 pp->pln_range = range_max;