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 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
67 nships = carriersatxy(target->sct_x, target->sct_y,
68 M_FLY | M_CHOPPER, 0, player->cnum);
71 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
75 || !getship(cno, &ship)
77 && (getrel(getnatp(ship.shp_own), player->cnum)
82 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
83 pr("Ship #%d not in %s\n", cno,
84 xyas(target->sct_x, target->sct_y, player->cnum));
87 if ((!(mchr[(int)ship.shp_type].m_flags & M_FLY)
88 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
89 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER))
90 || ship.shp_effic < SHP_AIROPS_EFF) {
91 pr("Can't land on %s.\n", prship(&ship));
95 /* clear to land on ship#CNO */
96 pr("landing on carrier %d\n", cno);
97 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
99 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
101 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
109 /* try to land at sector */
110 if (target->sct_own != player->cnum
111 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
112 pr("Nowhere to land at sector %s!\n",
113 xyas(target->sct_x, target->sct_y, player->cnum));
116 if (target->sct_type == SCT_MOUNT) {
117 pr("Nowhere to land at sector %s!\n",
118 xyas(target->sct_x, target->sct_y, player->cnum));
121 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
124 /* clear to land at sector */
131 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
132 struct emp_qelem *esc_list, int cno)
134 struct emp_qelem *list, *qp;
136 struct plchrstr *pcp;
139 int nchoppers, nxlight, nplane;
141 if (cno < 0 || !getship(cno, &ship))
145 nchoppers = ship.shp_nchoppers;
146 nxlight = ship.shp_nxlight;
147 nplane = ship.shp_nplane;
148 mcp = &mchr[(int)ship.shp_type];
151 for (list = bomb_list;
153 list = list == bomb_list ? esc_list : NULL) {
154 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
155 /* FIXME duplicates put_plane_on_ship() logic; refactor */
156 plp = (struct plist *)qp;
157 pcp = &plchr[(int)plp->plane.pln_type];
158 if (plp->plane.pln_ship == ship.shp_uid)
160 /* try chopper space */
161 if ((pcp->pl_flags & P_K) && (mcp->m_flags & M_CHOPPER)
162 && nchoppers < mcp->m_nchoppers)
164 /* try xlight space */
165 else if ((pcp->pl_flags & P_E) && (mcp->m_flags & M_XLIGHT)
166 && nxlight < mcp->m_nxlight)
168 /* try plane space */
169 else if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY))
170 || ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L)
171 && (mcp->m_flags & M_MSL)))
172 && nplane < mcp->m_nplanes)
175 return 0; /* won't be able to land */
182 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
184 struct emp_qelem *qp;
191 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
192 plp = (struct plist *)qp;
195 if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
196 pr("\t%s cannot land on ship #%d! %s aborts!\n",
197 prplane(&plp->plane), cno, prplane(&plp->plane));
198 else if (!put_plane_on_ship(&plp->plane, &ship))
199 pr("\tNo room on ship #%d! %s aborts!\n", cno,
200 prplane(&plp->plane));
202 if (plp->plane.pln_own != ship.shp_own) {
203 /* plp->plane.pln_own = ship.shp_own;*/
205 "%s %s lands on your %s\n",
207 prplane(&plp->plane), prship(&ship));
211 plp->plane.pln_x = tx;
212 plp->plane.pln_y = ty;
213 getsect(tx, ty, §);
214 if (plp->plane.pln_own != sect.sct_own) {
215 /* plp->plane.pln_own = sect.sct_own;*/
217 "%s %s lands at your sector %s\n",
219 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
221 plp->plane.pln_ship = cno;
225 putship(ship.shp_uid, &ship);
229 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
232 struct emp_qelem *qp;
235 struct sctstr *sectp;
244 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
245 plp = (struct plist *)qp;
248 if (type == EF_SECTOR) {
250 if (!sectp->sct_own) {
251 if (sectp->sct_type == SCT_WATER)
252 pr("Your %s sink like a rock!\n", ip->i_name);
254 pr("Your %s vanish without a trace.\n", ip->i_name);
257 if (sectp->sct_own != player->cnum
258 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
259 pr("You don't own %s! Cargo jettisoned...\n",
260 xyas(tx, ty, player->cnum));
263 if (ip->i_vtype == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
264 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
265 xyas(tx, ty, player->cnum));
268 there = sectp->sct_item[ip->i_vtype];
272 there = sp->shp_item[ip->i_vtype];
273 mp = &mchr[(int)sp->shp_type];
274 max = mp->m_item[ip->i_vtype];
278 pr("%d excess %s discarded\n", max - there, ip->i_name);
282 pr("%d %s landed safely", amt, ip->i_name);
283 if (type == EF_SECTOR) {
285 sectp->sct_item[ip->i_vtype] = there;
286 if (sectp->sct_own != player->cnum)
287 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
288 cname(player->cnum), amt, ip->i_name,
289 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
290 pr(" at %s\n", xyas(tx, ty, player->cnum));
291 putsect((struct sctstr *)ptr);
293 struct shpstr *sp = (struct shpstr *)ptr;
294 sp->shp_item[ip->i_vtype] = there;
295 if (sp->shp_own != player->cnum)
296 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
297 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
298 pr(" on carrier #%d\n", sp->shp_uid);
299 putship(sp->shp_uid, sp);
304 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
306 struct emp_qelem *qp;
311 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
312 plp = (struct plist *)qp;
317 sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
318 pr("%d mines laid in %s.\n", amt,
319 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
320 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
321 writemap(player->cnum);
327 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
328 int ap_to_target, int rangemult, int wantflags, int nowantflags)
335 struct plchrstr *pcp;
342 while (nxtitem(ni, &plane)) {
345 if (plane.pln_mobil <= 0)
348 if (ontradingblock(EF_PLANE, (int *)&plane)) {
349 pr("plane #%d inelligible - it's for sale.\n",
355 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
357 pr("%s too far from assembly point\n", prplane(&plane));
360 if (plane.pln_effic < 40) {
361 pr("%s not efficient enough (must be 40%%)\n",
365 range += ap_to_target;
366 pcp = &plchr[(int)plane.pln_type];
370 for (x = 0; x < sizeof(wantflags) * 8; x++) {
372 if ((wantflags & y) == y)
373 if ((pcp->pl_flags & y) != y) {
392 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
396 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
398 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
400 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
409 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
411 if ((nowantflags & y) == y)
412 if ((pcp->pl_flags & y) == y)
419 if (plane.pln_range < range) {
420 pr("%s out of range (%d:%d)\n", prplane(&plane),
421 plane.pln_range, range);
424 if (plane.pln_ship >= 0) {
425 if (!getship(plane.pln_ship, &ship) ||
426 plane.pln_own != player->cnum) {
429 pr("(note) ship not valid for %s\n", prplane(&plane));
430 putplane(plane.pln_uid, &plane);
433 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
435 if (ship.shp_effic < SHIP_MINEFF)
437 if (ship.shp_effic < SHP_AIROPS_EFF)
439 /* Can't fly off non-owned ships or non-allied ship */
440 if ((ship.shp_own != player->cnum) &&
441 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
442 pr("(note) An ally does not own the ship %s is on\n",
447 if (plane.pln_land >= 0) {
448 if (!getland(plane.pln_land, &land) ||
449 (plane.pln_own != player->cnum)) {
452 pr("(note) land unit not valid for %s\n", prplane(&plane));
453 putplane(plane.pln_uid, &plane);
456 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
458 if (land.lnd_effic < LAND_MINEFF)
460 if (land.lnd_effic < LND_AIROPS_EFF)
462 /* Can't fly off units in ships or other units */
463 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
465 /* Can't fly off non-owned units or non-allied unit */
466 if ((land.lnd_own != player->cnum) &&
467 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
468 pr("(note) An ally does not own the unit %s is on\n",
473 /* Now, check the sector status if not on a plane or unit */
474 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
475 if (!getsect(plane.pln_x, plane.pln_y, §))
477 /* First, check allied status */
478 /* Can't fly from non-owned sectors or non-allied sectors */
479 if ((sect.sct_own != player->cnum) &&
480 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
481 pr("(note) An ally does not own the sector %s is in\n",
486 if ((pcp->pl_flags & P_V) == 0) {
487 if (sect.sct_type != SCT_AIRPT) {
488 pr("%s not at airport\n", prplane(&plane));
491 if (sect.sct_effic < 40) {
492 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));
495 if (rangemult == 2 && sect.sct_effic < 60) {
496 pr("%s is not 60%% efficient, %s can't land there.\n",
497 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
503 pr("%s standing by\n", prplane(&plane));
504 plane.pln_mission = 0;
505 putplane(plane.pln_uid, &plane);
506 plp = malloc(sizeof(struct plist));
512 emp_insque(&plp->queue, list);
517 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
518 int flags, int mission_flags)
520 struct emp_qelem *qp;
521 struct emp_qelem *next;
524 for (qp = list->q_forw; qp != list; qp = next) {
526 plp = (struct plist *)qp;
527 if (pln_equip(plp, ip, flags, mission) < 0) {
532 if (flags & (P_S | P_I)) {
533 if (plp->pcp->pl_flags & P_S)
534 mission_flags |= P_S;
535 if (plp->pcp->pl_flags & P_I)
536 mission_flags |= P_I;
538 if (!(plp->pcp->pl_flags & P_H))
539 /* no stealth on this mission */
540 mission_flags &= ~P_H;
541 if (!(plp->pcp->pl_flags & P_X))
542 /* no stealth on this mission */
543 mission_flags &= ~P_X;
544 if (!(plp->pcp->pl_flags & P_A)) {
545 /* no asw on this mission */
546 mission_flags &= ~P_A;
548 if (!(plp->pcp->pl_flags & P_MINE)) {
549 /* no asw on this mission */
550 mission_flags &= ~P_MINE;
552 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
553 pr("%s equipped\n", prplane(&plp->plane));
555 return mission_flags;
559 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
561 struct plchrstr *pcp;
574 if (pp->pln_ship >= 0) {
575 getship(pp->pln_ship, &ship);
576 item = ship.shp_item;
578 } else if (pp->pln_land >= 0) {
579 getland(pp->pln_land, &land);
580 item = land.lnd_item;
583 getsect(pp->pln_x, pp->pln_y, §);
584 item = sect.sct_item;
585 own = sect.sct_oldown;
588 if (ip->i_vtype == I_CIVIL) {
589 if (pp->pln_own != own) {
590 pr("You don't control those civilians!\n");
595 if (pcp->pl_fuel > item[I_PETROL]) {
596 pr("%s not enough petrol there!\n", prplane(pp));
599 item[I_PETROL] -= pcp->pl_fuel;
601 if ((flags & P_F) == 0) {
607 if (pp->pln_nuketype == -1) {
609 needed = pp->pln_load;
613 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
616 needed = (pp->pln_load * 2) / ip->i_lbs;
620 needed = (pp->pln_load * 2) / ip->i_lbs;
621 /* Is this mine dropping excursion? */
622 if (itype == I_SHELL && (pcp->pl_flags & P_MINE))
624 /* Is this a cargo drop? */
625 if ((pcp->pl_flags & P_C) == 0 || ip == 0) {
632 if ((pcp->pl_flags & (P_V | P_C)) == 0)
635 needed = pp->pln_load / ip->i_lbs;
638 if (pp->pln_nuketype == -1)
644 if (rval < 0 || (itype != I_NONE && needed <= 0)) {
645 pr("%s can't contribute to mission\n", prplane(pp));
648 if (itype != I_NONE) {
650 /* Supply is broken somewhere, so don't use it for now */
651 if (itype == I_SHELL && item[itype] < needed)
652 item[itype] += supply_commod(plp->plane.pln_own,
657 if (item[itype] < needed) {
658 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
661 item[itype] -= needed;
663 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
668 if (pp->pln_ship >= 0) {
669 if (pp->pln_own != ship.shp_own) {
671 "%s %s prepares for takeoff from ship %s\n",
672 cname(pp->pln_own), prplane(pp), prship(&ship));
674 putship(ship.shp_uid, &ship);
675 } else if (pp->pln_land >= 0) {
676 if (pp->pln_own != land.lnd_own) {
678 "%s %s prepares for takeoff from unit %s\n",
679 cname(pp->pln_own), prplane(pp), prland(&land));
681 putland(land.lnd_uid, &land);
683 if (pp->pln_own != sect.sct_own) {
684 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
685 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
695 pln_put(struct emp_qelem *list)
697 struct emp_qelem *qp;
698 struct emp_qelem *newqp;
704 /* Here is where planes return home from bombing runs.
705 We need to make sure they still have somewhere to return
709 plp = (struct plist *)qp;
711 /* Ok, check out where it wants to land */
712 if (pp->pln_ship >= 0) {
713 /* It is landing on a carrier */
714 getship(pp->pln_ship, &ship);
715 /* We should do more, like make sure it's really
716 a carrier, etc. but for now just make sure it's
718 if (ship.shp_effic < SHIP_MINEFF) {
720 "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n",
721 pp->pln_ship, pp->pln_uid);
725 /* Presume we are landing back in a sector. */
726 getsect(pp->pln_x, pp->pln_y, §);
727 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
729 "Nowhere to land at %s, plane #%d crashes and burns...\n",
730 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
734 putplane(pp->pln_uid, pp);
743 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
745 struct emp_qelem *bomb;
746 struct emp_qelem *esc;
750 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
752 bomb = bomb_list->q_forw;
753 while (bomb != bomb_list) {
754 if (QEMPTY(esc_list)) {
758 esc = esc_list->q_forw;
759 bombp = (struct plist *)bomb;
760 while (esc != esc_list) {
761 escp = (struct plist *)esc;
762 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
774 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
776 struct plchrstr *pcp;
779 pcp = &plchr[(int)plane->pln_type];
780 mcp = &mchr[(int)ship->shp_type];
782 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
783 return 1; /* Already on ship */
785 /* Try to put on ship as a chopper plane */
786 if ((pcp->pl_flags & P_K) &&
787 (mcp->m_flags & M_CHOPPER) &&
788 (ship->shp_nchoppers < mcp->m_nchoppers)) {
790 ship->shp_nchoppers++;
791 plane->pln_x = ship->shp_x;
792 plane->pln_y = ship->shp_y;
793 plane->pln_ship = ship->shp_uid;
794 putship(ship->shp_uid, ship);
795 putplane(plane->pln_uid, plane);
799 /* Try to put on ship as an xlight plane */
800 if ((pcp->pl_flags & P_E) &&
801 (mcp->m_flags & M_XLIGHT) &&
802 (ship->shp_nxlight < mcp->m_nxlight)) {
805 plane->pln_x = ship->shp_x;
806 plane->pln_y = ship->shp_y;
807 plane->pln_ship = ship->shp_uid;
808 putship(ship->shp_uid, ship);
809 putplane(plane->pln_uid, plane);
813 /* Try to put on ship as a normal plane */
814 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
815 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
816 (mcp->m_flags & M_MSL))) &&
817 (ship->shp_nplane < mcp->m_nplanes)) {
820 plane->pln_x = ship->shp_x;
821 plane->pln_y = ship->shp_y;
822 plane->pln_ship = ship->shp_uid;
823 putship(ship->shp_uid, ship);
824 putplane(plane->pln_uid, plane);
833 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
835 struct plchrstr *pcp;
838 pcp = &plchr[(int)plane->pln_type];
839 mcp = &mchr[(int)ship->shp_type];
841 /* Try to take off ship as a chopper plane */
842 if ((pcp->pl_flags & P_K) &&
843 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
845 ship->shp_nchoppers--;
846 plane->pln_ship = -1;
847 putship(ship->shp_uid, ship);
848 putplane(plane->pln_uid, plane);
852 /* Try to take off ship as an xlight plane */
853 if ((pcp->pl_flags & P_E) &&
854 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
857 plane->pln_ship = -1;
858 putship(ship->shp_uid, ship);
859 putplane(plane->pln_uid, plane);
863 /* Try to take off ship as a normal plane */
864 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
865 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
866 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
869 plane->pln_ship = -1;
870 putship(ship->shp_uid, ship);
871 putplane(plane->pln_uid, plane);
880 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
882 struct plchrstr *pcp;
885 pcp = &plchr[(int)plane->pln_type];
886 lcp = &lchr[(int)land->lnd_type];
888 /* Try to take off ship as an xlight plane */
889 if ((pcp->pl_flags & P_E) &&
890 (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) {
893 plane->pln_land = -1;
894 putland(land->lnd_uid, land);
895 putplane(plane->pln_uid, plane);
904 can_be_on_ship(int p, int s)
908 struct plchrstr *pcp;
914 pcp = &plchr[(int)plane.pln_type];
915 mcp = &mchr[(int)ship.shp_type];
917 if (pcp->pl_flags & P_L)
918 if (mcp->m_flags & M_FLY)
921 if (pcp->pl_flags & P_K)
922 if (mcp->m_flags & M_CHOPPER)
925 if (pcp->pl_flags & P_M)
926 if (mcp->m_flags & M_MSL)
929 if (pcp->pl_flags & P_E)
930 if (mcp->m_flags & M_XLIGHT)
937 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
940 struct plchrstr *pcp;
941 struct emp_qelem *qp;
942 struct emp_qelem *next;
948 getsect(x, y, §);
949 mines_there = sect.sct_mines;
951 if (mines_there == 0)
954 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
957 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
960 ip = (struct plist *)qp;
963 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
966 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
968 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
974 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
975 writemap(player->cnum);
976 sect.sct_mines = mines_there;
981 count_planes(struct shpstr *sp)
985 struct plchrstr *pcp;
991 if (sp->shp_effic < SHIP_MINEFF)
994 mcp = &mchr[(int)sp->shp_type];
995 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
996 while (nxtitem(&ni, &plane)) {
997 if (plane.pln_own == 0)
999 if (plane.pln_ship == sp->shp_uid) {
1000 pcp = &plchr[(int)plane.pln_type];
1001 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
1003 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
1005 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
1010 if (nplane != sp->shp_nplane ||
1011 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1012 sp->shp_nplane = nplane;
1013 sp->shp_nxlight = nxlight;
1014 sp->shp_nchoppers = nchoppers;
1015 putship(sp->shp_uid, sp);
1020 count_land_planes(struct lndstr *lp)
1022 struct nstr_item ni;
1023 struct plnstr plane;
1026 if (lp->lnd_effic < LAND_MINEFF)
1029 snxtitem_all(&ni, EF_PLANE);
1030 while (nxtitem(&ni, &plane)) {
1031 if (plane.pln_own == 0)
1033 if (plane.pln_land == lp->lnd_uid)
1037 if (lp->lnd_nxlight != nplane) {
1038 lp->lnd_nxlight = nplane;
1039 putland(lp->lnd_uid, lp);
1044 count_sect_planes(struct sctstr *sp)
1047 struct nstr_item ni;
1048 struct plnstr plane;
1050 snxtitem_all(&ni, EF_PLANE);
1051 while (nxtitem(&ni, &plane)) {
1054 if (plane.pln_flags & PLN_LAUNCHED)
1056 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1064 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1066 struct plchrstr *pcp;
1067 struct lchrstr *lcp;
1069 pcp = &plchr[(int)plane->pln_type];
1070 lcp = &lchr[(int)land->lnd_type];
1072 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1073 return 1; /* Already on unit */
1075 /* Try to put on unit as an xlight plane */
1076 if ((pcp->pl_flags & P_E) &&
1077 (lcp->l_flags & L_XLIGHT) &&
1078 (land->lnd_nxlight < lcp->l_nxlight)) {
1080 land->lnd_nxlight++;
1081 plane->pln_x = land->lnd_x;
1082 plane->pln_y = land->lnd_y;
1083 plane->pln_land = land->lnd_uid;
1084 putland(land->lnd_uid, land);
1085 putplane(plane->pln_uid, plane);
1089 /* We have failed */
1094 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1096 struct plchrstr *pcp = plchr + pp->pln_type;
1097 float tfact = (float)(pp->pln_tech - pcp->pl_tech) /
1098 (pp->pln_tech - pcp->pl_tech / 2);
1099 int acc = pp->pln_acc;
1102 if (type == EF_SHIP) {
1103 if (pcp->pl_flags & P_A)
1105 if (!(pcp->pl_flags & P_T))
1108 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1109 (1.0 - (float)acc / 100.0)) - hardtarget;
1111 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1113 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1114 if (hitchance > 100)
1119 /* return 0 if there was a nuclear detonation */
1122 pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp,
1125 struct plchrstr *pcp = plchr + pp->pln_type;
1133 if (pp->pln_nuketype != -1) {
1134 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1135 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1136 *nukedamp = detonate(pp, x, y);
1141 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1144 i = roll(pp->pln_load) + 1;
1145 if (i > pp->pln_load)
1148 if (pcp->pl_flags & P_M) {
1149 if (pcp->pl_flags & P_MAR)
1151 } else if (pcp->pl_flags & P_T)
1154 aim = 100 - pp->pln_acc;
1168 hitroll = roll(100);
1169 if (hitroll >= 90) {
1172 mpr(pp->pln_own, "BLAM");
1173 } else if (hitroll < aim) {
1176 mpr(pp->pln_own, "Blam");
1180 mpr(pp->pln_own, "blam");
1183 mpr(pp->pln_own, "-");
1186 mpr(pp->pln_own, "\n");
1193 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1196 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1197 return (int)(100 - 100 * misschance * misschance);
1201 pln_mobcost(int dist, struct plnstr *pp, int flags)
1205 if ((flags & P_F) || (flags & P_ESC))
1206 cost = 10 * 100 / pp->pln_effic;
1208 cost = 20 * 100 / pp->pln_effic;
1210 cost = ldround((double)cost * dist / pp->pln_range_max, 1);
1212 return min(32 + pp->pln_mobil, cost + 5);
1216 * Set PP's tech to TLEV along with everything else that depends on it.
1219 pln_set_tech(struct plnstr *pp, int tlev)
1221 struct plchrstr *pcp = plchr + pp->pln_type;
1222 int tech_diff = tlev - pcp->pl_tech;
1223 int limited_range = pp->pln_range < pp->pln_range_max;
1225 if (CANT_HAPPEN(tech_diff < 0)) {
1230 pp->pln_tech = tlev;
1231 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1232 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1233 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1234 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1235 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1237 if (!limited_range || pp->pln_range > pp->pln_range_max)
1238 pp->pln_range = pp->pln_range_max;