2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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-2005
53 #include "prototypes.h"
58 static int carrier_planes(struct shpstr *);
59 static int pln_equip(struct plist *, struct ichrstr *, int, char);
60 static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
63 * Get assembly point argument.
64 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
65 * If this yields a valid assembly point, read it into *AP_SECT and
67 * Else complain and return NULL.
68 * *AP_SECT and BUF[1024] may be modified in either case.
71 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
78 p = getstarg(input, "assembly point? ", buf);
81 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
84 /* over own or allied sector is fine */
85 if (ap_sect->sct_own == player->cnum
86 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
89 /* over own or allied ship is fine */
90 snxtitem_xy(&ni, EF_SHIP, x, y);
91 while (nxtitem(&ni, &ship)) {
92 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
94 if (ship.shp_own == player->cnum
95 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
99 pr("Assembly point not owned by you or an ally!\n");
104 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
116 nships = carriersatxy(target->sct_x, target->sct_y,
117 M_FLY | M_CHOPPER, 0, player->cnum);
120 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
124 || !getship(cno, &ship)
126 && (getrel(getnatp(ship.shp_own), player->cnum)
131 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
132 pr("Ship #%d not in %s\n", cno,
133 xyas(target->sct_x, target->sct_y, player->cnum));
136 fl = carrier_planes(&ship);
138 pr("Can't land on %s.\n", prship(&ship));
141 /* clear to land on ship#CNO */
142 pr("landing on carrier %d\n", cno);
150 /* try to land at sector */
151 if (target->sct_own != player->cnum
152 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
153 pr("Nowhere to land at sector %s!\n",
154 xyas(target->sct_x, target->sct_y, player->cnum));
157 if (target->sct_type == SCT_MOUNT) {
158 pr("Nowhere to land at sector %s!\n",
159 xyas(target->sct_x, target->sct_y, player->cnum));
162 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
165 /* clear to land at sector */
172 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
173 struct emp_qelem *esc_list, int cno)
175 struct emp_qelem *list, *qp;
179 if (cno < 0 || !getship(cno, &ship))
185 for (list = bomb_list;
187 list = list == bomb_list ? esc_list : NULL) {
188 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
189 plp = (struct plist *)qp;
190 if (plp->plane.pln_ship == ship.shp_uid)
192 if (!fit_plane_on_ship(&plp->plane, &ship))
200 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
202 struct emp_qelem *qp;
209 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
210 plp = (struct plist *)qp;
213 if (!could_be_on_ship(&plp->plane, &ship))
214 pr("\t%s cannot land on ship #%d! %s aborts!\n",
215 prplane(&plp->plane), cno, prplane(&plp->plane));
216 else if (!put_plane_on_ship(&plp->plane, &ship))
217 pr("\tNo room on ship #%d! %s aborts!\n",
218 cno, prplane(&plp->plane));
220 if (plp->plane.pln_own != ship.shp_own) {
221 /* plp->plane.pln_own = ship.shp_own;*/
222 wu(0, ship.shp_own, "%s %s lands on your %s\n",
223 cname(player->cnum), prplane(&plp->plane),
228 plp->plane.pln_x = tx;
229 plp->plane.pln_y = ty;
230 getsect(tx, ty, §);
231 if (plp->plane.pln_own != sect.sct_own) {
232 /* plp->plane.pln_own = sect.sct_own;*/
234 "%s %s lands at your sector %s\n",
236 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
238 plp->plane.pln_ship = cno;
242 putship(ship.shp_uid, &ship);
246 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
249 struct emp_qelem *qp;
252 struct sctstr *sectp;
261 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
262 plp = (struct plist *)qp;
265 if (type == EF_SECTOR) {
267 if (!sectp->sct_own) {
268 if (sectp->sct_type == SCT_WATER)
269 pr("Your %s sink like a rock!\n", ip->i_name);
271 pr("Your %s vanish without a trace.\n", ip->i_name);
274 if (sectp->sct_own != player->cnum
275 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
276 pr("You don't own %s! Cargo jettisoned...\n",
277 xyas(tx, ty, player->cnum));
280 if (ip->i_uid == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
281 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
282 xyas(tx, ty, player->cnum));
285 there = sectp->sct_item[ip->i_uid];
289 there = sp->shp_item[ip->i_uid];
290 mp = &mchr[(int)sp->shp_type];
291 max = mp->m_item[ip->i_uid];
295 pr("%d excess %s discarded\n", max - there, ip->i_name);
299 pr("%d %s landed safely", amt, ip->i_name);
300 if (type == EF_SECTOR) {
302 sectp->sct_item[ip->i_uid] = there;
303 if (sectp->sct_own != player->cnum)
304 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
305 cname(player->cnum), amt, ip->i_name,
306 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
307 pr(" at %s\n", xyas(tx, ty, player->cnum));
308 putsect((struct sctstr *)ptr);
310 struct shpstr *sp = (struct shpstr *)ptr;
311 sp->shp_item[ip->i_uid] = there;
312 if (sp->shp_own != player->cnum)
313 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
314 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
315 pr(" on carrier #%d\n", sp->shp_uid);
316 putship(sp->shp_uid, sp);
321 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
323 struct emp_qelem *qp;
328 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
329 plp = (struct plist *)qp;
334 if (sectp->sct_type != SCT_WATER) {
335 pr("Your seamines have no effect here.\n");
338 sectp->sct_mines = MIN(sectp->sct_mines + amt, MINES_MAX);
339 pr("%d mines laid in %s.\n", amt,
340 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
341 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
342 writemap(player->cnum);
348 * Has PP's type capabilities satisfying WANTFLAGS and NOWANTFLAGS?
349 * A plane type is capable unless
350 * - it lacks all of the P_F, P_ESC in WANTFLAGS, or
351 * - it lacks all of the P_E, P_L, P_K in WANTFLAGS, or
352 * - it lacks any of the other capabilities in WANTFLAGS, or
353 * - it has any of the capabilities in NOWANTFLAGS.
356 pln_capable(struct plnstr *pp, int wantflags, int nowantflags)
358 int flags = plchr[(int)pp->pln_type].pl_flags;
360 if (wantflags & (P_F | P_ESC)) {
361 if ((flags & wantflags & (P_F | P_ESC)) == 0)
363 wantflags &= ~(P_F | P_ESC);
366 if (wantflags & (P_E | P_L | P_K)) {
367 if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
369 wantflags &= ~(P_E | P_L | P_K);
372 if ((flags & wantflags) != wantflags)
375 if (flags & nowantflags)
382 * Find non-missile plane types that can operate from carrier SP.
383 * Return a combination of P_L, P_K, P_E.
384 * It's zero if SP can't support air operations due to its type or
385 * state (low efficiency).
388 carrier_planes(struct shpstr *sp)
390 struct mchrstr *mcp = mchr + sp->shp_type;
393 if (sp->shp_effic < SHP_AIROPS_EFF)
397 if (mcp->m_flags & M_FLY)
399 if (mcp->m_flags & M_CHOPPER)
401 if (mcp->m_flags & M_XLIGHT)
407 pln_airbase_ok(struct plnstr *pp, int oneway, int noisy)
412 struct plchrstr *pcp = plchr + pp->pln_type;
414 if (CANT_HAPPEN(noisy && pp->pln_own != player->cnum))
417 if (pp->pln_ship >= 0) {
418 /* ship: needs to be own or allied, efficient */
419 if (!getship(pp->pln_ship, &ship)) {
423 if (ship.shp_own != pp->pln_own
424 && getrel(getnatp(ship.shp_own), pp->pln_own) != ALLIED) {
426 pr("(note) An ally does not own the ship %s is on\n",
430 if ((carrier_planes(&ship) & pcp->pl_flags) == 0)
433 } else if (pp->pln_land >= 0) {
434 /* land: needs to be own or allied, efficient, not embarked */
435 if (!getland(pp->pln_land, &land)) {
439 if (land.lnd_own != pp->pln_own
440 && getrel(getnatp(land.lnd_own), pp->pln_own) != ALLIED) {
442 pr("(note) An ally does not own the unit %s is on\n",
446 if (land.lnd_effic < LND_AIROPS_EFF || !(pcp->pl_flags & P_E))
448 if (land.lnd_ship >= 0 || land.lnd_land >= 0)
452 /* sector: needs to be own or allied, efficient airfield */
453 if (!getsect(pp->pln_x, pp->pln_y, §)) {
458 if (sect.sct_own != pp->pln_own
459 && getrel(getnatp(sect.sct_own), pp->pln_own) != ALLIED) {
461 pr("(note) An ally does not own the sector %s is in\n",
465 /* need airfield unless VTOL */
466 if ((pcp->pl_flags & P_V) == 0) {
467 if (sect.sct_type != SCT_AIRPT) {
469 pr("%s not at airport\n", prplane(pp));
472 if (sect.sct_effic < 40) {
474 pr("%s is not 40%% efficient, %s can't take off from there.\n",
475 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
479 if (!oneway && sect.sct_effic < 60) {
481 pr("%s is not 60%% efficient, %s can't land there.\n",
482 xyas(sect.sct_x, sect.sct_y, pp->pln_own),
493 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
494 int ap_to_target, int rangemult, int wantflags, int nowantflags)
498 struct plchrstr *pcp;
505 while (nxtitem(ni, &plane)) {
508 if (plane.pln_mobil <= 0)
511 if (ontradingblock(EF_PLANE, &plane)) {
512 pr("plane #%d inelligible - it's for sale.\n",
518 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
520 pr("%s too far from assembly point\n", prplane(&plane));
523 if (plane.pln_effic < 40) {
524 pr("%s not efficient enough (must be 40%%)\n",
528 range += ap_to_target;
530 pcp = &plchr[(int)plane.pln_type];
531 if (!pln_capable(&plane, wantflags, nowantflags))
533 if (plane.pln_range < range) {
534 pr("%s out of range (%d:%d)\n",
535 prplane(&plane), plane.pln_range, range);
538 if (!pln_airbase_ok(&plane, rangemult != 2, 1))
540 pr("%s standing by\n", prplane(&plane));
541 plane.pln_mission = 0;
542 putplane(plane.pln_uid, &plane);
543 plp = malloc(sizeof(struct plist));
548 emp_insque(&plp->queue, list);
553 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip,
554 int flags, int mission_flags)
556 struct emp_qelem *qp;
557 struct emp_qelem *next;
560 for (qp = list->q_forw; qp != list; qp = next) {
562 plp = (struct plist *)qp;
563 if (pln_equip(plp, ip, flags, mission) < 0) {
568 if (flags & (P_S | P_I)) {
569 if (plp->pcp->pl_flags & P_S)
570 mission_flags |= P_S;
571 if (plp->pcp->pl_flags & P_I)
572 mission_flags |= P_I;
574 if (!(plp->pcp->pl_flags & P_H))
575 /* no stealth on this mission */
576 mission_flags &= ~P_H;
577 if (!(plp->pcp->pl_flags & P_X))
578 /* no stealth on this mission */
579 mission_flags &= ~P_X;
580 if (!(plp->pcp->pl_flags & P_A)) {
581 /* no asw on this mission */
582 mission_flags &= ~P_A;
583 /* FIXME escorts turn ASW patrol into ordinary recon */
585 if (!(plp->pcp->pl_flags & P_MINE)) {
586 /* no asw on this mission */
587 mission_flags &= ~P_MINE;
588 /* FIXME no effect */
590 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
591 pr("%s equipped\n", prplane(&plp->plane));
593 return mission_flags;
597 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
599 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;
640 if ((flags & P_F) == 0) {
646 if (pp->pln_nuketype == -1) {
648 needed = pp->pln_load;
653 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
656 needed = (pp->pln_load * 2) / ip->i_lbs;
659 if ((pcp->pl_flags & P_MINE) == 0)
662 needed = (pp->pln_load * 2) / ip->i_lbs;
665 if ((pcp->pl_flags & (P_V | P_C)) == 0)
668 needed = pp->pln_load / ip->i_lbs;
671 if (pp->pln_nuketype == -1)
677 if (rval < 0 || (itype != I_NONE && needed <= 0)) {
678 pr("%s can't contribute to mission\n", prplane(pp));
681 if (itype != I_NONE) {
683 /* Supply is broken somewhere, so don't use it for now */
684 if (itype == I_SHELL && item[itype] < needed)
685 item[itype] += supply_commod(plp->plane.pln_own,
690 abandon_needed = !!would_abandon(§, itype, needed, NULL);
691 if (item[itype] < needed + abandon_needed) {
692 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
695 item[itype] -= needed;
697 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
702 if (pp->pln_ship >= 0) {
703 if (pp->pln_own != ship.shp_own) {
705 "%s %s prepares for takeoff from ship %s\n",
706 cname(pp->pln_own), prplane(pp), prship(&ship));
708 putship(ship.shp_uid, &ship);
709 } else if (pp->pln_land >= 0) {
710 if (pp->pln_own != land.lnd_own) {
712 "%s %s prepares for takeoff from unit %s\n",
713 cname(pp->pln_own), prplane(pp), prland(&land));
715 putland(land.lnd_uid, &land);
717 if (pp->pln_own != sect.sct_own) {
718 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
719 cname(pp->pln_own), prplane(pp),
720 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
728 pln_put(struct emp_qelem *list)
730 struct emp_qelem *qp;
731 struct emp_qelem *newqp;
737 /* Here is where planes return home from bombing runs.
738 We need to make sure they still have somewhere to return
742 plp = (struct plist *)qp;
744 /* Ok, check out where it wants to land */
745 if (pp->pln_ship >= 0) {
746 /* It is landing on a carrier */
747 getship(pp->pln_ship, &ship);
748 /* We should do more, like make sure it's really
749 a carrier, etc. but for now just make sure it's
751 if (ship.shp_effic < SHIP_MINEFF) {
753 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
754 "splashes into the sea.\n",
755 pp->pln_ship, pp->pln_uid);
759 /* Presume we are landing back in a sector. */
760 getsect(pp->pln_x, pp->pln_y, §);
761 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
763 "Nowhere to land at %s, plane #%d crashes and burns...\n",
764 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
768 putplane(pp->pln_uid, pp);
777 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
779 struct emp_qelem *bomb;
780 struct emp_qelem *esc;
784 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
786 bomb = bomb_list->q_forw;
787 while (bomb != bomb_list) {
788 if (QEMPTY(esc_list)) {
792 esc = esc_list->q_forw;
793 bombp = (struct plist *)bomb;
794 while (esc != esc_list) {
795 escp = (struct plist *)esc;
796 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
808 * Fit a plane of PP's type on ship SP.
809 * Adjust SP's plane counters.
810 * Updating the plane accordingly is the caller's job.
811 * Return whether it fits.
814 fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
816 struct plchrstr *pcp = plchr + pp->pln_type;
817 struct mchrstr *mcp = mchr + sp->shp_type;
820 if (pcp->pl_flags & P_K) {
821 /* chopper, try chopper slot first */
822 if (sp->shp_nchoppers < mcp->m_nchoppers)
823 return ++sp->shp_nchoppers;
824 /* else try plane slot */
826 } else if (pcp->pl_flags & P_E) {
827 /* x-light, try x-light slot first */
828 if (sp->shp_nxlight < mcp->m_nxlight)
829 return ++sp->shp_nxlight;
830 /* else try plane slot */
831 wanted = M_MSL | M_FLY;
832 } else if (!(pcp->pl_flags & P_L)) {
833 /* not light, no go */
835 } else if (pcp->pl_flags & P_M) {
836 /* missile, use plane slot */
837 wanted = M_MSL | M_FLY;
839 /* fixed-wing plane, use plane slot */
843 if ((mcp->m_flags & wanted) == 0)
844 return 0; /* ship not capable */
846 if (sp->shp_nplane < mcp->m_nplanes)
847 return ++sp->shp_nplane;
853 * Fit a plane of PP's type off ship SP.
854 * Adjust SP's plane counters, badly. You need to run count_planes()
855 * before the next fit_plane_on_ship().
856 * Updating the plane accordingly is the caller's job.
859 fit_plane_off_ship(struct plnstr *pp, struct shpstr *sp)
862 * Frees chopper and nxlight slots first, which is why we need to
863 * run count_planes() before fit_plane_on_ship().
865 struct plchrstr *pcp = plchr + pp->pln_type;
867 if (pcp->pl_flags & P_K) {
868 if (sp->shp_nchoppers) {
872 } else if (pcp->pl_flags & P_E) {
873 if (sp->shp_nxlight) {
879 if (CANT_HAPPEN(sp->shp_nplane == 0))
885 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
887 if (plane->pln_ship == ship->shp_uid)
888 return 1; /* Already on ship */
890 if (!fit_plane_on_ship(plane, ship))
893 plane->pln_x = ship->shp_x;
894 plane->pln_y = ship->shp_y;
895 plane->pln_ship = ship->shp_uid;
896 putplane(plane->pln_uid, plane);
897 putship(ship->shp_uid, ship);
902 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
904 if (CANT_HAPPEN(plane->pln_ship != ship->shp_uid))
907 fit_plane_off_ship(plane, ship);
908 plane->pln_ship = -1;
909 putship(ship->shp_uid, ship);
910 putplane(plane->pln_uid, plane);
914 * Fit a plane of PP's type on land unit LP.
915 * Adjust LP's plane counters.
916 * Updating the plane accordingly is the caller's job.
917 * Return whether it fits.
920 fit_plane_on_land(struct plnstr *pp, struct lndstr *lp)
922 struct plchrstr *pcp = plchr + pp->pln_type;
923 struct lchrstr *lcp = lchr + lp->lnd_type;
925 if ((pcp->pl_flags & P_E) && lp->lnd_nxlight < lcp->l_nxlight)
926 return ++lp->lnd_nxlight;
932 * Fit a plane of PP's type off land unit LP.
933 * Adjust LP's plane counters.
934 * Updating the plane accordingly is the caller's job.
937 fit_plane_off_land(struct plnstr *pp, struct lndstr *lp)
939 struct plchrstr *pcp = plchr + pp->pln_type;
941 if (CANT_HAPPEN(lp->lnd_nxlight == 0))
947 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
949 if (plane->pln_land == land->lnd_uid)
950 return 1; /* Already on unit */
952 if (!fit_plane_on_land(plane, land))
955 plane->pln_x = land->lnd_x;
956 plane->pln_y = land->lnd_y;
957 plane->pln_land = land->lnd_uid;
958 putplane(plane->pln_uid, plane);
959 putland(land->lnd_uid, land);
964 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
966 if (CANT_HAPPEN(plane->pln_ship != land->lnd_uid))
969 fit_plane_off_land(plane, land);
970 plane->pln_land = -1;
971 putland(land->lnd_uid, land);
972 putplane(plane->pln_uid, plane);
976 * Could a plane of PP's type be on on ship SP?
979 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
984 ship.shp_nplane = ship.shp_nchoppers = ship.shp_nxlight = 0;
985 return fit_plane_on_ship(pp, &ship);
989 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
992 struct plchrstr *pcp;
993 struct emp_qelem *qp;
994 struct emp_qelem *next;
1000 getsect(x, y, §);
1001 mines_there = sect.sct_mines;
1003 if (mines_there == 0)
1006 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
1009 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
1012 ip = (struct plist *)qp;
1015 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
1018 if (chance((100.0 - pp->pln_acc) / 100.0)) {
1019 pr("Sweep! in %s\n",
1020 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1026 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1027 writemap(player->cnum);
1028 sect.sct_mines = mines_there;
1033 count_planes(struct shpstr *sp)
1035 struct nstr_item ni;
1036 struct plnstr plane;
1037 int nplane, nchoppers, nxlight;
1039 if (sp->shp_effic < SHIP_MINEFF)
1042 nplane = sp->shp_nplane;
1044 nchoppers = sp->shp_nchoppers;
1045 sp->shp_nchoppers = 0;
1046 nxlight = sp->shp_nxlight;
1047 sp->shp_nxlight = 0;
1049 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1050 while (nxtitem(&ni, &plane)) {
1051 if (plane.pln_own == 0)
1053 if (plane.pln_ship == sp->shp_uid) {
1054 if (!fit_plane_on_ship(&plane, sp))
1059 if (nplane != sp->shp_nplane ||
1060 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1061 putship(sp->shp_uid, sp);
1066 count_land_planes(struct lndstr *lp)
1068 struct nstr_item ni;
1069 struct plnstr plane;
1072 if (lp->lnd_effic < LAND_MINEFF)
1075 nplane = lp->lnd_nxlight;
1076 lp->lnd_nxlight = 0;
1078 snxtitem_all(&ni, EF_PLANE);
1079 while (nxtitem(&ni, &plane)) {
1080 if (plane.pln_own == 0)
1082 if (plane.pln_land == lp->lnd_uid)
1083 if (!fit_plane_on_land(&plane, lp))
1087 if (lp->lnd_nxlight != nplane)
1088 putland(lp->lnd_uid, lp);
1092 count_sect_planes(struct sctstr *sp)
1095 struct nstr_item ni;
1096 struct plnstr plane;
1098 snxtitem_all(&ni, EF_PLANE);
1099 while (nxtitem(&ni, &plane)) {
1102 if (plane.pln_flags & PLN_LAUNCHED)
1104 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1112 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1114 struct plchrstr *pcp = plchr + pp->pln_type;
1115 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
1116 (pp->pln_tech - pcp->pl_tech / 2);
1117 int acc = pp->pln_acc;
1120 if (type == EF_SHIP) {
1121 if (pcp->pl_flags & P_A)
1123 if (!(pcp->pl_flags & P_T))
1126 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1127 (1.0 - acc / 100.0)) - hardtarget;
1129 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1131 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1132 if (hitchance > 100)
1137 /* return 0 if there was a nuclear detonation */
1140 pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
1144 struct plchrstr *pcp = plchr + pp->pln_type;
1152 if (pp->pln_nuketype != -1) {
1153 if (nuk_on_plane(&nuke, pp->pln_uid) >= 0) {
1154 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1155 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1156 pp->pln_nuketype = -1;
1157 *nukedamp = detonate(&nuke, x, y,
1158 pp->pln_flags & PLN_AIRBURST);
1165 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1168 i = roll(pp->pln_load) + 1;
1169 if (i > pp->pln_load)
1172 if (pcp->pl_flags & P_M) {
1173 if (pcp->pl_flags & P_MAR)
1175 } else if (pcp->pl_flags & P_T)
1178 aim = 100 - pp->pln_acc;
1192 hitroll = roll(100);
1193 if (hitroll >= 90) {
1196 mpr(pp->pln_own, "BLAM");
1197 } else if (hitroll < aim) {
1200 mpr(pp->pln_own, "Blam");
1204 mpr(pp->pln_own, "blam");
1207 mpr(pp->pln_own, "-");
1210 mpr(pp->pln_own, "\n");
1217 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1220 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1221 return (int)(100 - 100 * misschance * misschance);
1225 pln_mobcost(int dist, struct plnstr *pp, int flags)
1229 cost = 20.0 / (pp->pln_effic / 100.0);
1230 if ((flags & P_F) || (flags & P_ESC))
1233 return ldround(cost * dist / pp->pln_range_max + 5, 1);
1237 * Set PP's tech to TLEV along with everything else that depends on it.
1240 pln_set_tech(struct plnstr *pp, int tlev)
1242 struct plchrstr *pcp = plchr + pp->pln_type;
1243 int tech_diff = tlev - pcp->pl_tech;
1244 int limited_range = pp->pln_range < pp->pln_range_max;
1246 if (CANT_HAPPEN(tech_diff < 0)) {
1251 pp->pln_tech = tlev;
1252 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1253 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1254 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1255 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1256 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1258 if (!limited_range || pp->pln_range > pp->pln_range_max)
1259 pp->pln_range = pp->pln_range_max;