2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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
52 #include "prototypes.h"
55 static int pln_equip(struct plist *, struct ichrstr *, int, s_char);
58 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
69 if ((target->sct_own && target->sct_own != player->cnum &&
70 (getrel(getnatp(target->sct_own), player->cnum) != ALLIED)) &&
71 (target->sct_type != SCT_HARBR) &&
72 (target->sct_type != SCT_BSPAN)) {
73 pr("Nowhere to land at sector %s!\n",
74 xyas(target->sct_x, target->sct_y, player->cnum));
77 if (target->sct_type == SCT_MOUNT) {
78 pr("Nowhere to land at sector %s!\n",
79 xyas(target->sct_x, target->sct_y, player->cnum));
83 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
85 if (target->sct_type == SCT_WATER || target->sct_type == SCT_HARBR
86 || target->sct_type == SCT_BSPAN) {
87 nships = carriersatxy(target->sct_x, target->sct_y,
88 M_FLY | M_CHOPPER, 0, player->cnum);
90 if (target->sct_type == SCT_WATER) {
91 pr("Nowhere to land at sector %s!\n",
92 xyas(target->sct_x, target->sct_y, player->cnum));
95 if ((target->sct_own && target->sct_own != player->cnum)
96 && (getrel(getnatp(target->sct_own), player->cnum) !=
98 pr("Nowhere to land at sector %s!\n",
99 xyas(target->sct_x, target->sct_y, player->cnum));
110 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
113 if (n < 0 || !getship(n, &ship)
115 && (getrel(getnatp(ship.shp_own), player->cnum)
120 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
121 pr("Ship #%d not in %s\n", n,
122 xyas(target->sct_x, target->sct_y, player->cnum));
125 if (!(mchr[(int)ship.shp_type].m_flags & M_FLY)
126 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
127 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
129 pr("Can't land on %s.\n", prship(&ship));
132 pr("landing on carrier %d\n", n);
135 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
137 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
139 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
142 if ((target->sct_own && target->sct_own != player->cnum) &&
143 (getrel(getnatp(target->sct_own), player->cnum) != ALLIED) &&
145 pr("Nowhere to land at sector %s!\n",
146 xyas(target->sct_x, target->sct_y, player->cnum));
151 if ((target->sct_own == 0) && (cno < 0)) {
152 pr("Nowhere to land at sector %s!\n",
153 xyas(target->sct_x, target->sct_y, player->cnum));
163 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
165 struct emp_qelem *qp;
172 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
173 plp = (struct plist *)qp;
174 /* XXX - need to restrict # of planes per ship */
177 if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
178 pr("\t%s cannot land on ship #%d! %s aborts!\n",
179 prplane(&plp->plane), cno, prplane(&plp->plane));
180 else if (!put_plane_on_ship(&plp->plane, &ship))
181 pr("\tNo room on ship #%d! %s aborts!\n", cno,
182 prplane(&plp->plane));
184 if (plp->plane.pln_own != ship.shp_own) {
185 /* plp->plane.pln_own = ship.shp_own;*/
187 "%s %s lands on your %s\n",
189 prplane(&plp->plane), prship(&ship));
193 plp->plane.pln_x = tx;
194 plp->plane.pln_y = ty;
195 getsect(tx, ty, §);
196 if (plp->plane.pln_own != sect.sct_own) {
197 /* plp->plane.pln_own = sect.sct_own;*/
199 "%s %s lands at your sector %s\n",
201 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
203 plp->plane.pln_ship = cno;
207 putship(ship.shp_uid, &ship);
211 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
214 struct emp_qelem *qp;
217 struct sctstr *sectp;
226 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
227 plp = (struct plist *)qp;
230 if (type == EF_SECTOR) {
232 if (sectp->sct_type == SCT_WATER && ip->i_vtype == V_SHELL) {
234 sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
235 pr("%d mines laid in %s.\n", amt,
236 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
238 && map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
239 writemap(player->cnum);
243 there = sectp->sct_item[ip->i_vtype];
247 there = sp->shp_item[ip->i_vtype];
248 mp = &mchr[(int)sp->shp_type];
249 max = vl_find(ip->i_vtype, mp->m_vtype,
250 mp->m_vamt, (int)mp->m_nv);
254 pr("%d excess %s discarded\n", max - there, ip->i_name);
258 pr("%d %s landed safely", amt, ip->i_name);
259 if (type == EF_SECTOR) {
261 sectp->sct_item[ip->i_vtype] = there;
262 if (sectp->sct_own != player->cnum)
263 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
264 cname(player->cnum), amt, ip->i_name,
265 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
266 pr(" at %s\n", xyas(tx, ty, player->cnum));
267 putsect((struct sctstr *)ptr);
269 struct shpstr *sp = (struct shpstr *)ptr;
270 sp->shp_item[ip->i_vtype] = there;
271 if (sp->shp_own != player->cnum)
272 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
273 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
274 pr(" on carrier #%d\n", sp->shp_uid);
275 putship(sp->shp_uid, sp);
280 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
281 int ap_to_target, int rangemult, int wantflags, int nowantflags)
288 struct plchrstr *pcp;
291 register int bad, bad1;
295 while (nxtitem(ni, (s_char *)&plane)) {
298 if (plane.pln_mobil <= (s_char)0)
301 if (ontradingblock(EF_PLANE, (int *)&plane)) {
302 pr("plane #%d inelligible - it's for sale.\n",
308 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
310 pr("%s too far from assembly point\n", prplane(&plane));
313 if (plane.pln_effic < 40) {
314 pr("%s not efficient enough (must be 40%%)\n",
318 range += ap_to_target;
319 pcp = &plchr[(int)plane.pln_type];
323 for (x = 0; x < sizeof(wantflags) * 8; x++) {
325 if ((wantflags & y) == y)
326 if ((pcp->pl_flags & y) != y) {
345 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
349 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
351 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
353 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
362 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
364 if ((nowantflags & y) == y)
365 if ((pcp->pl_flags & y) == y)
372 if (plane.pln_range < range) {
373 pr("%s out of range (%d:%d)\n", prplane(&plane),
374 plane.pln_range, range);
377 if (plane.pln_ship >= 0) {
378 if (!getship(plane.pln_ship, &ship) ||
379 plane.pln_own != player->cnum) {
382 pr("(note) ship not valid for %s\n", prplane(&plane));
383 putplane(plane.pln_uid, &plane);
386 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
388 if (ship.shp_effic < SHIP_MINEFF)
390 if (ship.shp_effic < 50)
392 /* Can't fly off non-owned ships or non-allied ship */
393 if ((ship.shp_own != player->cnum) &&
394 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
395 pr("(note) An ally does not own the ship %s is on\n",
400 if (plane.pln_land >= 0) {
401 if (!getland(plane.pln_land, &land) ||
402 (plane.pln_own != player->cnum)) {
405 pr("(note) land unit not valid for %s\n", prplane(&plane));
406 putplane(plane.pln_uid, &plane);
409 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
411 if (land.lnd_effic < LAND_MINEFF)
413 if (land.lnd_effic < 50)
415 /* Can't fly off units in ships or other units */
416 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
418 /* Can't fly off non-owned units or non-allied unit */
419 if ((land.lnd_own != player->cnum) &&
420 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
421 pr("(note) An ally does not own the unit %s is on\n",
426 /* Now, check the sector status if not on a plane or unit */
427 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
428 if (!getsect(plane.pln_x, plane.pln_y, §))
430 /* First, check allied status */
431 /* Can't fly from non-owned sectors or non-allied sectors */
432 if ((sect.sct_own != player->cnum) &&
433 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
434 pr("(note) An ally does not own the sector %s is in\n",
439 if ((pcp->pl_flags & P_V) == 0) {
440 if (sect.sct_type != SCT_AIRPT) {
441 pr("%s not at airport\n", prplane(&plane));
444 if (sect.sct_effic < 40) {
445 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));
448 if (rangemult == 2 && sect.sct_effic < 60) {
449 pr("%s is not 60%% efficient, %s can't land there.\n",
450 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
456 pr("%s standing by\n", prplane(&plane));
457 plane.pln_mission = 0;
458 putplane(plane.pln_uid, &plane);
459 plp = (struct plist *)malloc(sizeof(struct plist));
465 emp_insque(&plp->queue, list);
470 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
471 int flags, int mission_flags, int *tech)
473 struct emp_qelem *qp;
474 struct emp_qelem *next;
479 for (qp = list->q_forw; qp != list; qp = next) {
481 plp = (struct plist *)qp;
482 if (pln_equip(plp, ip, flags, mission) < 0) {
487 if (flags & (P_S | P_I)) {
488 if (plp->pcp->pl_flags & P_S)
489 mission_flags |= P_S;
490 if (plp->pcp->pl_flags & P_I)
491 mission_flags |= P_I;
493 if (*tech > plp->plane.pln_tech)
494 *tech = plp->plane.pln_tech;
495 if (!(plp->pcp->pl_flags & P_H))
496 /* no stealth on this mission */
497 mission_flags &= ~P_H;
498 if (!(plp->pcp->pl_flags & P_X))
499 /* no stealth on this mission */
500 mission_flags &= ~P_X;
501 if (!(plp->pcp->pl_flags & P_A)) {
502 /* no asw on this mission */
503 mission_flags &= ~P_A;
505 if (!(plp->pcp->pl_flags & P_MINE)) {
506 /* no asw on this mission */
507 mission_flags &= ~P_MINE;
509 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
510 pr("%s equipped\n", prplane(&plp->plane));
512 return mission_flags;
516 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
518 register struct plchrstr *pcp;
531 if (pp->pln_ship >= 0) {
532 getship(pp->pln_ship, &ship);
533 item = ship.shp_item;
535 } else if (pp->pln_land >= 0) {
536 getland(pp->pln_land, &land);
537 item = land.lnd_item;
540 getsect(pp->pln_x, pp->pln_y, §);
541 item = sect.sct_item;
542 own = sect.sct_oldown;
545 if (ip->i_vtype == V_CIVIL) {
546 if (pp->pln_own != own) {
547 pr("You don't control those civilians!\n");
552 if (pcp->pl_fuel > item[I_PETROL]) {
553 pr("%s not enough petrol there!\n", prplane(pp));
556 item[I_PETROL] -= pcp->pl_fuel;
558 if ((flags & P_F) == 0) {
564 if (pp->pln_nuketype == -1) {
566 needed = pp->pln_load;
570 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
573 needed = (pp->pln_load * 2) / ip->i_lbs;
577 needed = (pp->pln_load * 2) / ip->i_lbs;
578 /* Is this mine dropping excursion? */
579 if (itype == I_SHELL && (pcp->pl_flags & P_MINE))
581 /* Is this a cargo drop? */
582 if ((pcp->pl_flags & P_C) == 0 || ip == 0) {
589 if ((pcp->pl_flags & (P_V | P_C)) == 0)
592 needed = pp->pln_load / ip->i_lbs;
595 if (pp->pln_nuketype == (s_char)-1)
601 if (rval < 0 || (itype && needed <= 0)) {
602 pr("%s can't contribute to mission\n", prplane(pp));
606 /* Supply is broken somewhere, so don't use it for now */
607 if (item[itype] < needed && itype == I_SHELL)
608 item[itype] += supply_commod(plp->plane.pln_own,
609 plp->plane.pln_x, plp->plane.pln_y,
612 if (item[itype] < needed) {
613 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
616 item[itype] -= needed;
618 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
623 if (pp->pln_ship >= 0) {
624 if (pp->pln_own != ship.shp_own) {
626 "%s %s prepares for takeoff from ship %s\n",
627 cname(pp->pln_own), prplane(pp), prship(&ship));
629 putship(ship.shp_uid, &ship);
630 } else if (pp->pln_land >= 0) {
631 if (pp->pln_own != land.lnd_own) {
633 "%s %s prepares for takeoff from unit %s\n",
634 cname(pp->pln_own), prplane(pp), prland(&land));
636 putland(land.lnd_uid, &land);
638 if (pp->pln_own != sect.sct_own) {
639 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
640 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
650 pln_put(struct emp_qelem *list)
652 register struct emp_qelem *qp;
653 register struct emp_qelem *newqp;
659 /* Here is where planes return home from bombing runs.
660 We need to make sure they still have somewhere to return
664 plp = (struct plist *)qp;
666 /* Ok, check out where it wants to land */
667 if (pp->pln_ship >= 0) {
668 /* It is landing on a carrier */
669 getship(pp->pln_ship, &ship);
670 /* We should do more, like make sure it's really
671 a carrier, etc. but for now just make sure it's
673 if (ship.shp_effic < SHIP_MINEFF) {
675 "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n",
676 pp->pln_ship, pp->pln_uid);
680 /* Presume we are landing back in a sector. */
681 getsect(pp->pln_x, pp->pln_y, §);
682 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
684 "Nowwhere to land at %s, plane #%d crashes and burns...\n",
685 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
689 putplane(pp->pln_uid, pp);
698 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
700 struct emp_qelem *bomb;
701 struct emp_qelem *esc;
705 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
707 bomb = bomb_list->q_forw;
708 while (bomb != bomb_list) {
709 if (QEMPTY(esc_list)) {
713 esc = esc_list->q_forw;
714 bombp = (struct plist *)bomb;
715 while (esc != esc_list) {
716 escp = (struct plist *)esc;
717 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
729 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
731 struct plchrstr *pcp;
734 pcp = &plchr[(int)plane->pln_type];
735 mcp = &mchr[(int)ship->shp_type];
737 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
738 return 1; /* Already on ship */
740 /* Try to put on ship as a chopper plane */
741 if ((pcp->pl_flags & P_K) &&
742 (mcp->m_flags & M_CHOPPER) &&
743 (ship->shp_nchoppers < mcp->m_nchoppers)) {
745 ship->shp_nchoppers++;
746 plane->pln_x = ship->shp_x;
747 plane->pln_y = ship->shp_y;
748 plane->pln_ship = ship->shp_uid;
749 putship(ship->shp_uid, ship);
750 putplane(plane->pln_uid, plane);
754 /* Try to put on ship as an xlight plane */
755 if ((pcp->pl_flags & P_E) &&
756 (mcp->m_flags & M_XLIGHT) &&
757 (ship->shp_nxlight < mcp->m_nxlight)) {
760 plane->pln_x = ship->shp_x;
761 plane->pln_y = ship->shp_y;
762 plane->pln_ship = ship->shp_uid;
763 putship(ship->shp_uid, ship);
764 putplane(plane->pln_uid, plane);
768 /* Try to put on ship as a normal plane */
769 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
770 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
771 (mcp->m_flags & M_MSL))) &&
772 (ship->shp_nplane < mcp->m_nplanes)) {
775 plane->pln_x = ship->shp_x;
776 plane->pln_y = ship->shp_y;
777 plane->pln_ship = ship->shp_uid;
778 putship(ship->shp_uid, ship);
779 putplane(plane->pln_uid, plane);
788 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
790 struct plchrstr *pcp;
793 pcp = &plchr[(int)plane->pln_type];
794 mcp = &mchr[(int)ship->shp_type];
796 /* Try to take off ship as a chopper plane */
797 if ((pcp->pl_flags & P_K) &&
798 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
800 ship->shp_nchoppers--;
801 plane->pln_ship = -1;
802 putship(ship->shp_uid, ship);
803 putplane(plane->pln_uid, plane);
807 /* Try to take off ship as an xlight plane */
808 if ((pcp->pl_flags & P_E) &&
809 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
812 plane->pln_ship = -1;
813 putship(ship->shp_uid, ship);
814 putplane(plane->pln_uid, plane);
818 /* Try to take off ship as a normal plane */
819 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
820 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
821 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
824 plane->pln_ship = -1;
825 putship(ship->shp_uid, ship);
826 putplane(plane->pln_uid, plane);
835 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
837 struct plchrstr *pcp;
840 pcp = &plchr[(int)plane->pln_type];
841 lcp = &lchr[(int)land->lnd_type];
843 /* Try to take off ship as an xlight plane */
844 if ((pcp->pl_flags & P_E) &&
845 (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) {
848 plane->pln_land = -1;
849 putland(land->lnd_uid, land);
850 putplane(plane->pln_uid, plane);
859 can_be_on_ship(int p, int s)
863 struct plchrstr *pcp;
869 pcp = &plchr[(int)plane.pln_type];
870 mcp = &mchr[(int)ship.shp_type];
872 if (pcp->pl_flags & P_L)
873 if (mcp->m_flags & M_FLY)
876 if (pcp->pl_flags & P_K)
877 if (mcp->m_flags & M_CHOPPER)
880 if (pcp->pl_flags & P_M)
881 if (mcp->m_flags & M_MSL)
884 if (pcp->pl_flags & P_E)
885 if (mcp->m_flags & M_XLIGHT)
892 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
895 struct plchrstr *pcp;
896 struct emp_qelem *qp;
897 struct emp_qelem *next;
903 getsect(x, y, §);
904 mines_there = sect.sct_mines;
906 if (mines_there == 0)
909 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
912 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
915 ip = (struct plist *)qp;
918 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
921 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
923 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
929 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
930 writemap(player->cnum);
931 sect.sct_mines = mines_there;
936 count_planes(struct shpstr *sp)
940 struct plchrstr *pcp;
946 if (sp->shp_effic < SHIP_MINEFF)
949 mcp = &mchr[(int)sp->shp_type];
950 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
951 while (nxtitem(&ni, (s_char *)&plane)) {
952 if (plane.pln_own == 0)
954 if (plane.pln_ship == sp->shp_uid) {
955 pcp = &plchr[(int)plane.pln_type];
956 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
958 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
960 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
965 if (nplane != sp->shp_nplane ||
966 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
967 sp->shp_nplane = nplane;
968 sp->shp_nxlight = nxlight;
969 sp->shp_nchoppers = nchoppers;
970 putship(sp->shp_uid, sp);
975 count_land_planes(struct lndstr *lp)
981 if (lp->lnd_effic < LAND_MINEFF)
984 snxtitem_all(&ni, EF_PLANE);
985 while (nxtitem(&ni, (s_char *)&plane)) {
986 if (plane.pln_own == 0)
988 if (plane.pln_land == lp->lnd_uid)
992 if (lp->lnd_nxlight != nplane) {
993 lp->lnd_nxlight = nplane;
994 putland(lp->lnd_uid, lp);
999 count_sect_planes(struct sctstr *sp)
1002 struct nstr_item ni;
1003 struct plnstr plane;
1005 snxtitem_all(&ni, EF_PLANE);
1006 while (nxtitem(&ni, (s_char *)&plane)) {
1009 if (plane.pln_flags & PLN_LAUNCHED)
1011 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1019 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1021 struct plchrstr *pcp;
1022 struct lchrstr *lcp;
1024 pcp = &plchr[(int)plane->pln_type];
1025 lcp = &lchr[(int)land->lnd_type];
1027 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1028 return 1; /* Already on unit */
1030 /* Try to put on unit as an xlight plane */
1031 if ((pcp->pl_flags & P_E) &&
1032 (lcp->l_flags & L_XLIGHT) &&
1033 (land->lnd_nxlight < lcp->l_nxlight)) {
1035 land->lnd_nxlight++;
1036 plane->pln_x = land->lnd_x;
1037 plane->pln_y = land->lnd_y;
1038 plane->pln_land = land->lnd_uid;
1039 putland(land->lnd_uid, land);
1040 putplane(plane->pln_uid, plane);
1044 /* We have failed */
1049 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1051 struct plchrstr *pcp = plchr + pp->pln_type;
1052 float tfact = (float)(pp->pln_tech - pcp->pl_tech) /
1053 (pp->pln_tech - pcp->pl_tech / 2);
1054 int acc = pp->pln_acc;
1057 if (type == EF_SHIP) {
1058 if (pcp->pl_flags & P_A)
1060 if (!(pcp->pl_flags & P_T))
1063 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1064 (1.0 - (float)acc / 100.0)) - hardtarget;
1066 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1068 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1069 if (hitchance > 100)
1074 /* return 0 if there was a nuclear detonation */
1077 pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp,
1080 struct plchrstr *pcp = plchr + pp->pln_type;
1088 if (pp->pln_nuketype != (s_char)-1) {
1089 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1090 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1091 *nukedamp = detonate(pp, x, y);
1096 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1099 i = roll(pp->pln_load) + 1;
1100 if (i > pp->pln_load)
1103 if (pcp->pl_flags & P_M) {
1104 if (pcp->pl_flags & P_MAR)
1106 } else if (pcp->pl_flags & P_T)
1109 aim = 100 - pp->pln_acc;
1123 hitroll = roll(100);
1124 if (hitroll >= 90) {
1127 mpr(pp->pln_own, "BLAM");
1128 } else if (hitroll < aim) {
1131 mpr(pp->pln_own, "Blam");
1135 mpr(pp->pln_own, "blam");
1138 mpr(pp->pln_own, "-");
1141 mpr(pp->pln_own, "\n");
1148 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1151 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1152 return (int)(100 - 100 * misschance * misschance);
1156 pln_mobcost(int dist, struct plnstr *pp, int flags)
1160 if ((flags & P_F) || (flags & P_ESC))
1161 cost = 10 * 100 / pp->pln_effic;
1163 cost = 20 * 100 / pp->pln_effic;
1165 cost = ldround((double)cost * dist / pp->pln_range_max, 1);
1167 return min(32 + pp->pln_mobil, cost + 5);
1171 * Set PP's tech to TLEV along with everything else that depends on it.
1174 pln_set_tech(struct plnstr *pp, int tlev)
1176 struct plchrstr *pcp = plchr + pp->pln_type;
1177 int tech_diff = tlev - pcp->pl_tech;
1178 int limited_range = pp->pln_range < pp->pln_range_max;
1180 if (CANT_HAPPEN(tech_diff < 0)) {
1185 pp->pln_tech = tlev;
1186 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1187 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1188 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1189 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1190 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1192 if (!limited_range || pp->pln_range > pp->pln_range_max)
1193 pp->pln_range = pp->pln_range_max;