2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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
49 #include "prototypes.h"
52 static int pln_equip(struct plist *, struct ichrstr *, int, s_char);
55 * Get assembly point argument.
56 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
57 * If this yields a valid assembly point, read it into *AP_SECT and
59 * Else complain and return NULL.
60 * *AP_SECT and BUF[1024] may be modified in either case.
63 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
70 p = getstarg(input, "assembly point? ", buf);
73 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
76 /* over own or allied sector is fine */
77 if (ap_sect->sct_own == player->cnum
78 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
81 /* over own or allied ship is fine */
82 snxtitem_xy(&ni, EF_SHIP, x, y);
83 while (nxtitem(&ni, &ship)) {
84 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
86 if (ship.shp_own == player->cnum
87 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
91 pr("Assembly point not owned by you or an ally!\n");
96 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
108 nships = carriersatxy(target->sct_x, target->sct_y,
109 M_FLY | M_CHOPPER, 0, player->cnum);
112 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
116 || !getship(cno, &ship)
118 && (getrel(getnatp(ship.shp_own), player->cnum)
123 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
124 pr("Ship #%d not in %s\n", cno,
125 xyas(target->sct_x, target->sct_y, player->cnum));
128 if ((!(mchr[(int)ship.shp_type].m_flags & M_FLY)
129 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
130 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER))
131 || ship.shp_effic < SHP_AIROPS_EFF) {
132 pr("Can't land on %s.\n", prship(&ship));
136 /* clear to land on ship#CNO */
137 pr("landing on carrier %d\n", cno);
138 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
140 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
142 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
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;
177 struct plchrstr *pcp;
180 int nchoppers, nxlight, nplane;
182 if (cno < 0 || !getship(cno, &ship))
186 nchoppers = ship.shp_nchoppers;
187 nxlight = ship.shp_nxlight;
188 nplane = ship.shp_nplane;
189 mcp = &mchr[(int)ship.shp_type];
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 /* FIXME duplicates put_plane_on_ship() logic; refactor */
197 plp = (struct plist *)qp;
198 pcp = &plchr[(int)plp->plane.pln_type];
199 if (plp->plane.pln_ship == ship.shp_uid)
201 /* try chopper space */
202 if ((pcp->pl_flags & P_K) && (mcp->m_flags & M_CHOPPER)
203 && nchoppers < mcp->m_nchoppers)
205 /* try xlight space */
206 else if ((pcp->pl_flags & P_E) && (mcp->m_flags & M_XLIGHT)
207 && nxlight < mcp->m_nxlight)
209 /* try plane space */
210 else if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY))
211 || ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L)
212 && (mcp->m_flags & M_MSL)))
213 && nplane < mcp->m_nplanes)
216 return 0; /* won't be able to land */
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 (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
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", cno,
241 prplane(&plp->plane));
243 if (plp->plane.pln_own != ship.shp_own) {
244 /* plp->plane.pln_own = ship.shp_own;*/
246 "%s %s lands on your %s\n",
248 prplane(&plp->plane), prship(&ship));
252 plp->plane.pln_x = tx;
253 plp->plane.pln_y = ty;
254 getsect(tx, ty, §);
255 if (plp->plane.pln_own != sect.sct_own) {
256 /* plp->plane.pln_own = sect.sct_own;*/
258 "%s %s lands at your sector %s\n",
260 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
262 plp->plane.pln_ship = cno;
266 putship(ship.shp_uid, &ship);
270 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
273 struct emp_qelem *qp;
276 struct sctstr *sectp;
285 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
286 plp = (struct plist *)qp;
289 if (type == EF_SECTOR) {
291 if (!sectp->sct_own) {
292 if (sectp->sct_type == SCT_WATER)
293 pr("Your %s sink like a rock!\n", ip->i_name);
295 pr("Your %s vanish without a trace.\n", ip->i_name);
298 if (sectp->sct_own != player->cnum
299 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
300 pr("You don't own %s! Cargo jettisoned...\n",
301 xyas(tx, ty, player->cnum));
304 if (ip->i_vtype == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
305 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
306 xyas(tx, ty, player->cnum));
309 there = sectp->sct_item[ip->i_vtype];
313 there = sp->shp_item[ip->i_vtype];
314 mp = &mchr[(int)sp->shp_type];
315 max = mp->m_item[ip->i_vtype];
319 pr("%d excess %s discarded\n", max - there, ip->i_name);
323 pr("%d %s landed safely", amt, ip->i_name);
324 if (type == EF_SECTOR) {
326 sectp->sct_item[ip->i_vtype] = there;
327 if (sectp->sct_own != player->cnum)
328 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
329 cname(player->cnum), amt, ip->i_name,
330 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
331 pr(" at %s\n", xyas(tx, ty, player->cnum));
332 putsect((struct sctstr *)ptr);
334 struct shpstr *sp = (struct shpstr *)ptr;
335 sp->shp_item[ip->i_vtype] = there;
336 if (sp->shp_own != player->cnum)
337 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
338 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
339 pr(" on carrier #%d\n", sp->shp_uid);
340 putship(sp->shp_uid, sp);
345 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
347 struct emp_qelem *qp;
352 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
353 plp = (struct plist *)qp;
358 sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
359 pr("%d mines laid in %s.\n", amt,
360 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
361 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
362 writemap(player->cnum);
368 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
369 int ap_to_target, int rangemult, int wantflags, int nowantflags)
376 struct plchrstr *pcp;
383 while (nxtitem(ni, &plane)) {
386 if (plane.pln_mobil <= 0)
389 if (ontradingblock(EF_PLANE, (int *)&plane)) {
390 pr("plane #%d inelligible - it's for sale.\n",
396 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
398 pr("%s too far from assembly point\n", prplane(&plane));
401 if (plane.pln_effic < 40) {
402 pr("%s not efficient enough (must be 40%%)\n",
406 range += ap_to_target;
407 pcp = &plchr[(int)plane.pln_type];
411 for (x = 0; x < sizeof(wantflags) * 8; x++) {
413 if ((wantflags & y) == y)
414 if ((pcp->pl_flags & y) != y) {
433 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
437 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
439 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
441 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
450 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
452 if ((nowantflags & y) == y)
453 if ((pcp->pl_flags & y) == y)
460 if (plane.pln_range < range) {
461 pr("%s out of range (%d:%d)\n", prplane(&plane),
462 plane.pln_range, range);
465 if (plane.pln_ship >= 0) {
466 if (!getship(plane.pln_ship, &ship) ||
467 plane.pln_own != player->cnum) {
470 pr("(note) ship not valid for %s\n", prplane(&plane));
471 putplane(plane.pln_uid, &plane);
474 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
476 if (ship.shp_effic < SHIP_MINEFF)
478 if (ship.shp_effic < SHP_AIROPS_EFF)
480 /* Can't fly off non-owned ships or non-allied ship */
481 if ((ship.shp_own != player->cnum) &&
482 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
483 pr("(note) An ally does not own the ship %s is on\n",
488 if (plane.pln_land >= 0) {
489 if (!getland(plane.pln_land, &land) ||
490 (plane.pln_own != player->cnum)) {
493 pr("(note) land unit not valid for %s\n", prplane(&plane));
494 putplane(plane.pln_uid, &plane);
497 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
499 if (land.lnd_effic < LAND_MINEFF)
501 if (land.lnd_effic < LND_AIROPS_EFF)
503 /* Can't fly off units in ships or other units */
504 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
506 /* Can't fly off non-owned units or non-allied unit */
507 if ((land.lnd_own != player->cnum) &&
508 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
509 pr("(note) An ally does not own the unit %s is on\n",
514 /* Now, check the sector status if not on a plane or unit */
515 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
516 if (!getsect(plane.pln_x, plane.pln_y, §))
518 /* First, check allied status */
519 /* Can't fly from non-owned sectors or non-allied sectors */
520 if ((sect.sct_own != player->cnum) &&
521 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
522 pr("(note) An ally does not own the sector %s is in\n",
527 if ((pcp->pl_flags & P_V) == 0) {
528 if (sect.sct_type != SCT_AIRPT) {
529 pr("%s not at airport\n", prplane(&plane));
532 if (sect.sct_effic < 40) {
533 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));
536 if (rangemult == 2 && sect.sct_effic < 60) {
537 pr("%s is not 60%% efficient, %s can't land there.\n",
538 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
544 pr("%s standing by\n", prplane(&plane));
545 plane.pln_mission = 0;
546 putplane(plane.pln_uid, &plane);
547 plp = malloc(sizeof(struct plist));
552 emp_insque(&plp->queue, list);
557 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
558 int flags, int mission_flags)
560 struct emp_qelem *qp;
561 struct emp_qelem *next;
564 for (qp = list->q_forw; qp != list; qp = next) {
566 plp = (struct plist *)qp;
567 if (pln_equip(plp, ip, flags, mission) < 0) {
572 if (flags & (P_S | P_I)) {
573 if (plp->pcp->pl_flags & P_S)
574 mission_flags |= P_S;
575 if (plp->pcp->pl_flags & P_I)
576 mission_flags |= P_I;
578 if (!(plp->pcp->pl_flags & P_H))
579 /* no stealth on this mission */
580 mission_flags &= ~P_H;
581 if (!(plp->pcp->pl_flags & P_X))
582 /* no stealth on this mission */
583 mission_flags &= ~P_X;
584 if (!(plp->pcp->pl_flags & P_A)) {
585 /* no asw on this mission */
586 mission_flags &= ~P_A;
588 if (!(plp->pcp->pl_flags & P_MINE)) {
589 /* no asw on this mission */
590 mission_flags &= ~P_MINE;
592 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
593 pr("%s equipped\n", prplane(&plp->plane));
595 return mission_flags;
599 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
601 struct plchrstr *pcp;
614 if (pp->pln_ship >= 0) {
615 getship(pp->pln_ship, &ship);
616 item = ship.shp_item;
618 } else if (pp->pln_land >= 0) {
619 getland(pp->pln_land, &land);
620 item = land.lnd_item;
623 getsect(pp->pln_x, pp->pln_y, §);
624 item = sect.sct_item;
625 own = sect.sct_oldown;
628 if (ip->i_vtype == I_CIVIL) {
629 if (pp->pln_own != own) {
630 pr("You don't control those civilians!\n");
635 if (pcp->pl_fuel > item[I_PETROL]) {
636 pr("%s not enough petrol there!\n", prplane(pp));
639 item[I_PETROL] -= pcp->pl_fuel;
641 if ((flags & P_F) == 0) {
647 if (pp->pln_nuketype == -1) {
649 needed = pp->pln_load;
653 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
656 needed = (pp->pln_load * 2) / ip->i_lbs;
660 needed = (pp->pln_load * 2) / ip->i_lbs;
661 /* Is this mine dropping excursion? */
662 if (itype == I_SHELL && (pcp->pl_flags & P_MINE))
664 /* Is this a cargo drop? */
665 if ((pcp->pl_flags & P_C) == 0 || ip == 0) {
672 if ((pcp->pl_flags & (P_V | P_C)) == 0)
675 needed = pp->pln_load / ip->i_lbs;
678 if (pp->pln_nuketype == -1)
684 if (rval < 0 || (itype != I_NONE && needed <= 0)) {
685 pr("%s can't contribute to mission\n", prplane(pp));
688 if (itype != I_NONE) {
690 /* Supply is broken somewhere, so don't use it for now */
691 if (itype == I_SHELL && item[itype] < needed)
692 item[itype] += supply_commod(plp->plane.pln_own,
697 if (item[itype] < needed) {
698 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
701 item[itype] -= needed;
703 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
708 if (pp->pln_ship >= 0) {
709 if (pp->pln_own != ship.shp_own) {
711 "%s %s prepares for takeoff from ship %s\n",
712 cname(pp->pln_own), prplane(pp), prship(&ship));
714 putship(ship.shp_uid, &ship);
715 } else if (pp->pln_land >= 0) {
716 if (pp->pln_own != land.lnd_own) {
718 "%s %s prepares for takeoff from unit %s\n",
719 cname(pp->pln_own), prplane(pp), prland(&land));
721 putland(land.lnd_uid, &land);
723 if (pp->pln_own != sect.sct_own) {
724 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
725 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
735 pln_put(struct emp_qelem *list)
737 struct emp_qelem *qp;
738 struct emp_qelem *newqp;
744 /* Here is where planes return home from bombing runs.
745 We need to make sure they still have somewhere to return
749 plp = (struct plist *)qp;
751 /* Ok, check out where it wants to land */
752 if (pp->pln_ship >= 0) {
753 /* It is landing on a carrier */
754 getship(pp->pln_ship, &ship);
755 /* We should do more, like make sure it's really
756 a carrier, etc. but for now just make sure it's
758 if (ship.shp_effic < SHIP_MINEFF) {
760 "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n",
761 pp->pln_ship, pp->pln_uid);
765 /* Presume we are landing back in a sector. */
766 getsect(pp->pln_x, pp->pln_y, §);
767 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
769 "Nowhere to land at %s, plane #%d crashes and burns...\n",
770 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
774 putplane(pp->pln_uid, pp);
783 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
785 struct emp_qelem *bomb;
786 struct emp_qelem *esc;
790 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
792 bomb = bomb_list->q_forw;
793 while (bomb != bomb_list) {
794 if (QEMPTY(esc_list)) {
798 esc = esc_list->q_forw;
799 bombp = (struct plist *)bomb;
800 while (esc != esc_list) {
801 escp = (struct plist *)esc;
802 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
814 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
816 struct plchrstr *pcp;
819 pcp = &plchr[(int)plane->pln_type];
820 mcp = &mchr[(int)ship->shp_type];
822 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
823 return 1; /* Already on ship */
825 /* Try to put on ship as a chopper plane */
826 if ((pcp->pl_flags & P_K) &&
827 (mcp->m_flags & M_CHOPPER) &&
828 (ship->shp_nchoppers < mcp->m_nchoppers)) {
830 ship->shp_nchoppers++;
831 plane->pln_x = ship->shp_x;
832 plane->pln_y = ship->shp_y;
833 plane->pln_ship = ship->shp_uid;
834 putship(ship->shp_uid, ship);
835 putplane(plane->pln_uid, plane);
839 /* Try to put on ship as an xlight plane */
840 if ((pcp->pl_flags & P_E) &&
841 (mcp->m_flags & M_XLIGHT) &&
842 (ship->shp_nxlight < mcp->m_nxlight)) {
845 plane->pln_x = ship->shp_x;
846 plane->pln_y = ship->shp_y;
847 plane->pln_ship = ship->shp_uid;
848 putship(ship->shp_uid, ship);
849 putplane(plane->pln_uid, plane);
853 /* Try to put on ship as a normal plane */
854 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
855 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
856 (mcp->m_flags & M_MSL))) &&
857 (ship->shp_nplane < mcp->m_nplanes)) {
860 plane->pln_x = ship->shp_x;
861 plane->pln_y = ship->shp_y;
862 plane->pln_ship = ship->shp_uid;
863 putship(ship->shp_uid, ship);
864 putplane(plane->pln_uid, plane);
873 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
875 struct plchrstr *pcp;
878 pcp = &plchr[(int)plane->pln_type];
879 mcp = &mchr[(int)ship->shp_type];
881 /* Try to take off ship as a chopper plane */
882 if ((pcp->pl_flags & P_K) &&
883 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
885 ship->shp_nchoppers--;
886 plane->pln_ship = -1;
887 putship(ship->shp_uid, ship);
888 putplane(plane->pln_uid, plane);
892 /* Try to take off ship as an xlight plane */
893 if ((pcp->pl_flags & P_E) &&
894 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
897 plane->pln_ship = -1;
898 putship(ship->shp_uid, ship);
899 putplane(plane->pln_uid, plane);
903 /* Try to take off ship as a normal plane */
904 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
905 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
906 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
909 plane->pln_ship = -1;
910 putship(ship->shp_uid, ship);
911 putplane(plane->pln_uid, plane);
920 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
922 struct plchrstr *pcp;
925 pcp = &plchr[(int)plane->pln_type];
926 lcp = &lchr[(int)land->lnd_type];
928 /* Try to take off ship as an xlight plane */
929 if ((pcp->pl_flags & P_E) &&
930 (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) {
933 plane->pln_land = -1;
934 putland(land->lnd_uid, land);
935 putplane(plane->pln_uid, plane);
944 can_be_on_ship(int p, int s)
948 struct plchrstr *pcp;
954 pcp = &plchr[(int)plane.pln_type];
955 mcp = &mchr[(int)ship.shp_type];
957 if (pcp->pl_flags & P_L)
958 if (mcp->m_flags & M_FLY)
961 if (pcp->pl_flags & P_K)
962 if (mcp->m_flags & M_CHOPPER)
965 if (pcp->pl_flags & P_M)
966 if (mcp->m_flags & M_MSL)
969 if (pcp->pl_flags & P_E)
970 if (mcp->m_flags & M_XLIGHT)
977 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
980 struct plchrstr *pcp;
981 struct emp_qelem *qp;
982 struct emp_qelem *next;
988 getsect(x, y, §);
989 mines_there = sect.sct_mines;
991 if (mines_there == 0)
994 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
997 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
1000 ip = (struct plist *)qp;
1003 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
1006 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
1007 pr("Sweep! in %s\n",
1008 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1014 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1015 writemap(player->cnum);
1016 sect.sct_mines = mines_there;
1021 count_planes(struct shpstr *sp)
1023 struct nstr_item ni;
1024 struct plnstr plane;
1025 struct plchrstr *pcp;
1026 struct mchrstr *mcp;
1031 if (sp->shp_effic < SHIP_MINEFF)
1034 mcp = &mchr[(int)sp->shp_type];
1035 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1036 while (nxtitem(&ni, &plane)) {
1037 if (plane.pln_own == 0)
1039 if (plane.pln_ship == sp->shp_uid) {
1040 pcp = &plchr[(int)plane.pln_type];
1041 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
1043 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
1045 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
1050 if (nplane != sp->shp_nplane ||
1051 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1052 sp->shp_nplane = nplane;
1053 sp->shp_nxlight = nxlight;
1054 sp->shp_nchoppers = nchoppers;
1055 putship(sp->shp_uid, sp);
1060 count_land_planes(struct lndstr *lp)
1062 struct nstr_item ni;
1063 struct plnstr plane;
1066 if (lp->lnd_effic < LAND_MINEFF)
1069 snxtitem_all(&ni, EF_PLANE);
1070 while (nxtitem(&ni, &plane)) {
1071 if (plane.pln_own == 0)
1073 if (plane.pln_land == lp->lnd_uid)
1077 if (lp->lnd_nxlight != nplane) {
1078 lp->lnd_nxlight = nplane;
1079 putland(lp->lnd_uid, lp);
1084 count_sect_planes(struct sctstr *sp)
1087 struct nstr_item ni;
1088 struct plnstr plane;
1090 snxtitem_all(&ni, EF_PLANE);
1091 while (nxtitem(&ni, &plane)) {
1094 if (plane.pln_flags & PLN_LAUNCHED)
1096 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1104 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1106 struct plchrstr *pcp;
1107 struct lchrstr *lcp;
1109 pcp = &plchr[(int)plane->pln_type];
1110 lcp = &lchr[(int)land->lnd_type];
1112 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1113 return 1; /* Already on unit */
1115 /* Try to put on unit as an xlight plane */
1116 if ((pcp->pl_flags & P_E) &&
1117 (lcp->l_flags & L_XLIGHT) &&
1118 (land->lnd_nxlight < lcp->l_nxlight)) {
1120 land->lnd_nxlight++;
1121 plane->pln_x = land->lnd_x;
1122 plane->pln_y = land->lnd_y;
1123 plane->pln_land = land->lnd_uid;
1124 putland(land->lnd_uid, land);
1125 putplane(plane->pln_uid, plane);
1129 /* We have failed */
1134 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1136 struct plchrstr *pcp = plchr + pp->pln_type;
1137 float tfact = (float)(pp->pln_tech - pcp->pl_tech) /
1138 (pp->pln_tech - pcp->pl_tech / 2);
1139 int acc = pp->pln_acc;
1142 if (type == EF_SHIP) {
1143 if (pcp->pl_flags & P_A)
1145 if (!(pcp->pl_flags & P_T))
1148 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1149 (1.0 - (float)acc / 100.0)) - hardtarget;
1151 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1153 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1154 if (hitchance > 100)
1159 /* return 0 if there was a nuclear detonation */
1162 pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp,
1165 struct plchrstr *pcp = plchr + pp->pln_type;
1173 if (pp->pln_nuketype != -1) {
1174 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1175 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1176 *nukedamp = detonate(pp, x, y);
1181 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1184 i = roll(pp->pln_load) + 1;
1185 if (i > pp->pln_load)
1188 if (pcp->pl_flags & P_M) {
1189 if (pcp->pl_flags & P_MAR)
1191 } else if (pcp->pl_flags & P_T)
1194 aim = 100 - pp->pln_acc;
1208 hitroll = roll(100);
1209 if (hitroll >= 90) {
1212 mpr(pp->pln_own, "BLAM");
1213 } else if (hitroll < aim) {
1216 mpr(pp->pln_own, "Blam");
1220 mpr(pp->pln_own, "blam");
1223 mpr(pp->pln_own, "-");
1226 mpr(pp->pln_own, "\n");
1233 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1236 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1237 return (int)(100 - 100 * misschance * misschance);
1241 pln_mobcost(int dist, struct plnstr *pp, int flags)
1245 if ((flags & P_F) || (flags & P_ESC))
1246 cost = 10 * 100 / pp->pln_effic;
1248 cost = 20 * 100 / pp->pln_effic;
1250 cost = ldround((double)cost * dist / pp->pln_range_max, 1);
1252 return min(32 + pp->pln_mobil, cost + 5);
1256 * Set PP's tech to TLEV along with everything else that depends on it.
1259 pln_set_tech(struct plnstr *pp, int tlev)
1261 struct plchrstr *pcp = plchr + pp->pln_type;
1262 int tech_diff = tlev - pcp->pl_tech;
1263 int limited_range = pp->pln_range < pp->pln_range_max;
1265 if (CANT_HAPPEN(tech_diff < 0)) {
1270 pp->pln_tech = tlev;
1271 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1272 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1273 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1274 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1275 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1277 if (!limited_range || pp->pln_range > pp->pln_range_max)
1278 pp->pln_range = pp->pln_range_max;