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", cno,
244 prplane(&plp->plane));
246 if (plp->plane.pln_own != ship.shp_own) {
247 /* plp->plane.pln_own = ship.shp_own;*/
249 "%s %s lands on your %s\n",
251 prplane(&plp->plane), prship(&ship));
255 plp->plane.pln_x = tx;
256 plp->plane.pln_y = ty;
257 getsect(tx, ty, §);
258 if (plp->plane.pln_own != sect.sct_own) {
259 /* plp->plane.pln_own = sect.sct_own;*/
261 "%s %s lands at your sector %s\n",
263 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
265 plp->plane.pln_ship = cno;
269 putship(ship.shp_uid, &ship);
273 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
276 struct emp_qelem *qp;
279 struct sctstr *sectp;
288 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
289 plp = (struct plist *)qp;
292 if (type == EF_SECTOR) {
294 if (!sectp->sct_own) {
295 if (sectp->sct_type == SCT_WATER)
296 pr("Your %s sink like a rock!\n", ip->i_name);
298 pr("Your %s vanish without a trace.\n", ip->i_name);
301 if (sectp->sct_own != player->cnum
302 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
303 pr("You don't own %s! Cargo jettisoned...\n",
304 xyas(tx, ty, player->cnum));
307 if (ip->i_uid == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
308 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
309 xyas(tx, ty, player->cnum));
312 there = sectp->sct_item[ip->i_uid];
316 there = sp->shp_item[ip->i_uid];
317 mp = &mchr[(int)sp->shp_type];
318 max = mp->m_item[ip->i_uid];
322 pr("%d excess %s discarded\n", max - there, ip->i_name);
326 pr("%d %s landed safely", amt, ip->i_name);
327 if (type == EF_SECTOR) {
329 sectp->sct_item[ip->i_uid] = there;
330 if (sectp->sct_own != player->cnum)
331 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
332 cname(player->cnum), amt, ip->i_name,
333 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
334 pr(" at %s\n", xyas(tx, ty, player->cnum));
335 putsect((struct sctstr *)ptr);
337 struct shpstr *sp = (struct shpstr *)ptr;
338 sp->shp_item[ip->i_uid] = there;
339 if (sp->shp_own != player->cnum)
340 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
341 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
342 pr(" on carrier #%d\n", sp->shp_uid);
343 putship(sp->shp_uid, sp);
348 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
350 struct emp_qelem *qp;
355 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
356 plp = (struct plist *)qp;
361 if (sectp->sct_type != SCT_WATER) {
362 pr("Your seamines have no effect here.\n");
365 sectp->sct_mines = MIN(sectp->sct_mines + amt, MINES_MAX);
366 pr("%d mines laid in %s.\n", amt,
367 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
368 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
369 writemap(player->cnum);
375 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
376 int ap_to_target, int rangemult, int wantflags, int nowantflags)
383 struct plchrstr *pcp;
390 while (nxtitem(ni, &plane)) {
393 if (plane.pln_mobil <= 0)
396 if (ontradingblock(EF_PLANE, &plane)) {
397 pr("plane #%d inelligible - it's for sale.\n",
403 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
405 pr("%s too far from assembly point\n", prplane(&plane));
408 if (plane.pln_effic < 40) {
409 pr("%s not efficient enough (must be 40%%)\n",
413 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)
467 if (plane.pln_range < range) {
468 pr("%s out of range (%d:%d)\n", prplane(&plane),
469 plane.pln_range, range);
472 if (plane.pln_ship >= 0) {
473 if (!getship(plane.pln_ship, &ship) ||
474 plane.pln_own != player->cnum) {
477 pr("(note) ship not valid for %s\n", prplane(&plane));
478 putplane(plane.pln_uid, &plane);
481 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
483 if (ship.shp_effic < SHIP_MINEFF)
485 if (ship.shp_effic < SHP_AIROPS_EFF)
487 /* Can't fly off non-owned ships or non-allied ship */
488 if ((ship.shp_own != player->cnum) &&
489 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
490 pr("(note) An ally does not own the ship %s is on\n",
495 if (plane.pln_land >= 0) {
496 if (!getland(plane.pln_land, &land) ||
497 (plane.pln_own != player->cnum)) {
500 pr("(note) land unit not valid for %s\n", prplane(&plane));
501 putplane(plane.pln_uid, &plane);
504 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
506 if (land.lnd_effic < LAND_MINEFF)
508 if (land.lnd_effic < LND_AIROPS_EFF)
510 /* Can't fly off units in ships or other units */
511 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
513 /* Can't fly off non-owned units or non-allied unit */
514 if ((land.lnd_own != player->cnum) &&
515 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
516 pr("(note) An ally does not own the unit %s is on\n",
521 /* Now, check the sector status if not on a plane or unit */
522 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
523 if (!getsect(plane.pln_x, plane.pln_y, §))
525 /* First, check allied status */
526 /* Can't fly from non-owned sectors or non-allied sectors */
527 if ((sect.sct_own != player->cnum) &&
528 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
529 pr("(note) An ally does not own the sector %s is in\n",
534 if ((pcp->pl_flags & P_V) == 0) {
535 if (sect.sct_type != SCT_AIRPT) {
536 pr("%s not at airport\n", prplane(&plane));
539 if (sect.sct_effic < 40) {
540 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));
543 if (rangemult == 2 && sect.sct_effic < 60) {
544 pr("%s is not 60%% efficient, %s can't land there.\n",
545 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
551 pr("%s standing by\n", prplane(&plane));
552 plane.pln_mission = 0;
553 putplane(plane.pln_uid, &plane);
554 plp = malloc(sizeof(struct plist));
559 emp_insque(&plp->queue, list);
564 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
565 int flags, int mission_flags)
567 struct emp_qelem *qp;
568 struct emp_qelem *next;
571 for (qp = list->q_forw; qp != list; qp = next) {
573 plp = (struct plist *)qp;
574 if (pln_equip(plp, ip, flags, mission) < 0) {
579 if (flags & (P_S | P_I)) {
580 if (plp->pcp->pl_flags & P_S)
581 mission_flags |= P_S;
582 if (plp->pcp->pl_flags & P_I)
583 mission_flags |= P_I;
585 if (!(plp->pcp->pl_flags & P_H))
586 /* no stealth on this mission */
587 mission_flags &= ~P_H;
588 if (!(plp->pcp->pl_flags & P_X))
589 /* no stealth on this mission */
590 mission_flags &= ~P_X;
591 if (!(plp->pcp->pl_flags & P_A)) {
592 /* no asw on this mission */
593 mission_flags &= ~P_A;
594 /* FIXME escorts turn ASW patrol into ordinary recon */
596 if (!(plp->pcp->pl_flags & P_MINE)) {
597 /* no asw on this mission */
598 mission_flags &= ~P_MINE;
599 /* FIXME no effect */
601 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
602 pr("%s equipped\n", prplane(&plp->plane));
604 return mission_flags;
608 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
610 struct plchrstr *pcp;
624 if (pp->pln_ship >= 0) {
625 getship(pp->pln_ship, &ship);
626 item = ship.shp_item;
628 } else if (pp->pln_land >= 0) {
629 getland(pp->pln_land, &land);
630 item = land.lnd_item;
633 getsect(pp->pln_x, pp->pln_y, §);
634 item = sect.sct_item;
635 own = sect.sct_oldown;
638 if (ip->i_uid == I_CIVIL) {
639 if (pp->pln_own != own) {
640 pr("You don't control those civilians!\n");
645 if (pcp->pl_fuel > item[I_PETROL]) {
646 pr("%s not enough petrol there!\n", prplane(pp));
649 item[I_PETROL] -= pcp->pl_fuel;
651 if ((flags & P_F) == 0) {
657 if (pp->pln_nuketype == -1) {
659 needed = pp->pln_load;
664 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
667 needed = (pp->pln_load * 2) / ip->i_lbs;
670 if ((pcp->pl_flags & P_MINE) == 0)
673 needed = (pp->pln_load * 2) / ip->i_lbs;
676 if ((pcp->pl_flags & (P_V | P_C)) == 0)
679 needed = pp->pln_load / ip->i_lbs;
682 if (pp->pln_nuketype == -1)
688 if (rval < 0 || (itype != I_NONE && needed <= 0)) {
689 pr("%s can't contribute to mission\n", prplane(pp));
692 if (itype != I_NONE) {
694 /* Supply is broken somewhere, so don't use it for now */
695 if (itype == I_SHELL && item[itype] < needed)
696 item[itype] += supply_commod(plp->plane.pln_own,
701 abandon_needed = !!would_abandon(§, itype, needed, NULL);
702 if (item[itype] < needed + abandon_needed) {
703 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
706 item[itype] -= needed;
708 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
713 if (pp->pln_ship >= 0) {
714 if (pp->pln_own != ship.shp_own) {
716 "%s %s prepares for takeoff from ship %s\n",
717 cname(pp->pln_own), prplane(pp), prship(&ship));
719 putship(ship.shp_uid, &ship);
720 } else if (pp->pln_land >= 0) {
721 if (pp->pln_own != land.lnd_own) {
723 "%s %s prepares for takeoff from unit %s\n",
724 cname(pp->pln_own), prplane(pp), prland(&land));
726 putland(land.lnd_uid, &land);
728 if (pp->pln_own != sect.sct_own) {
729 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
730 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
740 pln_put(struct emp_qelem *list)
742 struct emp_qelem *qp;
743 struct emp_qelem *newqp;
749 /* Here is where planes return home from bombing runs.
750 We need to make sure they still have somewhere to return
754 plp = (struct plist *)qp;
756 /* Ok, check out where it wants to land */
757 if (pp->pln_ship >= 0) {
758 /* It is landing on a carrier */
759 getship(pp->pln_ship, &ship);
760 /* We should do more, like make sure it's really
761 a carrier, etc. but for now just make sure it's
763 if (ship.shp_effic < SHIP_MINEFF) {
765 "Ship #%d has been sunk, plane #%d has nowhere to land, and\n"
766 "splashes into the sea.\n",
767 pp->pln_ship, pp->pln_uid);
771 /* Presume we are landing back in a sector. */
772 getsect(pp->pln_x, pp->pln_y, §);
773 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
775 "Nowhere to land at %s, plane #%d crashes and burns...\n",
776 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
780 putplane(pp->pln_uid, pp);
789 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
791 struct emp_qelem *bomb;
792 struct emp_qelem *esc;
796 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
798 bomb = bomb_list->q_forw;
799 while (bomb != bomb_list) {
800 if (QEMPTY(esc_list)) {
804 esc = esc_list->q_forw;
805 bombp = (struct plist *)bomb;
806 while (esc != esc_list) {
807 escp = (struct plist *)esc;
808 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
820 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
822 struct plchrstr *pcp;
825 pcp = &plchr[(int)plane->pln_type];
826 mcp = &mchr[(int)ship->shp_type];
828 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
829 return 1; /* Already on ship */
831 /* Try to put on ship as a chopper plane */
832 if ((pcp->pl_flags & P_K) &&
833 (mcp->m_flags & M_CHOPPER) &&
834 (ship->shp_nchoppers < mcp->m_nchoppers)) {
836 ship->shp_nchoppers++;
837 plane->pln_x = ship->shp_x;
838 plane->pln_y = ship->shp_y;
839 plane->pln_ship = ship->shp_uid;
840 putship(ship->shp_uid, ship);
841 putplane(plane->pln_uid, plane);
845 /* Try to put on ship as an xlight plane */
846 if ((pcp->pl_flags & P_E) &&
847 (mcp->m_flags & M_XLIGHT) &&
848 (ship->shp_nxlight < mcp->m_nxlight)) {
851 plane->pln_x = ship->shp_x;
852 plane->pln_y = ship->shp_y;
853 plane->pln_ship = ship->shp_uid;
854 putship(ship->shp_uid, ship);
855 putplane(plane->pln_uid, plane);
859 /* Try to put on ship as a normal plane */
860 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
861 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
862 (mcp->m_flags & M_MSL))) &&
863 (ship->shp_nplane < mcp->m_nplanes)) {
866 plane->pln_x = ship->shp_x;
867 plane->pln_y = ship->shp_y;
868 plane->pln_ship = ship->shp_uid;
869 putship(ship->shp_uid, ship);
870 putplane(plane->pln_uid, plane);
879 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
881 struct plchrstr *pcp;
884 pcp = &plchr[(int)plane->pln_type];
885 mcp = &mchr[(int)ship->shp_type];
887 /* Try to take off ship as a chopper plane */
888 if ((pcp->pl_flags & P_K) &&
889 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
891 ship->shp_nchoppers--;
892 plane->pln_ship = -1;
893 putship(ship->shp_uid, ship);
894 putplane(plane->pln_uid, plane);
898 /* Try to take off ship as an xlight plane */
899 if ((pcp->pl_flags & P_E) &&
900 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
903 plane->pln_ship = -1;
904 putship(ship->shp_uid, ship);
905 putplane(plane->pln_uid, plane);
909 /* Try to take off ship as a normal plane */
910 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
911 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
912 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
915 plane->pln_ship = -1;
916 putship(ship->shp_uid, ship);
917 putplane(plane->pln_uid, plane);
926 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
928 struct plchrstr *pcp;
930 pcp = &plchr[(int)plane->pln_type];
932 /* Try to take off ship as an xlight plane */
933 if ((pcp->pl_flags & P_E) && land->lnd_nxlight) {
936 plane->pln_land = -1;
937 putland(land->lnd_uid, land);
938 putplane(plane->pln_uid, plane);
947 can_be_on_ship(int p, int s)
951 struct plchrstr *pcp;
957 pcp = &plchr[(int)plane.pln_type];
958 mcp = &mchr[(int)ship.shp_type];
960 if (pcp->pl_flags & P_L)
961 if (mcp->m_flags & M_FLY)
964 if (pcp->pl_flags & P_K)
965 if (mcp->m_flags & M_CHOPPER)
968 if (pcp->pl_flags & P_M)
969 if (mcp->m_flags & M_MSL)
972 if (pcp->pl_flags & P_E)
973 if (mcp->m_flags & M_XLIGHT)
980 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
983 struct plchrstr *pcp;
984 struct emp_qelem *qp;
985 struct emp_qelem *next;
991 getsect(x, y, §);
992 mines_there = sect.sct_mines;
994 if (mines_there == 0)
997 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
1000 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
1003 ip = (struct plist *)qp;
1006 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
1009 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
1010 pr("Sweep! in %s\n",
1011 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
1017 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
1018 writemap(player->cnum);
1019 sect.sct_mines = mines_there;
1024 count_planes(struct shpstr *sp)
1026 struct nstr_item ni;
1027 struct plnstr plane;
1028 struct plchrstr *pcp;
1029 struct mchrstr *mcp;
1034 if (sp->shp_effic < SHIP_MINEFF)
1037 mcp = &mchr[(int)sp->shp_type];
1038 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
1039 while (nxtitem(&ni, &plane)) {
1040 if (plane.pln_own == 0)
1042 if (plane.pln_ship == sp->shp_uid) {
1043 pcp = &plchr[(int)plane.pln_type];
1044 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
1046 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
1048 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
1053 if (nplane != sp->shp_nplane ||
1054 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1055 sp->shp_nplane = nplane;
1056 sp->shp_nxlight = nxlight;
1057 sp->shp_nchoppers = nchoppers;
1058 putship(sp->shp_uid, sp);
1063 count_land_planes(struct lndstr *lp)
1065 struct nstr_item ni;
1066 struct plnstr plane;
1069 if (lp->lnd_effic < LAND_MINEFF)
1072 snxtitem_all(&ni, EF_PLANE);
1073 while (nxtitem(&ni, &plane)) {
1074 if (plane.pln_own == 0)
1076 if (plane.pln_land == lp->lnd_uid)
1080 if (lp->lnd_nxlight != nplane) {
1081 lp->lnd_nxlight = nplane;
1082 putland(lp->lnd_uid, lp);
1087 count_sect_planes(struct sctstr *sp)
1090 struct nstr_item ni;
1091 struct plnstr plane;
1093 snxtitem_all(&ni, EF_PLANE);
1094 while (nxtitem(&ni, &plane)) {
1097 if (plane.pln_flags & PLN_LAUNCHED)
1099 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1107 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1109 struct plchrstr *pcp;
1111 pcp = &plchr[(int)plane->pln_type];
1113 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1114 return 1; /* Already on unit */
1116 /* Try to put on unit as an xlight plane */
1117 if ((pcp->pl_flags & P_E) &&
1118 (land->lnd_nxlight < land->lnd_maxlight)) {
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, 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;