2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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)
70 nships = carriersatxy(target->sct_x, target->sct_y,
71 M_FLY | M_CHOPPER, 0, player->cnum);
74 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
78 || !getship(cno, &ship)
80 && (getrel(getnatp(ship.shp_own), player->cnum)
85 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
86 pr("Ship #%d not in %s\n", cno,
87 xyas(target->sct_x, target->sct_y, player->cnum));
90 if ((!(mchr[(int)ship.shp_type].m_flags & M_FLY)
91 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
92 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER))
93 || ship.shp_effic < SHP_AIROPS_EFF) {
94 pr("Can't land on %s.\n", prship(&ship));
98 /* clear to land on ship#CNO */
99 pr("landing on carrier %d\n", cno);
100 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
102 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
104 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
112 /* try to land at sector */
113 if (target->sct_own != player->cnum
114 && getrel(getnatp(target->sct_own), player->cnum) != ALLIED) {
115 pr("Nowhere to land at sector %s!\n",
116 xyas(target->sct_x, target->sct_y, player->cnum));
119 if (target->sct_type == SCT_MOUNT) {
120 pr("Nowhere to land at sector %s!\n",
121 xyas(target->sct_x, target->sct_y, player->cnum));
124 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
127 /* clear to land at sector */
134 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
135 struct emp_qelem *esc_list, int cno)
137 struct emp_qelem *list, *qp;
139 struct plchrstr *pcp;
142 int nchoppers, nxlight, nplane;
144 if (cno < 0 || !getship(cno, &ship))
148 nchoppers = ship.shp_nchoppers;
149 nxlight = ship.shp_nxlight;
150 nplane = ship.shp_nplane;
151 mcp = &mchr[(int)ship.shp_type];
154 for (list = bomb_list;
156 list = list == bomb_list ? esc_list : NULL) {
157 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
158 /* FIXME duplicates put_plane_on_ship() logic; refactor */
159 plp = (struct plist *)qp;
160 pcp = &plchr[(int)plp->plane.pln_type];
161 if (plp->plane.pln_ship == ship.shp_uid)
163 /* try chopper space */
164 if ((pcp->pl_flags & P_K) && (mcp->m_flags & M_CHOPPER)
165 && nchoppers < mcp->m_nchoppers)
167 /* try xlight space */
168 else if ((pcp->pl_flags & P_E) && (mcp->m_flags & M_XLIGHT)
169 && nxlight < mcp->m_nxlight)
171 /* try plane space */
172 else if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY))
173 || ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L)
174 && (mcp->m_flags & M_MSL)))
175 && nplane < mcp->m_nplanes)
178 return 0; /* won't be able to land */
185 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
187 struct emp_qelem *qp;
194 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
195 plp = (struct plist *)qp;
198 if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
199 pr("\t%s cannot land on ship #%d! %s aborts!\n",
200 prplane(&plp->plane), cno, prplane(&plp->plane));
201 else if (!put_plane_on_ship(&plp->plane, &ship))
202 pr("\tNo room on ship #%d! %s aborts!\n", cno,
203 prplane(&plp->plane));
205 if (plp->plane.pln_own != ship.shp_own) {
206 /* plp->plane.pln_own = ship.shp_own;*/
208 "%s %s lands on your %s\n",
210 prplane(&plp->plane), prship(&ship));
214 plp->plane.pln_x = tx;
215 plp->plane.pln_y = ty;
216 getsect(tx, ty, §);
217 if (plp->plane.pln_own != sect.sct_own) {
218 /* plp->plane.pln_own = sect.sct_own;*/
220 "%s %s lands at your sector %s\n",
222 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
224 plp->plane.pln_ship = cno;
228 putship(ship.shp_uid, &ship);
232 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
235 struct emp_qelem *qp;
238 struct sctstr *sectp;
247 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
248 plp = (struct plist *)qp;
251 if (type == EF_SECTOR) {
253 if (!sectp->sct_own) {
254 if (sectp->sct_type == SCT_WATER)
255 pr("Your %s sink like a rock!\n", ip->i_name);
257 pr("Your %s vanish without a trace.\n", ip->i_name);
260 if (sectp->sct_own != player->cnum
261 && getrel(getnatp(sectp->sct_own), player->cnum) != ALLIED) {
262 pr("You don't own %s! Cargo jettisoned...\n",
263 xyas(tx, ty, player->cnum));
266 if (ip->i_vtype == I_CIVIL && sectp->sct_own != sectp->sct_oldown) {
267 pr("%s is occupied. Your civilians suffer from identity crisis and die.\n",
268 xyas(tx, ty, player->cnum));
271 there = sectp->sct_item[ip->i_vtype];
275 there = sp->shp_item[ip->i_vtype];
276 mp = &mchr[(int)sp->shp_type];
277 max = mp->m_item[ip->i_vtype];
281 pr("%d excess %s discarded\n", max - there, ip->i_name);
285 pr("%d %s landed safely", amt, ip->i_name);
286 if (type == EF_SECTOR) {
288 sectp->sct_item[ip->i_vtype] = there;
289 if (sectp->sct_own != player->cnum)
290 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
291 cname(player->cnum), amt, ip->i_name,
292 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
293 pr(" at %s\n", xyas(tx, ty, player->cnum));
294 putsect((struct sctstr *)ptr);
296 struct shpstr *sp = (struct shpstr *)ptr;
297 sp->shp_item[ip->i_vtype] = there;
298 if (sp->shp_own != player->cnum)
299 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
300 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
301 pr(" on carrier #%d\n", sp->shp_uid);
302 putship(sp->shp_uid, sp);
307 pln_mine(struct emp_qelem *list, struct sctstr *sectp)
309 struct emp_qelem *qp;
314 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
315 plp = (struct plist *)qp;
320 sectp->sct_mines = min(sectp->sct_mines + amt, MINES_MAX);
321 pr("%d mines laid in %s.\n", amt,
322 xyas(sectp->sct_x, sectp->sct_y, player->cnum));
323 if (map_set(player->cnum, sectp->sct_x, sectp->sct_y, 'X', 0))
324 writemap(player->cnum);
330 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
331 int ap_to_target, int rangemult, int wantflags, int nowantflags)
338 struct plchrstr *pcp;
341 register int bad, bad1;
345 while (nxtitem(ni, (s_char *)&plane)) {
348 if (plane.pln_mobil <= (s_char)0)
351 if (ontradingblock(EF_PLANE, (int *)&plane)) {
352 pr("plane #%d inelligible - it's for sale.\n",
358 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
360 pr("%s too far from assembly point\n", prplane(&plane));
363 if (plane.pln_effic < 40) {
364 pr("%s not efficient enough (must be 40%%)\n",
368 range += ap_to_target;
369 pcp = &plchr[(int)plane.pln_type];
373 for (x = 0; x < sizeof(wantflags) * 8; x++) {
375 if ((wantflags & y) == y)
376 if ((pcp->pl_flags & y) != y) {
395 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
399 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
401 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
403 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
412 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
414 if ((nowantflags & y) == y)
415 if ((pcp->pl_flags & y) == y)
422 if (plane.pln_range < range) {
423 pr("%s out of range (%d:%d)\n", prplane(&plane),
424 plane.pln_range, range);
427 if (plane.pln_ship >= 0) {
428 if (!getship(plane.pln_ship, &ship) ||
429 plane.pln_own != player->cnum) {
432 pr("(note) ship not valid for %s\n", prplane(&plane));
433 putplane(plane.pln_uid, &plane);
436 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
438 if (ship.shp_effic < SHIP_MINEFF)
440 if (ship.shp_effic < SHP_AIROPS_EFF)
442 /* Can't fly off non-owned ships or non-allied ship */
443 if ((ship.shp_own != player->cnum) &&
444 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
445 pr("(note) An ally does not own the ship %s is on\n",
450 if (plane.pln_land >= 0) {
451 if (!getland(plane.pln_land, &land) ||
452 (plane.pln_own != player->cnum)) {
455 pr("(note) land unit not valid for %s\n", prplane(&plane));
456 putplane(plane.pln_uid, &plane);
459 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
461 if (land.lnd_effic < LAND_MINEFF)
463 if (land.lnd_effic < LND_AIROPS_EFF)
465 /* Can't fly off units in ships or other units */
466 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
468 /* Can't fly off non-owned units or non-allied unit */
469 if ((land.lnd_own != player->cnum) &&
470 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
471 pr("(note) An ally does not own the unit %s is on\n",
476 /* Now, check the sector status if not on a plane or unit */
477 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
478 if (!getsect(plane.pln_x, plane.pln_y, §))
480 /* First, check allied status */
481 /* Can't fly from non-owned sectors or non-allied sectors */
482 if ((sect.sct_own != player->cnum) &&
483 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
484 pr("(note) An ally does not own the sector %s is in\n",
489 if ((pcp->pl_flags & P_V) == 0) {
490 if (sect.sct_type != SCT_AIRPT) {
491 pr("%s not at airport\n", prplane(&plane));
494 if (sect.sct_effic < 40) {
495 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));
498 if (rangemult == 2 && sect.sct_effic < 60) {
499 pr("%s is not 60%% efficient, %s can't land there.\n",
500 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
506 pr("%s standing by\n", prplane(&plane));
507 plane.pln_mission = 0;
508 putplane(plane.pln_uid, &plane);
509 plp = (struct plist *)malloc(sizeof(struct plist));
515 emp_insque(&plp->queue, list);
520 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
521 int flags, int mission_flags)
523 struct emp_qelem *qp;
524 struct emp_qelem *next;
527 for (qp = list->q_forw; qp != list; qp = next) {
529 plp = (struct plist *)qp;
530 if (pln_equip(plp, ip, flags, mission) < 0) {
535 if (flags & (P_S | P_I)) {
536 if (plp->pcp->pl_flags & P_S)
537 mission_flags |= P_S;
538 if (plp->pcp->pl_flags & P_I)
539 mission_flags |= P_I;
541 if (!(plp->pcp->pl_flags & P_H))
542 /* no stealth on this mission */
543 mission_flags &= ~P_H;
544 if (!(plp->pcp->pl_flags & P_X))
545 /* no stealth on this mission */
546 mission_flags &= ~P_X;
547 if (!(plp->pcp->pl_flags & P_A)) {
548 /* no asw on this mission */
549 mission_flags &= ~P_A;
551 if (!(plp->pcp->pl_flags & P_MINE)) {
552 /* no asw on this mission */
553 mission_flags &= ~P_MINE;
555 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
556 pr("%s equipped\n", prplane(&plp->plane));
558 return mission_flags;
562 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
564 register struct plchrstr *pcp;
577 if (pp->pln_ship >= 0) {
578 getship(pp->pln_ship, &ship);
579 item = ship.shp_item;
581 } else if (pp->pln_land >= 0) {
582 getland(pp->pln_land, &land);
583 item = land.lnd_item;
586 getsect(pp->pln_x, pp->pln_y, §);
587 item = sect.sct_item;
588 own = sect.sct_oldown;
591 if (ip->i_vtype == I_CIVIL) {
592 if (pp->pln_own != own) {
593 pr("You don't control those civilians!\n");
598 if (pcp->pl_fuel > item[I_PETROL]) {
599 pr("%s not enough petrol there!\n", prplane(pp));
602 item[I_PETROL] -= pcp->pl_fuel;
604 if ((flags & P_F) == 0) {
610 if (pp->pln_nuketype == -1) {
612 needed = pp->pln_load;
616 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
619 needed = (pp->pln_load * 2) / ip->i_lbs;
623 needed = (pp->pln_load * 2) / ip->i_lbs;
624 /* Is this mine dropping excursion? */
625 if (itype == I_SHELL && (pcp->pl_flags & P_MINE))
627 /* Is this a cargo drop? */
628 if ((pcp->pl_flags & P_C) == 0 || ip == 0) {
635 if ((pcp->pl_flags & (P_V | P_C)) == 0)
638 needed = pp->pln_load / ip->i_lbs;
641 if (pp->pln_nuketype == (s_char)-1)
647 if (rval < 0 || (itype && needed <= 0)) {
648 pr("%s can't contribute to mission\n", prplane(pp));
652 /* Supply is broken somewhere, so don't use it for now */
653 if (item[itype] < needed && itype == I_SHELL)
654 item[itype] += supply_commod(plp->plane.pln_own,
655 plp->plane.pln_x, plp->plane.pln_y,
658 if (item[itype] < needed) {
659 pr("Not enough %s for %s\n", ichr[itype].i_name, prplane(pp));
662 item[itype] -= needed;
664 if (itype == I_SHELL && (mission == 's' || mission == 'p'))
669 if (pp->pln_ship >= 0) {
670 if (pp->pln_own != ship.shp_own) {
672 "%s %s prepares for takeoff from ship %s\n",
673 cname(pp->pln_own), prplane(pp), prship(&ship));
675 putship(ship.shp_uid, &ship);
676 } else if (pp->pln_land >= 0) {
677 if (pp->pln_own != land.lnd_own) {
679 "%s %s prepares for takeoff from unit %s\n",
680 cname(pp->pln_own), prplane(pp), prland(&land));
682 putland(land.lnd_uid, &land);
684 if (pp->pln_own != sect.sct_own) {
685 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
686 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
696 pln_put(struct emp_qelem *list)
698 register struct emp_qelem *qp;
699 register struct emp_qelem *newqp;
705 /* Here is where planes return home from bombing runs.
706 We need to make sure they still have somewhere to return
710 plp = (struct plist *)qp;
712 /* Ok, check out where it wants to land */
713 if (pp->pln_ship >= 0) {
714 /* It is landing on a carrier */
715 getship(pp->pln_ship, &ship);
716 /* We should do more, like make sure it's really
717 a carrier, etc. but for now just make sure it's
719 if (ship.shp_effic < SHIP_MINEFF) {
721 "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n",
722 pp->pln_ship, pp->pln_uid);
726 /* Presume we are landing back in a sector. */
727 getsect(pp->pln_x, pp->pln_y, §);
728 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
730 "Nowhere to land at %s, plane #%d crashes and burns...\n",
731 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
735 putplane(pp->pln_uid, pp);
744 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
746 struct emp_qelem *bomb;
747 struct emp_qelem *esc;
751 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
753 bomb = bomb_list->q_forw;
754 while (bomb != bomb_list) {
755 if (QEMPTY(esc_list)) {
759 esc = esc_list->q_forw;
760 bombp = (struct plist *)bomb;
761 while (esc != esc_list) {
762 escp = (struct plist *)esc;
763 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
775 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
777 struct plchrstr *pcp;
780 pcp = &plchr[(int)plane->pln_type];
781 mcp = &mchr[(int)ship->shp_type];
783 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
784 return 1; /* Already on ship */
786 /* Try to put on ship as a chopper plane */
787 if ((pcp->pl_flags & P_K) &&
788 (mcp->m_flags & M_CHOPPER) &&
789 (ship->shp_nchoppers < mcp->m_nchoppers)) {
791 ship->shp_nchoppers++;
792 plane->pln_x = ship->shp_x;
793 plane->pln_y = ship->shp_y;
794 plane->pln_ship = ship->shp_uid;
795 putship(ship->shp_uid, ship);
796 putplane(plane->pln_uid, plane);
800 /* Try to put on ship as an xlight plane */
801 if ((pcp->pl_flags & P_E) &&
802 (mcp->m_flags & M_XLIGHT) &&
803 (ship->shp_nxlight < mcp->m_nxlight)) {
806 plane->pln_x = ship->shp_x;
807 plane->pln_y = ship->shp_y;
808 plane->pln_ship = ship->shp_uid;
809 putship(ship->shp_uid, ship);
810 putplane(plane->pln_uid, plane);
814 /* Try to put on ship as a normal plane */
815 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
816 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
817 (mcp->m_flags & M_MSL))) &&
818 (ship->shp_nplane < mcp->m_nplanes)) {
821 plane->pln_x = ship->shp_x;
822 plane->pln_y = ship->shp_y;
823 plane->pln_ship = ship->shp_uid;
824 putship(ship->shp_uid, ship);
825 putplane(plane->pln_uid, plane);
834 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
836 struct plchrstr *pcp;
839 pcp = &plchr[(int)plane->pln_type];
840 mcp = &mchr[(int)ship->shp_type];
842 /* Try to take off ship as a chopper plane */
843 if ((pcp->pl_flags & P_K) &&
844 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
846 ship->shp_nchoppers--;
847 plane->pln_ship = -1;
848 putship(ship->shp_uid, ship);
849 putplane(plane->pln_uid, plane);
853 /* Try to take off ship as an xlight plane */
854 if ((pcp->pl_flags & P_E) &&
855 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
858 plane->pln_ship = -1;
859 putship(ship->shp_uid, ship);
860 putplane(plane->pln_uid, plane);
864 /* Try to take off ship as a normal plane */
865 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
866 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
867 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
870 plane->pln_ship = -1;
871 putship(ship->shp_uid, ship);
872 putplane(plane->pln_uid, plane);
881 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
883 struct plchrstr *pcp;
886 pcp = &plchr[(int)plane->pln_type];
887 lcp = &lchr[(int)land->lnd_type];
889 /* Try to take off ship as an xlight plane */
890 if ((pcp->pl_flags & P_E) &&
891 (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) {
894 plane->pln_land = -1;
895 putland(land->lnd_uid, land);
896 putplane(plane->pln_uid, plane);
905 can_be_on_ship(int p, int s)
909 struct plchrstr *pcp;
915 pcp = &plchr[(int)plane.pln_type];
916 mcp = &mchr[(int)ship.shp_type];
918 if (pcp->pl_flags & P_L)
919 if (mcp->m_flags & M_FLY)
922 if (pcp->pl_flags & P_K)
923 if (mcp->m_flags & M_CHOPPER)
926 if (pcp->pl_flags & P_M)
927 if (mcp->m_flags & M_MSL)
930 if (pcp->pl_flags & P_E)
931 if (mcp->m_flags & M_XLIGHT)
938 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
941 struct plchrstr *pcp;
942 struct emp_qelem *qp;
943 struct emp_qelem *next;
949 getsect(x, y, §);
950 mines_there = sect.sct_mines;
952 if (mines_there == 0)
955 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
958 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
961 ip = (struct plist *)qp;
964 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
967 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
969 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
975 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
976 writemap(player->cnum);
977 sect.sct_mines = mines_there;
982 count_planes(struct shpstr *sp)
986 struct plchrstr *pcp;
992 if (sp->shp_effic < SHIP_MINEFF)
995 mcp = &mchr[(int)sp->shp_type];
996 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
997 while (nxtitem(&ni, (s_char *)&plane)) {
998 if (plane.pln_own == 0)
1000 if (plane.pln_ship == sp->shp_uid) {
1001 pcp = &plchr[(int)plane.pln_type];
1002 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
1004 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
1006 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
1011 if (nplane != sp->shp_nplane ||
1012 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
1013 sp->shp_nplane = nplane;
1014 sp->shp_nxlight = nxlight;
1015 sp->shp_nchoppers = nchoppers;
1016 putship(sp->shp_uid, sp);
1021 count_land_planes(struct lndstr *lp)
1023 struct nstr_item ni;
1024 struct plnstr plane;
1027 if (lp->lnd_effic < LAND_MINEFF)
1030 snxtitem_all(&ni, EF_PLANE);
1031 while (nxtitem(&ni, (s_char *)&plane)) {
1032 if (plane.pln_own == 0)
1034 if (plane.pln_land == lp->lnd_uid)
1038 if (lp->lnd_nxlight != nplane) {
1039 lp->lnd_nxlight = nplane;
1040 putland(lp->lnd_uid, lp);
1045 count_sect_planes(struct sctstr *sp)
1048 struct nstr_item ni;
1049 struct plnstr plane;
1051 snxtitem_all(&ni, EF_PLANE);
1052 while (nxtitem(&ni, (s_char *)&plane)) {
1055 if (plane.pln_flags & PLN_LAUNCHED)
1057 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1065 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1067 struct plchrstr *pcp;
1068 struct lchrstr *lcp;
1070 pcp = &plchr[(int)plane->pln_type];
1071 lcp = &lchr[(int)land->lnd_type];
1073 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1074 return 1; /* Already on unit */
1076 /* Try to put on unit as an xlight plane */
1077 if ((pcp->pl_flags & P_E) &&
1078 (lcp->l_flags & L_XLIGHT) &&
1079 (land->lnd_nxlight < lcp->l_nxlight)) {
1081 land->lnd_nxlight++;
1082 plane->pln_x = land->lnd_x;
1083 plane->pln_y = land->lnd_y;
1084 plane->pln_land = land->lnd_uid;
1085 putland(land->lnd_uid, land);
1086 putplane(plane->pln_uid, plane);
1090 /* We have failed */
1095 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1097 struct plchrstr *pcp = plchr + pp->pln_type;
1098 float tfact = (float)(pp->pln_tech - pcp->pl_tech) /
1099 (pp->pln_tech - pcp->pl_tech / 2);
1100 int acc = pp->pln_acc;
1103 if (type == EF_SHIP) {
1104 if (pcp->pl_flags & P_A)
1106 if (!(pcp->pl_flags & P_T))
1109 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1110 (1.0 - (float)acc / 100.0)) - hardtarget;
1112 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1114 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1115 if (hitchance > 100)
1120 /* return 0 if there was a nuclear detonation */
1123 pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp,
1126 struct plchrstr *pcp = plchr + pp->pln_type;
1134 if (pp->pln_nuketype != (s_char)-1) {
1135 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1136 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1137 *nukedamp = detonate(pp, x, y);
1142 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1145 i = roll(pp->pln_load) + 1;
1146 if (i > pp->pln_load)
1149 if (pcp->pl_flags & P_M) {
1150 if (pcp->pl_flags & P_MAR)
1152 } else if (pcp->pl_flags & P_T)
1155 aim = 100 - pp->pln_acc;
1169 hitroll = roll(100);
1170 if (hitroll >= 90) {
1173 mpr(pp->pln_own, "BLAM");
1174 } else if (hitroll < aim) {
1177 mpr(pp->pln_own, "Blam");
1181 mpr(pp->pln_own, "blam");
1184 mpr(pp->pln_own, "-");
1187 mpr(pp->pln_own, "\n");
1194 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1197 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1198 return (int)(100 - 100 * misschance * misschance);
1202 pln_mobcost(int dist, struct plnstr *pp, int flags)
1206 if ((flags & P_F) || (flags & P_ESC))
1207 cost = 10 * 100 / pp->pln_effic;
1209 cost = 20 * 100 / pp->pln_effic;
1211 cost = ldround((double)cost * dist / pp->pln_range_max, 1);
1213 return min(32 + pp->pln_mobil, cost + 5);
1217 * Set PP's tech to TLEV along with everything else that depends on it.
1220 pln_set_tech(struct plnstr *pp, int tlev)
1222 struct plchrstr *pcp = plchr + pp->pln_type;
1223 int tech_diff = tlev - pcp->pl_tech;
1224 int limited_range = pp->pln_range < pp->pln_range_max;
1226 if (CANT_HAPPEN(tech_diff < 0)) {
1231 pp->pln_tech = tlev;
1232 pp->pln_att = PLN_ATTDEF(pcp->pl_att, tech_diff);
1233 pp->pln_def = PLN_ATTDEF(pcp->pl_def, tech_diff);
1234 pp->pln_acc = PLN_ACC(pcp->pl_acc, tech_diff);
1235 pp->pln_range_max = PLN_RAN(pcp->pl_range, tech_diff);
1236 pp->pln_load = PLN_LOAD(pcp->pl_load, tech_diff);
1238 if (!limited_range || pp->pln_range > pp->pln_range_max)
1239 pp->pln_range = pp->pln_range_max;