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
51 #include "prototypes.h"
54 static int pln_equip(struct plist *, struct ichrstr *, int, s_char);
57 * Get assembly point argument.
58 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
59 * If this yields a valid assembly point, read it into *AP_SECT and
61 * Else complain and return NULL.
62 * *AP_SECT and BUF[1024] may be modified in either case.
65 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
72 p = getstarg(input, "assembly point? ", buf);
75 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
78 /* over own or allied sector is fine */
79 if (ap_sect->sct_own == player->cnum
80 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
83 /* over own or allied ship is fine */
84 snxtitem_xy(&ni, EF_SHIP, x, y);
85 while (nxtitem(&ni, &ship)) {
86 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
88 if (ship.shp_own == player->cnum
89 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
93 pr("Assembly point not owned by you or an ally!\n");
98 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
110 nships = carriersatxy(target->sct_x, target->sct_y,
111 M_FLY | M_CHOPPER, 0, player->cnum);
114 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
118 || !getship(cno, &ship)
120 && (getrel(getnatp(ship.shp_own), player->cnum)
125 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
126 pr("Ship #%d not in %s\n", cno,
127 xyas(target->sct_x, target->sct_y, player->cnum));
130 if ((!(mchr[(int)ship.shp_type].m_flags & M_FLY)
131 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
132 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER))
133 || ship.shp_effic < SHP_AIROPS_EFF) {
134 pr("Can't land on %s.\n", prship(&ship));
138 /* clear to land on ship#CNO */
139 pr("landing on carrier %d\n", cno);
140 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
142 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
144 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
152 /* try to land at sector */
153 if (target->sct_own != player->cnum
154 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
155 pr("Nowhere to land at sector %s!\n",
156 xyas(target->sct_x, target->sct_y, player->cnum));
159 if (target->sct_type == SCT_MOUNT) {
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_AIRPT || target->sct_effic < 60)
167 /* clear to land at sector */
174 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
175 struct emp_qelem *esc_list, int cno)
177 struct emp_qelem *list, *qp;
179 struct plchrstr *pcp;
182 int nchoppers, nxlight, nplane;
184 if (cno < 0 || !getship(cno, &ship))
188 nchoppers = ship.shp_nchoppers;
189 nxlight = ship.shp_nxlight;
190 nplane = ship.shp_nplane;
191 mcp = &mchr[(int)ship.shp_type];
194 for (list = bomb_list;
196 list = list == bomb_list ? esc_list : NULL) {
197 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
198 /* FIXME duplicates put_plane_on_ship() logic; refactor */
199 plp = (struct plist *)qp;
200 pcp = &plchr[(int)plp->plane.pln_type];
201 if (plp->plane.pln_ship == ship.shp_uid)
203 /* try chopper space */
204 if ((pcp->pl_flags & P_K) && (mcp->m_flags & M_CHOPPER)
205 && nchoppers < mcp->m_nchoppers)
207 /* try xlight space */
208 else if ((pcp->pl_flags & P_E) && (mcp->m_flags & M_XLIGHT)
209 && nxlight < mcp->m_nxlight)
211 /* try plane space */
212 else if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY))
213 || ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L)
214 && (mcp->m_flags & M_MSL)))
215 && nplane < mcp->m_nplanes)
218 return 0; /* won't be able to land */
225 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
227 struct emp_qelem *qp;
234 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
235 plp = (struct plist *)qp;
238 if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
239 pr("\t%s cannot land on ship #%d! %s aborts!\n",
240 prplane(&plp->plane), cno, prplane(&plp->plane));
241 else if (!put_plane_on_ship(&plp->plane, &ship))
242 pr("\tNo room on ship #%d! %s aborts!\n", cno,
243 prplane(&plp->plane));
245 if (plp->plane.pln_own != ship.shp_own) {
246 /* plp->plane.pln_own = ship.shp_own;*/
248 "%s %s lands on your %s\n",
250 prplane(&plp->plane), prship(&ship));
254 plp->plane.pln_x = tx;
255 plp->plane.pln_y = ty;
256 getsect(tx, ty, §);
257 if (plp->plane.pln_own != sect.sct_own) {
258 /* plp->plane.pln_own = sect.sct_own;*/
260 "%s %s lands at your sector %s\n",
262 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
264 plp->plane.pln_ship = cno;
268 putship(ship.shp_uid, &ship);
272 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
275 struct emp_qelem *qp;
278 struct sctstr *sectp;
287 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
288 plp = (struct plist *)qp;
291 if (type == EF_SECTOR) {
293 if (!sectp->sct_own) {
294 if (sectp->sct_type == SCT_WATER)
295 pr("Your %s sink like a rock!\n", ip->i_name);
297 pr("Your %s vanish without a trace.\n", ip->i_name);
300 if (sectp->sct_own != player->cnum
301 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
302 pr("You don't own %s! Cargo jettisoned...\n",
303 xyas(tx, ty, player->cnum));
306 if (ip->i_vtype == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
307 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
308 xyas(tx, ty, player->cnum));
311 there = sectp->sct_item[ip->i_vtype];
315 there = sp->shp_item[ip->i_vtype];
316 mp = &mchr[(int)sp->shp_type];
317 max = mp->m_item[ip->i_vtype];
321 pr("%d excess %s discarded\n", max - there, ip->i_name);
325 pr("%d %s landed safely", amt, ip->i_name);
326 if (type == EF_SECTOR) {
328 sectp->sct_item[ip->i_vtype] = there;
329 if (sectp->sct_own != player->cnum)
330 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
331 cname(player->cnum), amt, ip->i_name,
332 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
333 pr(" at %s\n", xyas(tx, ty, player->cnum));
334 putsect((struct sctstr *)ptr);
336 struct shpstr *sp = (struct shpstr *)ptr;
337 sp->shp_item[ip->i_vtype] = there;
338 if (sp->shp_own != player->cnum)
339 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
340 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
341 pr(" on carrier #%d\n", sp->shp_uid);
342 putship(sp->shp_uid, sp);
347 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
349 struct emp_qelem *qp;
354 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
355 plp = (struct plist *)qp;
360 if (sectp->sct_type != SCT_WATER) {
361 pr("Your seamines have no effect here.\n");
364 sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
365 pr("%d mines laid in %s.\n", amt,
366 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
367 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
368 writemap(player->cnum);
374 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
375 int ap_to_target, int rangemult, int wantflags, int nowantflags)
382 struct plchrstr *pcp;
389 while (nxtitem(ni, &plane)) {
392 if (plane.pln_mobil <= 0)
395 if (ontradingblock(EF_PLANE, (int *)&plane)) {
396 pr("plane #%d inelligible - it's for sale.\n",
402 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
404 pr("%s too far from assembly point\n", prplane(&plane));
407 if (plane.pln_effic < 40) {
408 pr("%s not efficient enough (must be 40%%)\n",
412 range += ap_to_target;
413 pcp = &plchr[(int)plane.pln_type];
417 for (x = 0; x < sizeof(wantflags) * 8; x++) {
419 if ((wantflags & y) == y)
420 if ((pcp->pl_flags & y) != y) {
439 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
443 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
445 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
447 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
456 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
458 if ((nowantflags & y) == y)
459 if ((pcp->pl_flags & y) == y)
466 if (plane.pln_range < range) {
467 pr("%s out of range (%d:%d)\n", prplane(&plane),
468 plane.pln_range, range);
471 if (plane.pln_ship >= 0) {
472 if (!getship(plane.pln_ship, &ship) ||
473 plane.pln_own != player->cnum) {
476 pr("(note) ship not valid for %s\n", prplane(&plane));
477 putplane(plane.pln_uid, &plane);
480 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
482 if (ship.shp_effic < SHIP_MINEFF)
484 if (ship.shp_effic < SHP_AIROPS_EFF)
486 /* Can't fly off non-owned ships or non-allied ship */
487 if ((ship.shp_own != player->cnum) &&
488 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
489 pr("(note) An ally does not own the ship %s is on\n",
494 if (plane.pln_land >= 0) {
495 if (!getland(plane.pln_land, &land) ||
496 (plane.pln_own != player->cnum)) {
499 pr("(note) land unit not valid for %s\n", prplane(&plane));
500 putplane(plane.pln_uid, &plane);
503 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
505 if (land.lnd_effic < LAND_MINEFF)
507 if (land.lnd_effic < LND_AIROPS_EFF)
509 /* Can't fly off units in ships or other units */
510 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
512 /* Can't fly off non-owned units or non-allied unit */
513 if ((land.lnd_own != player->cnum) &&
514 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
515 pr("(note) An ally does not own the unit %s is on\n",
520 /* Now, check the sector status if not on a plane or unit */
521 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
522 if (!getsect(plane.pln_x, plane.pln_y, §))
524 /* First, check allied status */
525 /* Can't fly from non-owned sectors or non-allied sectors */
526 if ((sect.sct_own != player->cnum) &&
527 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
528 pr("(note) An ally does not own the sector %s is in\n",
533 if ((pcp->pl_flags & P_V) == 0) {
534 if (sect.sct_type != SCT_AIRPT) {
535 pr("%s not at airport\n", prplane(&plane));
538 if (sect.sct_effic < 40) {
539 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));
542 if (rangemult == 2 && sect.sct_effic < 60) {
543 pr("%s is not 60%% efficient, %s can't land there.\n",
544 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
550 pr("%s standing by\n", prplane(&plane));
551 plane.pln_mission = 0;
552 putplane(plane.pln_uid, &plane);
553 plp = malloc(sizeof(struct plist));
558 emp_insque(&plp->queue, list);
563 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
564 int flags, int mission_flags)
566 struct emp_qelem *qp;
567 struct emp_qelem *next;
570 for (qp = list->q_forw; qp != list; qp = next) {
572 plp = (struct plist *)qp;
573 if (pln_equip(plp, ip, flags, mission) < 0) {
578 if (flags & (P_S | P_I)) {
579 if (plp->pcp->pl_flags & P_S)
580 mission_flags |= P_S;
581 if (plp->pcp->pl_flags & P_I)
582 mission_flags |= P_I;
584 if (!(plp->pcp->pl_flags & P_H))
585 /* no stealth on this mission */
586 mission_flags &= ~P_H;
587 if (!(plp->pcp->pl_flags & P_X))
588 /* no stealth on this mission */
589 mission_flags &= ~P_X;
590 if (!(plp->pcp->pl_flags & P_A)) {
591 /* no asw on this mission */
592 mission_flags &= ~P_A;
594 if (!(plp->pcp->pl_flags & P_MINE)) {
595 /* no asw on this mission */
596 mission_flags &= ~P_MINE;
598 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
599 pr("%s equipped\n", prplane(&plp->plane));
601 return mission_flags;
605 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
607 struct plchrstr *pcp;
621 if (pp->pln_ship >= 0) {
622 getship(pp->pln_ship, &ship);
623 item = ship.shp_item;
625 } else if (pp->pln_land >= 0) {
626 getland(pp->pln_land, &land);
627 item = land.lnd_item;
630 getsect(pp->pln_x, pp->pln_y, §);
631 item = sect.sct_item;
632 own = sect.sct_oldown;
635 if (ip->i_vtype == I_CIVIL) {
636 if (pp->pln_own != own) {
637 pr("You don't control those civilians!\n");
642 if (pcp->pl_fuel > item[I_PETROL]) {
643 pr("%s not enough petrol there!\n", prplane(pp));
646 item[I_PETROL] -= pcp->pl_fuel;
648 if ((flags & P_F) == 0) {
654 if (pp->pln_nuketype == -1) {
656 needed = pp->pln_load;
661 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
664 needed = (pp->pln_load * 2) / ip->i_lbs;
667 if ((pcp->pl_flags & P_MINE) == 0)
670 needed = (pp->pln_load * 2) / ip->i_lbs;
673 if ((pcp->pl_flags & (P_V | P_C)) == 0)
676 needed = pp->pln_load / ip->i_lbs;
679 if (pp->pln_nuketype == -1)
685 if (rval < 0 || (itype != I_NONE && needed <= 0)) {
686 pr("%s can't contribute to mission\n", prplane(pp));
689 if (itype != I_NONE) {
691 /* Supply is broken somewhere, so don't use it for now */
692 if (itype == I_SHELL && item[itype] < needed)
693 item[itype] += supply_commod(plp->plane.pln_own,
698 abandon_needed = !!would_abandon(§, itype, needed, NULL);
699 if (item[itype] < needed + abandon_needed) {
700 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
703 item[itype] -= needed;
705 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
710 if (pp->pln_ship >= 0) {
711 if (pp->pln_own != ship.shp_own) {
713 "%s %s prepares for takeoff from ship %s\n",
714 cname(pp->pln_own), prplane(pp), prship(&ship));
716 putship(ship.shp_uid, &ship);
717 } else if (pp->pln_land >= 0) {
718 if (pp->pln_own != land.lnd_own) {
720 "%s %s prepares for takeoff from unit %s\n",
721 cname(pp->pln_own), prplane(pp), prland(&land));
723 putland(land.lnd_uid, &land);
725 if (pp->pln_own != sect.sct_own) {
726 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
727 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
737 pln_put(struct emp_qelem *list)
739 struct emp_qelem *qp;
740 struct emp_qelem *newqp;
746 /* Here is where planes return home from bombing runs.
747 We need to make sure they still have somewhere to return
751 plp = (struct plist *)qp;
753 /* Ok, check out where it wants to land */
754 if (pp->pln_ship >= 0) {
755 /* It is landing on a carrier */
756 getship(pp->pln_ship, &ship);
757 /* We should do more, like make sure it's really
758 a carrier, etc. but for now just make sure it's
760 if (ship.shp_effic < SHIP_MINEFF) {
762 "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n",
763 pp->pln_ship, pp->pln_uid);
767 /* Presume we are landing back in a sector. */
768 getsect(pp->pln_x, pp->pln_y, §);
769 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
771 "Nowhere to land at %s, plane #%d crashes and burns...\n",
772 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
776 putplane(pp->pln_uid, pp);
785 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
787 struct emp_qelem *bomb;
788 struct emp_qelem *esc;
792 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
794 bomb = bomb_list->q_forw;
795 while (bomb != bomb_list) {
796 if (QEMPTY(esc_list)) {
800 esc = esc_list->q_forw;
801 bombp = (struct plist *)bomb;
802 while (esc != esc_list) {
803 escp = (struct plist *)esc;
804 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
816 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
818 struct plchrstr *pcp;
821 pcp = &plchr[(int)plane->pln_type];
822 mcp = &mchr[(int)ship->shp_type];
824 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
825 return 1; /* Already on ship */
827 /* Try to put on ship as a chopper plane */
828 if ((pcp->pl_flags & P_K) &&
829 (mcp->m_flags & M_CHOPPER) &&
830 (ship->shp_nchoppers < mcp->m_nchoppers)) {
832 ship->shp_nchoppers++;
833 plane->pln_x = ship->shp_x;
834 plane->pln_y = ship->shp_y;
835 plane->pln_ship = ship->shp_uid;
836 putship(ship->shp_uid, ship);
837 putplane(plane->pln_uid, plane);
841 /* Try to put on ship as an xlight plane */
842 if ((pcp->pl_flags & P_E) &&
843 (mcp->m_flags & M_XLIGHT) &&
844 (ship->shp_nxlight < mcp->m_nxlight)) {
847 plane->pln_x = ship->shp_x;
848 plane->pln_y = ship->shp_y;
849 plane->pln_ship = ship->shp_uid;
850 putship(ship->shp_uid, ship);
851 putplane(plane->pln_uid, plane);
855 /* Try to put on ship as a normal plane */
856 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
857 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
858 (mcp->m_flags & M_MSL))) &&
859 (ship->shp_nplane < mcp->m_nplanes)) {
862 plane->pln_x = ship->shp_x;
863 plane->pln_y = ship->shp_y;
864 plane->pln_ship = ship->shp_uid;
865 putship(ship->shp_uid, ship);
866 putplane(plane->pln_uid, plane);
875 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
877 struct plchrstr *pcp;
880 pcp = &plchr[(int)plane->pln_type];
881 mcp = &mchr[(int)ship->shp_type];
883 /* Try to take off ship as a chopper plane */
884 if ((pcp->pl_flags & P_K) &&
885 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
887 ship->shp_nchoppers--;
888 plane->pln_ship = -1;
889 putship(ship->shp_uid, ship);
890 putplane(plane->pln_uid, plane);
894 /* Try to take off ship as an xlight plane */
895 if ((pcp->pl_flags & P_E) &&
896 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
899 plane->pln_ship = -1;
900 putship(ship->shp_uid, ship);
901 putplane(plane->pln_uid, plane);
905 /* Try to take off ship as a normal plane */
906 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
907 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
908 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
911 plane->pln_ship = -1;
912 putship(ship->shp_uid, ship);
913 putplane(plane->pln_uid, plane);
922 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
924 struct plchrstr *pcp;
927 pcp = &plchr[(int)plane->pln_type];
928 lcp = &lchr[(int)land->lnd_type];
930 /* Try to take off ship as an xlight plane */
931 if ((pcp->pl_flags & P_E) &&
932 (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) {
935 plane->pln_land = -1;
936 putland(land->lnd_uid, land);
937 putplane(plane->pln_uid, plane);
946 can_be_on_ship(int p, int s)
950 struct plchrstr *pcp;
956 pcp = &plchr[(int)plane.pln_type];
957 mcp = &mchr[(int)ship.shp_type];
959 if (pcp->pl_flags & P_L)
960 if (mcp->m_flags & M_FLY)
963 if (pcp->pl_flags & P_K)
964 if (mcp->m_flags & M_CHOPPER)
967 if (pcp->pl_flags & P_M)
968 if (mcp->m_flags & M_MSL)
971 if (pcp->pl_flags & P_E)
972 if (mcp->m_flags & M_XLIGHT)
979 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
982 struct plchrstr *pcp;
983 struct emp_qelem *qp;
984 struct emp_qelem *next;
990 getsect(x, y, §);
991 mines_there = sect.sct_mines;
993 if (mines_there == 0)
996 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
999 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
1002 ip = (struct plist *)qp;
1005 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
1008 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
1009 pr("Sweep! in %s\n",
1010 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1016 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1017 writemap(player->cnum);
1018 sect.sct_mines = mines_there;
1023 count_planes(struct shpstr *sp)
1025 struct nstr_item ni;
1026 struct plnstr plane;
1027 struct plchrstr *pcp;
1028 struct mchrstr *mcp;
1033 if (sp->shp_effic < SHIP_MINEFF)
1036 mcp = &mchr[(int)sp->shp_type];
1037 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1038 while (nxtitem(&ni, &plane)) {
1039 if (plane.pln_own == 0)
1041 if (plane.pln_ship == sp->shp_uid) {
1042 pcp = &plchr[(int)plane.pln_type];
1043 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
1045 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
1047 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
1052 if (nplane != sp->shp_nplane ||
1053 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1054 sp->shp_nplane = nplane;
1055 sp->shp_nxlight = nxlight;
1056 sp->shp_nchoppers = nchoppers;
1057 putship(sp->shp_uid, sp);
1062 count_land_planes(struct lndstr *lp)
1064 struct nstr_item ni;
1065 struct plnstr plane;
1068 if (lp->lnd_effic < LAND_MINEFF)
1071 snxtitem_all(&ni, EF_PLANE);
1072 while (nxtitem(&ni, &plane)) {
1073 if (plane.pln_own == 0)
1075 if (plane.pln_land == lp->lnd_uid)
1079 if (lp->lnd_nxlight != nplane) {
1080 lp->lnd_nxlight = nplane;
1081 putland(lp->lnd_uid, lp);
1086 count_sect_planes(struct sctstr *sp)
1089 struct nstr_item ni;
1090 struct plnstr plane;
1092 snxtitem_all(&ni, EF_PLANE);
1093 while (nxtitem(&ni, &plane)) {
1096 if (plane.pln_flags & PLN_LAUNCHED)
1098 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1106 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1108 struct plchrstr *pcp;
1109 struct lchrstr *lcp;
1111 pcp = &plchr[(int)plane->pln_type];
1112 lcp = &lchr[(int)land->lnd_type];
1114 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1115 return 1; /* Already on unit */
1117 /* Try to put on unit as an xlight plane */
1118 if ((pcp->pl_flags & P_E) &&
1119 (lcp->l_flags & L_XLIGHT) &&
1120 (land->lnd_nxlight < lcp->l_nxlight)) {
1122 land->lnd_nxlight++;
1123 plane->pln_x = land->lnd_x;
1124 plane->pln_y = land->lnd_y;
1125 plane->pln_land = land->lnd_uid;
1126 putland(land->lnd_uid, land);
1127 putplane(plane->pln_uid, plane);
1131 /* We have failed */
1136 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1138 struct plchrstr *pcp = plchr + pp->pln_type;
1139 float tfact = (float)(pp->pln_tech - pcp->pl_tech) /
1140 (pp->pln_tech - pcp->pl_tech / 2);
1141 int acc = pp->pln_acc;
1144 if (type == EF_SHIP) {
1145 if (pcp->pl_flags & P_A)
1147 if (!(pcp->pl_flags & P_T))
1150 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1151 (1.0 - (float)acc / 100.0)) - hardtarget;
1153 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1155 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1156 if (hitchance > 100)
1161 /* return 0 if there was a nuclear detonation */
1164 pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp,
1167 struct plchrstr *pcp = plchr + pp->pln_type;
1175 if (pp->pln_nuketype != -1) {
1176 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1177 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1178 *nukedamp = detonate(pp, x, y);
1183 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1186 i = roll(pp->pln_load) + 1;
1187 if (i > pp->pln_load)
1190 if (pcp->pl_flags & P_M) {
1191 if (pcp->pl_flags & P_MAR)
1193 } else if (pcp->pl_flags & P_T)
1196 aim = 100 - pp->pln_acc;
1210 hitroll = roll(100);
1211 if (hitroll >= 90) {
1214 mpr(pp->pln_own, "BLAM");
1215 } else if (hitroll < aim) {
1218 mpr(pp->pln_own, "Blam");
1222 mpr(pp->pln_own, "blam");
1225 mpr(pp->pln_own, "-");
1228 mpr(pp->pln_own, "\n");
1235 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1238 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1239 return (int)(100 - 100 * misschance * misschance);
1243 pln_mobcost(int dist, struct plnstr *pp, int flags)
1247 if ((flags & P_F) || (flags & P_ESC))
1248 cost = 10 * 100 / pp->pln_effic;
1250 cost = 20 * 100 / pp->pln_effic;
1252 cost = ldround((double)cost * dist / pp->pln_range_max, 1);
1254 return min(32 + pp->pln_mobil, cost + 5);
1258 * Set PP's tech to TLEV along with everything else that depends on it.
1261 pln_set_tech(struct plnstr *pp, int tlev)
1263 struct plchrstr *pcp = plchr + pp->pln_type;
1264 int tech_diff = tlev - pcp->pl_tech;
1265 int limited_range = pp->pln_range < pp->pln_range_max;
1267 if (CANT_HAPPEN(tech_diff < 0)) {
1272 pp->pln_tech = tlev;
1273 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1274 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1275 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1276 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1277 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1279 if (!limited_range || pp->pln_range > pp->pln_range_max)
1280 pp->pln_range = pp->pln_range_max;