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 pln_equip(struct plist *, struct ichrstr *, int, char);
59 static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
62 * Get assembly point argument.
63 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
64 * If this yields a valid assembly point, read it into *AP_SECT and
66 * Else complain and return NULL.
67 * *AP_SECT and BUF[1024] may be modified in either case.
70 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
77 p = getstarg(input, "assembly point? ", buf);
80 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
83 /* over own or allied sector is fine */
84 if (ap_sect->sct_own == player->cnum
85 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
88 /* over own or allied ship is fine */
89 snxtitem_xy(&ni, EF_SHIP, x, y);
90 while (nxtitem(&ni, &ship)) {
91 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
93 if (ship.shp_own == player->cnum
94 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
98 pr("Assembly point not owned by you or an ally!\n");
103 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
115 nships = carriersatxy(target->sct_x, target->sct_y,
116 M_FLY | M_CHOPPER, 0, player->cnum);
119 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
123 || !getship(cno, &ship)
125 && (getrel(getnatp(ship.shp_own), player->cnum)
130 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
131 pr("Ship #%d not in %s\n", cno,
132 xyas(target->sct_x, target->sct_y, player->cnum));
135 if ((!(mchr[(int)ship.shp_type].m_flags & M_FLY)
136 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
137 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER))
138 || ship.shp_effic < SHP_AIROPS_EFF) {
139 pr("Can't land on %s.\n", prship(&ship));
143 /* clear to land on ship#CNO */
144 pr("landing on carrier %d\n", cno);
145 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
147 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
149 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
157 /* try to land at sector */
158 if (target->sct_own != player->cnum
159 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
160 pr("Nowhere to land at sector %s!\n",
161 xyas(target->sct_x, target->sct_y, player->cnum));
164 if (target->sct_type == SCT_MOUNT) {
165 pr("Nowhere to land at sector %s!\n",
166 xyas(target->sct_x, target->sct_y, player->cnum));
169 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
172 /* clear to land at sector */
179 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
180 struct emp_qelem *esc_list, int cno)
182 struct emp_qelem *list, *qp;
186 if (cno < 0 || !getship(cno, &ship))
192 for (list = bomb_list;
194 list = list == bomb_list ? esc_list : NULL) {
195 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
196 plp = (struct plist *)qp;
197 if (plp->plane.pln_ship == ship.shp_uid)
199 if (!fit_plane_on_ship(&plp->plane, &ship))
207 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
209 struct emp_qelem *qp;
216 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
217 plp = (struct plist *)qp;
220 if (!could_be_on_ship(&plp->plane, &ship))
221 pr("\t%s cannot land on ship #%d! %s aborts!\n",
222 prplane(&plp->plane), cno, prplane(&plp->plane));
223 else if (!put_plane_on_ship(&plp->plane, &ship))
224 pr("\tNo room on ship #%d! %s aborts!\n",
225 cno, prplane(&plp->plane));
227 if (plp->plane.pln_own != ship.shp_own) {
228 /* plp->plane.pln_own = ship.shp_own;*/
229 wu(0, ship.shp_own, "%s %s lands on your %s\n",
230 cname(player->cnum), prplane(&plp->plane),
235 plp->plane.pln_x = tx;
236 plp->plane.pln_y = ty;
237 getsect(tx, ty, §);
238 if (plp->plane.pln_own != sect.sct_own) {
239 /* plp->plane.pln_own = sect.sct_own;*/
241 "%s %s lands at your sector %s\n",
243 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
245 plp->plane.pln_ship = cno;
249 putship(ship.shp_uid, &ship);
253 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
256 struct emp_qelem *qp;
259 struct sctstr *sectp;
268 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
269 plp = (struct plist *)qp;
272 if (type == EF_SECTOR) {
274 if (!sectp->sct_own) {
275 if (sectp->sct_type == SCT_WATER)
276 pr("Your %s sink like a rock!\n", ip->i_name);
278 pr("Your %s vanish without a trace.\n", ip->i_name);
281 if (sectp->sct_own != player->cnum
282 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
283 pr("You don't own %s! Cargo jettisoned...\n",
284 xyas(tx, ty, player->cnum));
287 if (ip->i_uid == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
288 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
289 xyas(tx, ty, player->cnum));
292 there = sectp->sct_item[ip->i_uid];
296 there = sp->shp_item[ip->i_uid];
297 mp = &mchr[(int)sp->shp_type];
298 max = mp->m_item[ip->i_uid];
302 pr("%d excess %s discarded\n", max - there, ip->i_name);
306 pr("%d %s landed safely", amt, ip->i_name);
307 if (type == EF_SECTOR) {
309 sectp->sct_item[ip->i_uid] = there;
310 if (sectp->sct_own != player->cnum)
311 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
312 cname(player->cnum), amt, ip->i_name,
313 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
314 pr(" at %s\n", xyas(tx, ty, player->cnum));
315 putsect((struct sctstr *)ptr);
317 struct shpstr *sp = (struct shpstr *)ptr;
318 sp->shp_item[ip->i_uid] = there;
319 if (sp->shp_own != player->cnum)
320 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
321 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
322 pr(" on carrier #%d\n", sp->shp_uid);
323 putship(sp->shp_uid, sp);
328 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
330 struct emp_qelem *qp;
335 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
336 plp = (struct plist *)qp;
341 if (sectp->sct_type != SCT_WATER) {
342 pr("Your seamines have no effect here.\n");
345 sectp->sct_mines = MIN(sectp->sct_mines + amt, MINES_MAX);
346 pr("%d mines laid in %s.\n", amt,
347 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
348 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
349 writemap(player->cnum);
355 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
356 int ap_to_target, int rangemult, int wantflags, int nowantflags)
363 struct plchrstr *pcp;
370 while (nxtitem(ni, &plane)) {
373 if (plane.pln_mobil <= 0)
376 if (ontradingblock(EF_PLANE, &plane)) {
377 pr("plane #%d inelligible - it's for sale.\n",
383 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
385 pr("%s too far from assembly point\n", prplane(&plane));
388 if (plane.pln_effic < 40) {
389 pr("%s not efficient enough (must be 40%%)\n",
393 range += ap_to_target;
395 pcp = &plchr[(int)plane.pln_type];
399 for (x = 0; x < sizeof(wantflags) * 8; x++) {
401 if ((wantflags & y) == y)
402 if ((pcp->pl_flags & y) != y) {
421 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
425 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
427 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
429 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
438 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
440 if ((nowantflags & y) == y)
441 if ((pcp->pl_flags & y) == y)
447 if (plane.pln_range < range) {
448 pr("%s out of range (%d:%d)\n",
449 prplane(&plane), plane.pln_range, range);
452 if (plane.pln_ship >= 0) {
453 if (!getship(plane.pln_ship, &ship) ||
454 plane.pln_own != player->cnum) {
457 pr("(note) ship not valid for %s\n", prplane(&plane));
458 putplane(plane.pln_uid, &plane);
461 if (!could_be_on_ship(&plane, &ship))
463 if (ship.shp_effic < SHIP_MINEFF)
465 if (ship.shp_effic < SHP_AIROPS_EFF)
467 /* Can't fly off non-owned ships or non-allied ship */
468 if ((ship.shp_own != player->cnum) &&
469 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
470 pr("(note) An ally does not own the ship %s is on\n",
475 if (plane.pln_land >= 0) {
476 if (!getland(plane.pln_land, &land) ||
477 (plane.pln_own != player->cnum)) {
480 pr("(note) land unit not valid for %s\n", prplane(&plane));
481 putplane(plane.pln_uid, &plane);
484 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
486 if (land.lnd_effic < LAND_MINEFF)
488 if (land.lnd_effic < LND_AIROPS_EFF)
490 /* Can't fly off units in ships or other units */
491 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
493 /* Can't fly off non-owned units or non-allied unit */
494 if ((land.lnd_own != player->cnum) &&
495 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
496 pr("(note) An ally does not own the unit %s is on\n",
501 /* Now, check the sector status if not on a plane or unit */
502 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
503 if (!getsect(plane.pln_x, plane.pln_y, §))
505 /* First, check allied status */
506 /* Can't fly from non-owned sectors or non-allied sectors */
507 if ((sect.sct_own != player->cnum) &&
508 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
509 pr("(note) An ally does not own the sector %s is in\n",
514 if ((pcp->pl_flags & P_V) == 0) {
515 if (sect.sct_type != SCT_AIRPT) {
516 pr("%s not at airport\n", prplane(&plane));
519 if (sect.sct_effic < 40) {
520 pr("%s is not 40%% efficient, %s can't take off from there.\n", xyas(sect.sct_x, sect.sct_y, plane.pln_own), prplane(&plane));
523 if (rangemult == 2 && sect.sct_effic < 60) {
524 pr("%s is not 60%% efficient, %s can't land there.\n",
525 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
531 pr("%s standing by\n", prplane(&plane));
532 plane.pln_mission = 0;
533 putplane(plane.pln_uid, &plane);
534 plp = malloc(sizeof(struct plist));
539 emp_insque(&plp->queue, list);
544 pln_arm(struct emp_qelem *list, int dist, char mission, struct ichrstr *ip,
545 int flags, int mission_flags)
547 struct emp_qelem *qp;
548 struct emp_qelem *next;
551 for (qp = list->q_forw; qp != list; qp = next) {
553 plp = (struct plist *)qp;
554 if (pln_equip(plp, ip, flags, mission) < 0) {
559 if (flags & (P_S | P_I)) {
560 if (plp->pcp->pl_flags & P_S)
561 mission_flags |= P_S;
562 if (plp->pcp->pl_flags & P_I)
563 mission_flags |= P_I;
565 if (!(plp->pcp->pl_flags & P_H))
566 /* no stealth on this mission */
567 mission_flags &= ~P_H;
568 if (!(plp->pcp->pl_flags & P_X))
569 /* no stealth on this mission */
570 mission_flags &= ~P_X;
571 if (!(plp->pcp->pl_flags & P_A)) {
572 /* no asw on this mission */
573 mission_flags &= ~P_A;
574 /* FIXME escorts turn ASW patrol into ordinary recon */
576 if (!(plp->pcp->pl_flags & P_MINE)) {
577 /* no asw on this mission */
578 mission_flags &= ~P_MINE;
579 /* FIXME no effect */
581 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
582 pr("%s equipped\n", prplane(&plp->plane));
584 return mission_flags;
588 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
590 struct plchrstr *pcp;
604 if (pp->pln_ship >= 0) {
605 getship(pp->pln_ship, &ship);
606 item = ship.shp_item;
608 } else if (pp->pln_land >= 0) {
609 getland(pp->pln_land, &land);
610 item = land.lnd_item;
613 getsect(pp->pln_x, pp->pln_y, §);
614 item = sect.sct_item;
615 own = sect.sct_oldown;
618 if (ip->i_uid == I_CIVIL) {
619 if (pp->pln_own != own) {
620 pr("You don't control those civilians!\n");
625 if (pcp->pl_fuel > item[I_PETROL]) {
626 pr("%s not enough petrol there!\n", prplane(pp));
629 item[I_PETROL] -= pcp->pl_fuel;
631 if ((flags & P_F) == 0) {
637 if (pp->pln_nuketype == -1) {
639 needed = pp->pln_load;
644 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
647 needed = (pp->pln_load * 2) / ip->i_lbs;
650 if ((pcp->pl_flags & P_MINE) == 0)
653 needed = (pp->pln_load * 2) / ip->i_lbs;
656 if ((pcp->pl_flags & (P_V | P_C)) == 0)
659 needed = pp->pln_load / ip->i_lbs;
662 if (pp->pln_nuketype == -1)
668 if (rval < 0 || (itype != I_NONE && needed <= 0)) {
669 pr("%s can't contribute to mission\n", prplane(pp));
672 if (itype != I_NONE) {
674 /* Supply is broken somewhere, so don't use it for now */
675 if (itype == I_SHELL && item[itype] < needed)
676 item[itype] += supply_commod(plp->plane.pln_own,
681 abandon_needed = !!would_abandon(§, itype, needed, NULL);
682 if (item[itype] < needed + abandon_needed) {
683 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
686 item[itype] -= needed;
688 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
693 if (pp->pln_ship >= 0) {
694 if (pp->pln_own != ship.shp_own) {
696 "%s %s prepares for takeoff from ship %s\n",
697 cname(pp->pln_own), prplane(pp), prship(&ship));
699 putship(ship.shp_uid, &ship);
700 } else if (pp->pln_land >= 0) {
701 if (pp->pln_own != land.lnd_own) {
703 "%s %s prepares for takeoff from unit %s\n",
704 cname(pp->pln_own), prplane(pp), prland(&land));
706 putland(land.lnd_uid, &land);
708 if (pp->pln_own != sect.sct_own) {
709 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
710 cname(pp->pln_own), prplane(pp),
711 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
719 pln_put(struct emp_qelem *list)
721 struct emp_qelem *qp;
722 struct emp_qelem *newqp;
728 /* Here is where planes return home from bombing runs.
729 We need to make sure they still have somewhere to return
733 plp = (struct plist *)qp;
735 /* Ok, check out where it wants to land */
736 if (pp->pln_ship >= 0) {
737 /* It is landing on a carrier */
738 getship(pp->pln_ship, &ship);
739 /* We should do more, like make sure it's really
740 a carrier, etc. but for now just make sure it's
742 if (ship.shp_effic < SHIP_MINEFF) {
744 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
745 "splashes into the sea.\n",
746 pp->pln_ship, pp->pln_uid);
750 /* Presume we are landing back in a sector. */
751 getsect(pp->pln_x, pp->pln_y, §);
752 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
754 "Nowhere to land at %s, plane #%d crashes and burns...\n",
755 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
759 putplane(pp->pln_uid, pp);
768 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
770 struct emp_qelem *bomb;
771 struct emp_qelem *esc;
775 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
777 bomb = bomb_list->q_forw;
778 while (bomb != bomb_list) {
779 if (QEMPTY(esc_list)) {
783 esc = esc_list->q_forw;
784 bombp = (struct plist *)bomb;
785 while (esc != esc_list) {
786 escp = (struct plist *)esc;
787 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
799 * Fit a plane of PP's type on ship SP.
800 * Adjust SP's plane counters.
801 * Updating the plane accordingly is the caller's job.
802 * Return whether it fits.
805 fit_plane_on_ship(struct plnstr *pp, struct shpstr *sp)
807 struct plchrstr *pcp = plchr + pp->pln_type;
808 struct mchrstr *mcp = mchr + sp->shp_type;
810 if ((pcp->pl_flags & P_K) && sp->shp_nchoppers < mcp->m_nchoppers)
811 return ++sp->shp_nchoppers;
813 if ((pcp->pl_flags & P_E) && sp->shp_nxlight < mcp->m_nxlight)
814 return ++sp->shp_nxlight;
816 if (!(pcp->pl_flags & P_L))
819 if (((mcp->m_flags & M_FLY)
820 || ((mcp->m_flags & M_MSL) && (pcp->pl_flags & P_M)))
821 && sp->shp_nplane < mcp->m_nplanes)
822 return ++sp->shp_nplane;
828 * Fit a plane of PP's type off ship SP.
829 * Adjust SP's plane counters, badly. You need to run count_planes()
830 * before the next fit_plane_on_ship().
831 * Updating the plane accordingly is the caller's job.
834 fit_plane_off_ship(struct plnstr *pp, struct shpstr *sp)
837 * Frees chopper and nxlight slots first, which is why we need to
838 * run count_planes() before fit_plane_on_ship().
840 struct plchrstr *pcp = plchr + pp->pln_type;
842 if ((pcp->pl_flags & P_K) && sp->shp_nchoppers) {
847 if ((pcp->pl_flags & P_E) && sp->shp_nxlight) {
852 if (CANT_HAPPEN(sp->shp_nplane == 0))
859 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
861 if (plane->pln_ship == ship->shp_uid)
862 return 1; /* Already on ship */
864 if (!fit_plane_on_ship(plane, ship))
867 plane->pln_x = ship->shp_x;
868 plane->pln_y = ship->shp_y;
869 plane->pln_ship = ship->shp_uid;
870 putplane(plane->pln_uid, plane);
871 putship(ship->shp_uid, ship);
876 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
878 if (CANT_HAPPEN(plane->pln_ship != ship->shp_uid))
881 fit_plane_off_ship(plane, ship);
882 plane->pln_ship = -1;
883 putship(ship->shp_uid, ship);
884 putplane(plane->pln_uid, plane);
888 * Fit a plane of PP's type on land unit LP.
889 * Adjust LP's plane counters.
890 * Updating the plane accordingly is the caller's job.
891 * Return whether it fits.
894 fit_plane_on_land(struct plnstr *pp, struct lndstr *lp)
896 struct plchrstr *pcp = plchr + pp->pln_type;
897 struct lchrstr *lcp = lchr + lp->lnd_type;
899 if ((pcp->pl_flags & P_E) && lp->lnd_nxlight < lcp->l_nxlight)
900 return ++lp->lnd_nxlight;
906 * Fit a plane of PP's type off land unit LP.
907 * Adjust LP's plane counters.
908 * Updating the plane accordingly is the caller's job.
911 fit_plane_off_land(struct plnstr *pp, struct lndstr *lp)
913 struct plchrstr *pcp = plchr + pp->pln_type;
915 if (CANT_HAPPEN(lp->lnd_nxlight == 0))
921 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
923 if (plane->pln_land == land->lnd_uid)
924 return 1; /* Already on unit */
926 if (!fit_plane_on_land(plane, land))
929 plane->pln_x = land->lnd_x;
930 plane->pln_y = land->lnd_y;
931 plane->pln_land = land->lnd_uid;
932 putplane(plane->pln_uid, plane);
933 putland(land->lnd_uid, land);
938 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
940 if (CANT_HAPPEN(plane->pln_ship != land->lnd_uid))
943 fit_plane_off_land(plane, land);
944 plane->pln_land = -1;
945 putland(land->lnd_uid, land);
946 putplane(plane->pln_uid, plane);
950 * Could a plane of PP's type be on on ship SP?
953 could_be_on_ship(struct plnstr *pp, struct shpstr *sp)
958 sp->shp_nplane = sp->shp_nchoppers = sp->shp_nxlight = 0;
959 return fit_plane_on_ship(pp, &ship);
963 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
966 struct plchrstr *pcp;
967 struct emp_qelem *qp;
968 struct emp_qelem *next;
974 getsect(x, y, §);
975 mines_there = sect.sct_mines;
977 if (mines_there == 0)
980 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
983 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
986 ip = (struct plist *)qp;
989 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
992 if (chance((100.0 - pp->pln_acc) / 100.0)) {
994 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1000 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1001 writemap(player->cnum);
1002 sect.sct_mines = mines_there;
1007 count_planes(struct shpstr *sp)
1009 struct nstr_item ni;
1010 struct plnstr plane;
1011 int nplane, nchoppers, nxlight;
1013 if (sp->shp_effic < SHIP_MINEFF)
1016 nplane = sp->shp_nplane;
1018 nchoppers = sp->shp_nchoppers;
1019 sp->shp_nchoppers = 0;
1020 nxlight = sp->shp_nxlight;
1021 sp->shp_nxlight = 0;
1023 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1024 while (nxtitem(&ni, &plane)) {
1025 if (plane.pln_own == 0)
1027 if (plane.pln_ship == sp->shp_uid) {
1028 if (!fit_plane_on_ship(&plane, sp))
1033 if (nplane != sp->shp_nplane ||
1034 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1035 putship(sp->shp_uid, sp);
1040 count_land_planes(struct lndstr *lp)
1042 struct nstr_item ni;
1043 struct plnstr plane;
1046 if (lp->lnd_effic < LAND_MINEFF)
1049 nplane = lp->lnd_nxlight;
1050 lp->lnd_nxlight = 0;
1052 snxtitem_all(&ni, EF_PLANE);
1053 while (nxtitem(&ni, &plane)) {
1054 if (plane.pln_own == 0)
1056 if (plane.pln_land == lp->lnd_uid)
1057 if (!fit_plane_on_land(&plane, lp))
1061 if (lp->lnd_nxlight != nplane)
1062 putland(lp->lnd_uid, lp);
1066 count_sect_planes(struct sctstr *sp)
1069 struct nstr_item ni;
1070 struct plnstr plane;
1072 snxtitem_all(&ni, EF_PLANE);
1073 while (nxtitem(&ni, &plane)) {
1076 if (plane.pln_flags & PLN_LAUNCHED)
1078 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1086 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1088 struct plchrstr *pcp = plchr + pp->pln_type;
1089 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
1090 (pp->pln_tech - pcp->pl_tech / 2);
1091 int acc = pp->pln_acc;
1094 if (type == EF_SHIP) {
1095 if (pcp->pl_flags & P_A)
1097 if (!(pcp->pl_flags & P_T))
1100 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1101 (1.0 - acc / 100.0)) - hardtarget;
1103 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1105 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1106 if (hitchance > 100)
1111 /* return 0 if there was a nuclear detonation */
1114 pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
1118 struct plchrstr *pcp = plchr + pp->pln_type;
1126 if (pp->pln_nuketype != -1) {
1127 if (nuk_on_plane(&nuke, pp->pln_uid) >= 0) {
1128 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1129 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1130 pp->pln_nuketype = -1;
1131 *nukedamp = detonate(&nuke, x, y,
1132 pp->pln_flags & PLN_AIRBURST);
1139 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1142 i = roll(pp->pln_load) + 1;
1143 if (i > pp->pln_load)
1146 if (pcp->pl_flags & P_M) {
1147 if (pcp->pl_flags & P_MAR)
1149 } else if (pcp->pl_flags & P_T)
1152 aim = 100 - pp->pln_acc;
1166 hitroll = roll(100);
1167 if (hitroll >= 90) {
1170 mpr(pp->pln_own, "BLAM");
1171 } else if (hitroll < aim) {
1174 mpr(pp->pln_own, "Blam");
1178 mpr(pp->pln_own, "blam");
1181 mpr(pp->pln_own, "-");
1184 mpr(pp->pln_own, "\n");
1191 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1194 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1195 return (int)(100 - 100 * misschance * misschance);
1199 pln_mobcost(int dist, struct plnstr *pp, int flags)
1203 cost = 20.0 / (pp->pln_effic / 100.0);
1204 if ((flags & P_F) || (flags & P_ESC))
1207 return ldround(cost * dist / pp->pln_range_max + 5, 1);
1211 * Set PP's tech to TLEV along with everything else that depends on it.
1214 pln_set_tech(struct plnstr *pp, int tlev)
1216 struct plchrstr *pcp = plchr + pp->pln_type;
1217 int tech_diff = tlev - pcp->pl_tech;
1218 int limited_range = pp->pln_range < pp->pln_range_max;
1220 if (CANT_HAPPEN(tech_diff < 0)) {
1225 pp->pln_tech = tlev;
1226 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1227 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1228 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1229 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1230 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1232 if (!limited_range || pp->pln_range > pp->pln_range_max)
1233 pp->pln_range = pp->pln_range_max;