2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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
52 #include "prototypes.h"
55 static int pln_equip(struct plist *, struct ichrstr *, int, char);
58 * Get assembly point argument.
59 * If INPUT is not empty, use it, else prompt for more input using PROMPT.
60 * If this yields a valid assembly point, read it into *AP_SECT and
62 * Else complain and return NULL.
63 * *AP_SECT and BUF[1024] may be modified in either case.
66 get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
73 p = getstarg(input, "assembly point? ", buf);
76 if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
79 /* over own or allied sector is fine */
80 if (ap_sect->sct_own == player->cnum
81 || getrel(getnatp(ap_sect->sct_own), player->cnum) == ALLIED)
84 /* over own or allied ship is fine */
85 snxtitem_xy(&ni, EF_SHIP, x, y);
86 while (nxtitem(&ni, &ship)) {
87 if (ship.shp_effic < SHIP_MINEFF || ship.shp_own == 0)
89 if (ship.shp_own == player->cnum
90 || getrel(getnatp(ship.shp_own), player->cnum) == ALLIED)
94 pr("Assembly point not owned by you or an ally!\n");
99 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
111 nships = carriersatxy(target->sct_x, target->sct_y,
112 M_FLY | M_CHOPPER, 0, player->cnum);
115 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
119 || !getship(cno, &ship)
121 && (getrel(getnatp(ship.shp_own), player->cnum)
126 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
127 pr("Ship #%d not in %s\n", cno,
128 xyas(target->sct_x, target->sct_y, player->cnum));
131 if ((!(mchr[(int)ship.shp_type].m_flags & M_FLY)
132 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
133 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER))
134 || ship.shp_effic < SHP_AIROPS_EFF) {
135 pr("Can't land on %s.\n", prship(&ship));
139 /* clear to land on ship#CNO */
140 pr("landing on carrier %d\n", cno);
141 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
143 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
145 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
153 /* try to land at sector */
154 if (target->sct_own != player->cnum
155 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
156 pr("Nowhere to land at sector %s!\n",
157 xyas(target->sct_x, target->sct_y, player->cnum));
160 if (target->sct_type == SCT_MOUNT) {
161 pr("Nowhere to land at sector %s!\n",
162 xyas(target->sct_x, target->sct_y, player->cnum));
165 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
168 /* clear to land at sector */
175 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
176 struct emp_qelem *esc_list, int cno)
178 struct emp_qelem *list, *qp;
180 struct plchrstr *pcp;
183 int nchoppers, nxlight, nplane;
185 if (cno < 0 || !getship(cno, &ship))
189 nchoppers = ship.shp_nchoppers;
190 nxlight = ship.shp_nxlight;
191 nplane = ship.shp_nplane;
192 mcp = &mchr[(int)ship.shp_type];
195 for (list = bomb_list;
197 list = list == bomb_list ? esc_list : NULL) {
198 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
199 /* FIXME duplicates put_plane_on_ship() logic; refactor */
200 plp = (struct plist *)qp;
201 pcp = &plchr[(int)plp->plane.pln_type];
202 if (plp->plane.pln_ship == ship.shp_uid)
204 /* try chopper space */
205 if ((pcp->pl_flags & P_K) && (mcp->m_flags & M_CHOPPER)
206 && nchoppers < mcp->m_nchoppers)
208 /* try xlight space */
209 else if ((pcp->pl_flags & P_E) && (mcp->m_flags & M_XLIGHT)
210 && nxlight < mcp->m_nxlight)
212 /* try plane space */
213 else if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY))
214 || ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L)
215 && (mcp->m_flags & M_MSL)))
216 && nplane < mcp->m_nplanes)
219 return 0; /* won't be able to land */
226 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
228 struct emp_qelem *qp;
235 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
236 plp = (struct plist *)qp;
239 if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
240 pr("\t%s cannot land on ship #%d! %s aborts!\n",
241 prplane(&plp->plane), cno, prplane(&plp->plane));
242 else if (!put_plane_on_ship(&plp->plane, &ship))
243 pr("\tNo room on ship #%d! %s aborts!\n",
244 cno, prplane(&plp->plane));
246 if (plp->plane.pln_own != ship.shp_own) {
247 /* plp->plane.pln_own = ship.shp_own;*/
248 wu(0, ship.shp_own, "%s %s lands on your %s\n",
249 cname(player->cnum), prplane(&plp->plane),
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_uid == 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_uid];
315 there = sp->shp_item[ip->i_uid];
316 mp = &mchr[(int)sp->shp_type];
317 max = mp->m_item[ip->i_uid];
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_uid] = 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_uid] = 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, &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;
414 pcp = &plchr[(int)plane.pln_type];
418 for (x = 0; x < sizeof(wantflags) * 8; x++) {
420 if ((wantflags & y) == y)
421 if ((pcp->pl_flags & y) != y) {
440 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
444 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
446 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
448 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
457 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
459 if ((nowantflags & y) == y)
460 if ((pcp->pl_flags & y) == y)
466 if (plane.pln_range < range) {
467 pr("%s out of range (%d:%d)\n",
468 prplane(&plane), 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, char 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;
593 /* FIXME escorts turn ASW patrol into ordinary recon */
595 if (!(plp->pcp->pl_flags & P_MINE)) {
596 /* no asw on this mission */
597 mission_flags &= ~P_MINE;
598 /* FIXME no effect */
600 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
601 pr("%s equipped\n", prplane(&plp->plane));
603 return mission_flags;
607 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
609 struct plchrstr *pcp;
623 if (pp->pln_ship >= 0) {
624 getship(pp->pln_ship, &ship);
625 item = ship.shp_item;
627 } else if (pp->pln_land >= 0) {
628 getland(pp->pln_land, &land);
629 item = land.lnd_item;
632 getsect(pp->pln_x, pp->pln_y, §);
633 item = sect.sct_item;
634 own = sect.sct_oldown;
637 if (ip->i_uid == I_CIVIL) {
638 if (pp->pln_own != own) {
639 pr("You don't control those civilians!\n");
644 if (pcp->pl_fuel > item[I_PETROL]) {
645 pr("%s not enough petrol there!\n", prplane(pp));
648 item[I_PETROL] -= pcp->pl_fuel;
650 if ((flags & P_F) == 0) {
656 if (pp->pln_nuketype == -1) {
658 needed = pp->pln_load;
663 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
666 needed = (pp->pln_load * 2) / ip->i_lbs;
669 if ((pcp->pl_flags & P_MINE) == 0)
672 needed = (pp->pln_load * 2) / ip->i_lbs;
675 if ((pcp->pl_flags & (P_V | P_C)) == 0)
678 needed = pp->pln_load / ip->i_lbs;
681 if (pp->pln_nuketype == -1)
687 if (rval < 0 || (itype != I_NONE && needed <= 0)) {
688 pr("%s can't contribute to mission\n", prplane(pp));
691 if (itype != I_NONE) {
693 /* Supply is broken somewhere, so don't use it for now */
694 if (itype == I_SHELL && item[itype] < needed)
695 item[itype] += supply_commod(plp->plane.pln_own,
700 abandon_needed = !!would_abandon(§, itype, needed, NULL);
701 if (item[itype] < needed + abandon_needed) {
702 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
705 item[itype] -= needed;
707 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
712 if (pp->pln_ship >= 0) {
713 if (pp->pln_own != ship.shp_own) {
715 "%s %s prepares for takeoff from ship %s\n",
716 cname(pp->pln_own), prplane(pp), prship(&ship));
718 putship(ship.shp_uid, &ship);
719 } else if (pp->pln_land >= 0) {
720 if (pp->pln_own != land.lnd_own) {
722 "%s %s prepares for takeoff from unit %s\n",
723 cname(pp->pln_own), prplane(pp), prland(&land));
725 putland(land.lnd_uid, &land);
727 if (pp->pln_own != sect.sct_own) {
728 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
729 cname(pp->pln_own), prplane(pp),
730 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
738 pln_put(struct emp_qelem *list)
740 struct emp_qelem *qp;
741 struct emp_qelem *newqp;
747 /* Here is where planes return home from bombing runs.
748 We need to make sure they still have somewhere to return
752 plp = (struct plist *)qp;
754 /* Ok, check out where it wants to land */
755 if (pp->pln_ship >= 0) {
756 /* It is landing on a carrier */
757 getship(pp->pln_ship, &ship);
758 /* We should do more, like make sure it's really
759 a carrier, etc. but for now just make sure it's
761 if (ship.shp_effic < SHIP_MINEFF) {
763 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
764 "splashes into the sea.\n",
765 pp->pln_ship, pp->pln_uid);
769 /* Presume we are landing back in a sector. */
770 getsect(pp->pln_x, pp->pln_y, §);
771 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
773 "Nowhere to land at %s, plane #%d crashes and burns...\n",
774 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
778 putplane(pp->pln_uid, pp);
787 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
789 struct emp_qelem *bomb;
790 struct emp_qelem *esc;
794 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
796 bomb = bomb_list->q_forw;
797 while (bomb != bomb_list) {
798 if (QEMPTY(esc_list)) {
802 esc = esc_list->q_forw;
803 bombp = (struct plist *)bomb;
804 while (esc != esc_list) {
805 escp = (struct plist *)esc;
806 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
818 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
820 struct plchrstr *pcp;
823 pcp = &plchr[(int)plane->pln_type];
824 mcp = &mchr[(int)ship->shp_type];
826 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
827 return 1; /* Already on ship */
829 /* Try to put on ship as a chopper plane */
830 if ((pcp->pl_flags & P_K) &&
831 (mcp->m_flags & M_CHOPPER) &&
832 (ship->shp_nchoppers < mcp->m_nchoppers)) {
834 ship->shp_nchoppers++;
835 plane->pln_x = ship->shp_x;
836 plane->pln_y = ship->shp_y;
837 plane->pln_ship = ship->shp_uid;
838 putship(ship->shp_uid, ship);
839 putplane(plane->pln_uid, plane);
843 /* Try to put on ship as an xlight plane */
844 if ((pcp->pl_flags & P_E) &&
845 (mcp->m_flags & M_XLIGHT) &&
846 (ship->shp_nxlight < mcp->m_nxlight)) {
849 plane->pln_x = ship->shp_x;
850 plane->pln_y = ship->shp_y;
851 plane->pln_ship = ship->shp_uid;
852 putship(ship->shp_uid, ship);
853 putplane(plane->pln_uid, plane);
857 /* Try to put on ship as a normal plane */
858 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
859 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
860 (mcp->m_flags & M_MSL))) &&
861 (ship->shp_nplane < mcp->m_nplanes)) {
864 plane->pln_x = ship->shp_x;
865 plane->pln_y = ship->shp_y;
866 plane->pln_ship = ship->shp_uid;
867 putship(ship->shp_uid, ship);
868 putplane(plane->pln_uid, plane);
877 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
879 struct plchrstr *pcp;
882 pcp = &plchr[(int)plane->pln_type];
883 mcp = &mchr[(int)ship->shp_type];
885 /* Try to take off ship as a chopper plane */
886 if ((pcp->pl_flags & P_K) &&
887 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
889 ship->shp_nchoppers--;
890 plane->pln_ship = -1;
891 putship(ship->shp_uid, ship);
892 putplane(plane->pln_uid, plane);
896 /* Try to take off ship as an xlight plane */
897 if ((pcp->pl_flags & P_E) &&
898 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
901 plane->pln_ship = -1;
902 putship(ship->shp_uid, ship);
903 putplane(plane->pln_uid, plane);
907 /* Try to take off ship as a normal plane */
908 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
909 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
910 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
913 plane->pln_ship = -1;
914 putship(ship->shp_uid, ship);
915 putplane(plane->pln_uid, plane);
924 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
926 struct plchrstr *pcp;
928 pcp = &plchr[(int)plane->pln_type];
930 /* Try to take off ship as an xlight plane */
931 if ((pcp->pl_flags & P_E) && land->lnd_nxlight) {
934 plane->pln_land = -1;
935 putland(land->lnd_uid, land);
936 putplane(plane->pln_uid, plane);
945 can_be_on_ship(int p, int s)
949 struct plchrstr *pcp;
955 pcp = &plchr[(int)plane.pln_type];
956 mcp = &mchr[(int)ship.shp_type];
958 if (pcp->pl_flags & P_L)
959 if (mcp->m_flags & M_FLY)
962 if (pcp->pl_flags & P_K)
963 if (mcp->m_flags & M_CHOPPER)
966 if (pcp->pl_flags & P_M)
967 if (mcp->m_flags & M_MSL)
970 if (pcp->pl_flags & P_E)
971 if (mcp->m_flags & M_XLIGHT)
978 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
981 struct plchrstr *pcp;
982 struct emp_qelem *qp;
983 struct emp_qelem *next;
989 getsect(x, y, §);
990 mines_there = sect.sct_mines;
992 if (mines_there == 0)
995 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
998 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
1001 ip = (struct plist *)qp;
1004 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
1007 if (chance((100.0 - pp->pln_acc) / 100.0)) {
1008 pr("Sweep! in %s\n",
1009 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1015 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1016 writemap(player->cnum);
1017 sect.sct_mines = mines_there;
1022 count_planes(struct shpstr *sp)
1024 struct nstr_item ni;
1025 struct plnstr plane;
1026 struct plchrstr *pcp;
1027 struct mchrstr *mcp;
1032 if (sp->shp_effic < SHIP_MINEFF)
1035 mcp = &mchr[(int)sp->shp_type];
1036 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1037 while (nxtitem(&ni, &plane)) {
1038 if (plane.pln_own == 0)
1040 if (plane.pln_ship == sp->shp_uid) {
1041 pcp = &plchr[(int)plane.pln_type];
1042 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
1044 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
1046 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
1051 if (nplane != sp->shp_nplane ||
1052 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1053 sp->shp_nplane = nplane;
1054 sp->shp_nxlight = nxlight;
1055 sp->shp_nchoppers = nchoppers;
1056 putship(sp->shp_uid, sp);
1061 count_land_planes(struct lndstr *lp)
1063 struct nstr_item ni;
1064 struct plnstr plane;
1067 if (lp->lnd_effic < LAND_MINEFF)
1070 snxtitem_all(&ni, EF_PLANE);
1071 while (nxtitem(&ni, &plane)) {
1072 if (plane.pln_own == 0)
1074 if (plane.pln_land == lp->lnd_uid)
1078 if (lp->lnd_nxlight != nplane) {
1079 lp->lnd_nxlight = nplane;
1080 putland(lp->lnd_uid, lp);
1085 count_sect_planes(struct sctstr *sp)
1088 struct nstr_item ni;
1089 struct plnstr plane;
1091 snxtitem_all(&ni, EF_PLANE);
1092 while (nxtitem(&ni, &plane)) {
1095 if (plane.pln_flags & PLN_LAUNCHED)
1097 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1105 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1107 struct plchrstr *pcp;
1109 pcp = &plchr[(int)plane->pln_type];
1111 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1112 return 1; /* Already on unit */
1114 /* Try to put on unit as an xlight plane */
1115 if ((pcp->pl_flags & P_E) &&
1116 (land->lnd_nxlight < land->lnd_maxlight)) {
1118 land->lnd_nxlight++;
1119 plane->pln_x = land->lnd_x;
1120 plane->pln_y = land->lnd_y;
1121 plane->pln_land = land->lnd_uid;
1122 putland(land->lnd_uid, land);
1123 putplane(plane->pln_uid, plane);
1127 /* We have failed */
1132 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1134 struct plchrstr *pcp = plchr + pp->pln_type;
1135 double tfact = (double)(pp->pln_tech - pcp->pl_tech) /
1136 (pp->pln_tech - pcp->pl_tech / 2);
1137 int acc = pp->pln_acc;
1140 if (type == EF_SHIP) {
1141 if (pcp->pl_flags & P_A)
1143 if (!(pcp->pl_flags & P_T))
1146 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1147 (1.0 - acc / 100.0)) - hardtarget;
1149 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1151 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1152 if (hitchance > 100)
1157 /* return 0 if there was a nuclear detonation */
1160 pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
1164 struct plchrstr *pcp = plchr + pp->pln_type;
1172 if (pp->pln_nuketype != -1) {
1173 if (nuk_on_plane(&nuke, pp->pln_uid) >= 0) {
1174 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1175 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1176 pp->pln_nuketype = -1;
1177 *nukedamp = detonate(&nuke, x, y,
1178 pp->pln_flags & PLN_AIRBURST);
1185 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1188 i = roll(pp->pln_load) + 1;
1189 if (i > pp->pln_load)
1192 if (pcp->pl_flags & P_M) {
1193 if (pcp->pl_flags & P_MAR)
1195 } else if (pcp->pl_flags & P_T)
1198 aim = 100 - pp->pln_acc;
1212 hitroll = roll(100);
1213 if (hitroll >= 90) {
1216 mpr(pp->pln_own, "BLAM");
1217 } else if (hitroll < aim) {
1220 mpr(pp->pln_own, "Blam");
1224 mpr(pp->pln_own, "blam");
1227 mpr(pp->pln_own, "-");
1230 mpr(pp->pln_own, "\n");
1237 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1240 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1241 return (int)(100 - 100 * misschance * misschance);
1245 pln_mobcost(int dist, struct plnstr *pp, int flags)
1249 cost = 20.0 / (pp->pln_effic / 100.0);
1250 if ((flags & P_F) || (flags & P_ESC))
1253 return ldround(cost * dist / pp->pln_range_max + 5, 1);
1257 * Set PP's tech to TLEV along with everything else that depends on it.
1260 pln_set_tech(struct plnstr *pp, int tlev)
1262 struct plchrstr *pcp = plchr + pp->pln_type;
1263 int tech_diff = tlev - pcp->pl_tech;
1264 int limited_range = pp->pln_range < pp->pln_range_max;
1266 if (CANT_HAPPEN(tech_diff < 0)) {
1271 pp->pln_tech = tlev;
1272 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1273 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1274 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1275 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1276 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1278 if (!limited_range || pp->pln_range > pp->pln_range_max)
1279 pp->pln_range = pp->pln_range_max;