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
51 #include "prototypes.h"
55 pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
66 if ((target->sct_own && target->sct_own != player->cnum &&
67 (getrel(getnatp(target->sct_own), player->cnum) != ALLIED)) &&
68 (target->sct_type != SCT_HARBR) &&
69 (target->sct_type != SCT_BSPAN)) {
70 pr("Nowhere to land at sector %s!\n",
71 xyas(target->sct_x, target->sct_y, player->cnum));
74 if (target->sct_type == SCT_MOUNT) {
75 pr("Nowhere to land at sector %s!\n",
76 xyas(target->sct_x, target->sct_y, player->cnum));
80 if (target->sct_type != SCT_AIRPT || target->sct_effic < 60)
82 if (target->sct_type == SCT_WATER || target->sct_type == SCT_HARBR
83 || target->sct_type == SCT_BSPAN) {
84 nships = carriersatxy(target->sct_x, target->sct_y,
85 M_FLY | M_CHOPPER, 0, player->cnum);
87 if (target->sct_type == SCT_WATER) {
88 pr("Nowhere to land at sector %s!\n",
89 xyas(target->sct_x, target->sct_y, player->cnum));
92 if ((target->sct_own && target->sct_own != player->cnum)
93 && (getrel(getnatp(target->sct_own), player->cnum) !=
95 pr("Nowhere to land at sector %s!\n",
96 xyas(target->sct_x, target->sct_y, player->cnum));
107 if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
110 if (n < 0 || !getship(n, &ship) || (!player->owner &&
112 (getnatp(ship.shp_own),
118 if (ship.shp_x != target->sct_x || ship.shp_y != target->sct_y) {
119 pr("Ship #%d not in %s\n", n,
120 xyas(target->sct_x, target->sct_y, player->cnum));
123 if (!(mchr[(int)ship.shp_type].m_flags & M_FLY)
124 && !(mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
125 && !(mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
127 pr("Can't land on %s.\n", prship(&ship));
130 pr("landing on carrier %d\n", n);
133 if (mchr[(int)ship.shp_type].m_flags & M_FLY)
135 if (mchr[(int)ship.shp_type].m_flags & M_CHOPPER)
137 if (mchr[(int)ship.shp_type].m_flags & M_XLIGHT)
140 if ((target->sct_own && target->sct_own != player->cnum) &&
141 (getrel(getnatp(target->sct_own), player->cnum) != ALLIED) &&
143 pr("Nowhere to land at sector %s!\n",
144 xyas(target->sct_x, target->sct_y, player->cnum));
149 if ((target->sct_own == 0) && (cno < 0)) {
150 pr("Nowhere to land at sector %s!\n",
151 xyas(target->sct_x, target->sct_y, player->cnum));
161 pln_newlanding(struct emp_qelem *list, coord tx, coord ty, int cno)
163 struct emp_qelem *qp;
170 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
171 plp = (struct plist *)qp;
172 /* XXX - need to restrict # of planes per ship */
175 if (!can_be_on_ship(plp->plane.pln_uid, ship.shp_uid))
176 pr("\t%s cannot land on ship #%d! %s aborts!\n",
177 prplane(&plp->plane), cno, prplane(&plp->plane));
178 else if (!put_plane_on_ship(&plp->plane, &ship))
179 pr("\tNo room on ship #%d! %s aborts!\n", cno,
180 prplane(&plp->plane));
182 if (plp->plane.pln_own != ship.shp_own) {
183 /* plp->plane.pln_own = ship.shp_own;*/
185 "%s %s lands on your %s\n",
187 prplane(&plp->plane), prship(&ship));
191 plp->plane.pln_x = tx;
192 plp->plane.pln_y = ty;
193 getsect(tx, ty, §);
194 if (plp->plane.pln_own != sect.sct_own) {
195 /* plp->plane.pln_own = sect.sct_own;*/
197 "%s %s lands at your sector %s\n",
199 prplane(&plp->plane), xyas(tx, ty, sect.sct_own));
201 plp->plane.pln_ship = cno;
205 putship(ship.shp_uid, &ship);
209 pln_dropoff(struct emp_qelem *list, struct ichrstr *ip, coord tx, coord ty,
210 s_char *ptr, int type)
212 struct emp_qelem *qp;
224 for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
225 plp = (struct plist *)qp;
228 if (type == EF_SECTOR &&
229 (((struct sctstr *)ptr)->sct_type == SCT_WATER) &&
230 ip->i_vtype == V_SHELL) {
231 mines_there = getvar(V_MINE, ptr, EF_SECTOR);
232 putvar(V_MINE, amt + mines_there, ptr, EF_SECTOR);
233 pr("%d mines laid in %s.\n", amt,
234 xyas(((struct sctstr *)ptr)->sct_x,
235 ((struct sctstr *)ptr)->sct_y, player->cnum));
237 map_set(player->cnum, ((struct sctstr *)ptr)->sct_x,
238 ((struct sctstr *)ptr)->sct_y, 'X', 0))
239 writemap(player->cnum);
240 putsect((struct sctstr *)ptr);
242 there = getvar(ip->i_vtype, ptr, type) + amt;
244 if (type == EF_SHIP) {
245 ship = (struct shpstr *)ptr;
246 mp = &mchr[(int)ship->shp_type];
247 max = vl_find(ip->i_vtype, mp->m_vtype,
248 mp->m_vamt, (int)mp->m_nv);
251 pr("%d excess %s discarded\n", max - there, ip->i_name);
255 putvar(ip->i_vtype, there, ptr, type);
256 pr("%d %s landed safely", amt, ip->i_name);
257 if (type == EF_SECTOR) {
258 struct sctstr *sectp = (struct sctstr *)ptr;
259 if (sectp->sct_own != player->cnum)
260 wu(0, sectp->sct_own, "%s planes drop %d %s in %s\n",
261 cname(player->cnum), amt, ip->i_name,
262 xyas(sectp->sct_x, sectp->sct_y, sectp->sct_own));
263 pr(" at %s\n", xyas(tx, ty, player->cnum));
264 putsect((struct sctstr *)ptr);
266 struct shpstr *sp = (struct shpstr *)ptr;
267 if (sp->shp_own != player->cnum)
268 wu(0, sp->shp_own, "%s planes land %d %s on carrier %d\n",
269 cname(player->cnum), amt, ip->i_name, sp->shp_uid);
270 pr(" on carrier #%d\n", ship->shp_uid);
271 putship(ship->shp_uid, ship);
277 pln_sel(struct nstr_item *ni, struct emp_qelem *list, struct sctstr *ap,
278 int ap_to_target, int rangemult, int wantflags, int nowantflags)
285 struct plchrstr *pcp;
288 register int bad, bad1;
292 while (nxtitem(ni, (s_char *)&plane)) {
295 if (plane.pln_mobil <= (s_char)0)
298 if (ontradingblock(EF_PLANE, (int *)&plane)) {
299 pr("plane #%d inelligible - it's for sale.\n",
305 range = mapdist(plane.pln_x, plane.pln_y, ap->sct_x, ap->sct_y);
307 pr("%s too far from assembly point\n", prplane(&plane));
310 if (plane.pln_effic < 40) {
311 pr("%s not efficient enough (must be 40%%)\n",
315 range += ap_to_target;
316 pcp = &plchr[(int)plane.pln_type];
320 for (x = 0; x < sizeof(wantflags) * 8; x++) {
322 if ((wantflags & y) == y)
323 if ((pcp->pl_flags & y) != y) {
342 if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
346 if ((wantflags & P_L) && (pcp->pl_flags & P_L))
348 if ((wantflags & P_K) && (pcp->pl_flags & P_K))
350 if ((wantflags & P_E) && (pcp->pl_flags & P_E))
359 for (x = 0; x < sizeof(nowantflags) * 8; x++) {
361 if ((nowantflags & y) == y)
362 if ((pcp->pl_flags & y) == y)
369 if (plane.pln_range < range) {
370 pr("%s out of range (%d:%d)\n", prplane(&plane),
371 plane.pln_range, range);
374 if (plane.pln_ship >= 0) {
375 if (!getship(plane.pln_ship, &ship) ||
376 plane.pln_own != player->cnum) {
379 pr("(note) ship not valid for %s\n", prplane(&plane));
380 putplane(plane.pln_uid, &plane);
383 if (!can_be_on_ship(plane.pln_uid, ship.shp_uid))
385 if (ship.shp_effic < SHIP_MINEFF)
387 if (ship.shp_effic < 50)
389 /* Can't fly off non-owned ships or non-allied ship */
390 if ((ship.shp_own != player->cnum) &&
391 (getrel(getnatp(ship.shp_own), player->cnum) != ALLIED)) {
392 pr("(note) An ally does not own the ship %s is on\n",
397 if (plane.pln_land >= 0) {
398 if (!getland(plane.pln_land, &land) ||
399 (plane.pln_own != player->cnum)) {
402 pr("(note) land unit not valid for %s\n", prplane(&plane));
403 putplane(plane.pln_uid, &plane);
406 if (!(plchr[(int)plane.pln_type].pl_flags & P_E))
408 if (land.lnd_effic < LAND_MINEFF)
410 if (land.lnd_effic < 50)
412 /* Can't fly off units in ships or other units */
413 if ((land.lnd_ship >= 0) || (land.lnd_land >= 0))
415 /* Can't fly off non-owned units or non-allied unit */
416 if ((land.lnd_own != player->cnum) &&
417 (getrel(getnatp(land.lnd_own), player->cnum) != ALLIED)) {
418 pr("(note) An ally does not own the unit %s is on\n",
423 /* Now, check the sector status if not on a plane or unit */
424 if ((plane.pln_ship < 0) && (plane.pln_land < 0)) {
425 if (!getsect(plane.pln_x, plane.pln_y, §))
427 /* First, check allied status */
428 /* Can't fly from non-owned sectors or non-allied sectors */
429 if ((sect.sct_own != player->cnum) &&
430 (getrel(getnatp(sect.sct_own), player->cnum) != ALLIED)) {
431 pr("(note) An ally does not own the sector %s is in\n",
436 if ((pcp->pl_flags & P_V) == 0) {
437 if (sect.sct_type != SCT_AIRPT) {
438 pr("%s not at airport\n", prplane(&plane));
441 if (sect.sct_effic < 40) {
442 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));
445 if (rangemult == 2 && sect.sct_effic < 60) {
446 pr("%s is not 60%% efficient, %s can't land there.\n",
447 xyas(sect.sct_x, sect.sct_y, plane.pln_own),
453 pr("%s standing by\n", prplane(&plane));
454 plane.pln_mission = 0;
455 putplane(plane.pln_uid, &plane);
456 plp = (struct plist *)malloc(sizeof(struct plist));
461 bcopy((s_char *)&plane, (s_char *)&plp->plane,
462 sizeof(struct plnstr));
463 emp_insque(&plp->queue, list);
468 pln_arm(struct emp_qelem *list, int dist, int mission, struct ichrstr *ip,
469 int flags, int mission_flags, int *tech)
471 struct emp_qelem *qp;
472 struct emp_qelem *next;
477 for (qp = list->q_forw; qp != list; qp = next) {
479 plp = (struct plist *)qp;
480 if (pln_equip(plp, ip, flags, mission) < 0) {
485 if (flags & (P_S | P_I)) {
486 if (plp->pcp->pl_flags & P_S)
487 mission_flags |= P_S;
488 if (plp->pcp->pl_flags & P_I)
489 mission_flags |= P_I;
491 if (*tech > plp->plane.pln_tech)
492 *tech = plp->plane.pln_tech;
493 if (!(plp->pcp->pl_flags & P_H))
494 /* no stealth on this mission */
495 mission_flags &= ~P_H;
496 if (!(plp->pcp->pl_flags & P_X))
497 /* no stealth on this mission */
498 mission_flags &= ~P_X;
499 if (!(plp->pcp->pl_flags & P_A)) {
500 /* no asw on this mission */
501 mission_flags &= ~P_A;
503 if (!(plp->pcp->pl_flags & P_MINE)) {
504 /* no asw on this mission */
505 mission_flags &= ~P_MINE;
507 plp->plane.pln_mobil -= pln_mobcost(dist, &plp->plane, flags);
508 pr("%s equipped\n", prplane(&plp->plane));
510 return mission_flags;
514 pln_equip(struct plist *plp, struct ichrstr *ip, int flags, s_char mission)
516 register struct plchrstr *pcp;
531 if (pp->pln_ship >= 0) {
532 getship(pp->pln_ship, &ship);
534 ptr = (s_char *)&ship;
536 } else if (pp->pln_land >= 0) {
537 getland(pp->pln_land, &land);
539 ptr = (s_char *)&land;
542 getsect(pp->pln_x, pp->pln_y, §);
544 ptr = (s_char *)§
545 own = sect.sct_oldown;
548 if (ip->i_vtype == V_CIVIL) {
549 if (pp->pln_own != own) {
550 pr("You don't control those civilians!\n");
555 getvec(VT_ITEM, vec, ptr, type);
556 if (pcp->pl_fuel > vec[I_PETROL]) {
557 pr("%s not enough petrol there!\n", prplane(pp));
560 vec[I_PETROL] -= pcp->pl_fuel;
562 if ((flags & P_F) == 0) {
568 if (pp->pln_nuketype == -1) {
570 needed = pp->pln_load;
574 if ((pcp->pl_flags & P_C) == 0 || ip == 0)
577 needed = (pp->pln_load * 2) / ip->i_lbs;
581 needed = (pp->pln_load * 2) / ip->i_lbs;
582 /* Is this mine dropping excursion? */
583 if ((item == I_SHELL) && (pcp->pl_flags & P_MINE))
585 /* Is this a cargo drop? */
586 if ((pcp->pl_flags & P_C) == 0 || ip == 0) {
593 if ((pcp->pl_flags & (P_V | P_C)) == 0)
596 needed = pp->pln_load / ip->i_lbs;
599 if (pp->pln_nuketype == (s_char)-1)
605 if (rval < 0 || (item && needed <= 0)) {
606 pr("%s can't contribute to mission\n", prplane(pp));
610 /* Supply is broken somewhere, so don't use it for now */
611 if ((vec[item] < needed) && (item == I_SHELL))
612 vec[item] += supply_commod(plp->plane.pln_own,
613 plp->plane.pln_x, plp->plane.pln_y,
616 if (vec[item] < needed) {
617 pr("Not enough %s for %s\n", ichr[item].i_name, prplane(pp));
622 if (item == I_SHELL && (mission == 's' || mission == 'p'))
627 putvec(VT_ITEM, vec, ptr, type);
628 if (type == EF_SHIP) {
629 if (pp->pln_own != ship.shp_own) {
631 "%s %s prepares for takeoff from ship %s\n",
632 cname(pp->pln_own), prplane(pp), prship(&ship));
634 putship(ship.shp_uid, &ship);
635 } else if (type == EF_LAND) {
636 if (pp->pln_own != land.lnd_own) {
638 "%s %s prepares for takeoff from unit %s\n",
639 cname(pp->pln_own), prplane(pp), prland(&land));
641 putland(land.lnd_uid, &land);
643 if (pp->pln_own != sect.sct_own) {
644 wu(0, sect.sct_own, "%s %s prepares for takeoff from %s\n",
645 cname(pp->pln_own), prplane(pp), xyas(sect.sct_x,
655 pln_put(struct emp_qelem *list)
657 register struct emp_qelem *qp;
658 register struct emp_qelem *newqp;
664 /* Here is where planes return home from bombing runs.
665 We need to make sure they still have somewhere to return
669 plp = (struct plist *)qp;
671 /* Ok, check out where it wants to land */
672 if (pp->pln_ship >= 0) {
673 /* It is landing on a carrier */
674 getship(pp->pln_ship, &ship);
675 /* We should do more, like make sure it's really
676 a carrier, etc. but for now just make sure it's
678 if (ship.shp_effic < SHIP_MINEFF) {
680 "Ship #%d has been sunk, plane #%d has nowhere to land, and\nsplashes into the sea.\n",
681 pp->pln_ship, pp->pln_uid);
685 /* Presume we are landing back in a sector. */
686 getsect(pp->pln_x, pp->pln_y, §);
687 if (sect.sct_type == SCT_WATER || sect.sct_type == SCT_WASTE) {
689 "Nowwhere to land at %s, plane #%d crashes and burns...\n",
690 xyas(pp->pln_x, pp->pln_y, pp->pln_own), pp->pln_uid);
694 putplane(pp->pln_uid, pp);
703 pln_removedupes(struct emp_qelem *bomb_list, struct emp_qelem *esc_list)
705 struct emp_qelem *bomb;
706 struct emp_qelem *esc;
710 if (QEMPTY(bomb_list) || QEMPTY(esc_list))
712 bomb = bomb_list->q_forw;
713 while (bomb != bomb_list) {
714 if (QEMPTY(esc_list)) {
718 esc = esc_list->q_forw;
719 bombp = (struct plist *)bomb;
720 while (esc != esc_list) {
721 escp = (struct plist *)esc;
722 if (escp->plane.pln_uid == bombp->plane.pln_uid) {
734 put_plane_on_ship(struct plnstr *plane, struct shpstr *ship)
736 struct plchrstr *pcp;
739 pcp = &plchr[(int)plane->pln_type];
740 mcp = &mchr[(int)ship->shp_type];
742 if (((int)plane->pln_ship) == ((int)ship->shp_uid))
743 return 1; /* Already on ship */
745 /* Try to put on ship as a chopper plane */
746 if ((pcp->pl_flags & P_K) &&
747 (mcp->m_flags & M_CHOPPER) &&
748 (ship->shp_nchoppers < mcp->m_nchoppers)) {
750 ship->shp_nchoppers++;
751 plane->pln_x = ship->shp_x;
752 plane->pln_y = ship->shp_y;
753 plane->pln_ship = ship->shp_uid;
754 putship(ship->shp_uid, ship);
755 putplane(plane->pln_uid, plane);
759 /* Try to put on ship as an xlight plane */
760 if ((pcp->pl_flags & P_E) &&
761 (mcp->m_flags & M_XLIGHT) &&
762 (ship->shp_nxlight < mcp->m_nxlight)) {
765 plane->pln_x = ship->shp_x;
766 plane->pln_y = ship->shp_y;
767 plane->pln_ship = ship->shp_uid;
768 putship(ship->shp_uid, ship);
769 putplane(plane->pln_uid, plane);
773 /* Try to put on ship as a normal plane */
774 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
775 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
776 (mcp->m_flags & M_MSL))) &&
777 (ship->shp_nplane < mcp->m_nplanes)) {
780 plane->pln_x = ship->shp_x;
781 plane->pln_y = ship->shp_y;
782 plane->pln_ship = ship->shp_uid;
783 putship(ship->shp_uid, ship);
784 putplane(plane->pln_uid, plane);
793 take_plane_off_ship(struct plnstr *plane, struct shpstr *ship)
795 struct plchrstr *pcp;
798 pcp = &plchr[(int)plane->pln_type];
799 mcp = &mchr[(int)ship->shp_type];
801 /* Try to take off ship as a chopper plane */
802 if ((pcp->pl_flags & P_K) &&
803 (mcp->m_flags & M_CHOPPER) && (ship->shp_nchoppers)) {
805 ship->shp_nchoppers--;
806 plane->pln_ship = -1;
807 putship(ship->shp_uid, ship);
808 putplane(plane->pln_uid, plane);
812 /* Try to take off ship as an xlight plane */
813 if ((pcp->pl_flags & P_E) &&
814 (mcp->m_flags & M_XLIGHT) && (ship->shp_nxlight)) {
817 plane->pln_ship = -1;
818 putship(ship->shp_uid, ship);
819 putplane(plane->pln_uid, plane);
823 /* Try to take off ship as a normal plane */
824 if ((((pcp->pl_flags & P_L) && (mcp->m_flags & M_FLY)) ||
825 ((pcp->pl_flags & P_M) && (pcp->pl_flags & P_L) &&
826 (mcp->m_flags & M_MSL))) && (ship->shp_nplane)) {
829 plane->pln_ship = -1;
830 putship(ship->shp_uid, ship);
831 putplane(plane->pln_uid, plane);
840 take_plane_off_land(struct plnstr *plane, struct lndstr *land)
842 struct plchrstr *pcp;
845 pcp = &plchr[(int)plane->pln_type];
846 lcp = &lchr[(int)land->lnd_type];
848 /* Try to take off ship as an xlight plane */
849 if ((pcp->pl_flags & P_E) &&
850 (lcp->l_flags & L_XLIGHT) && (land->lnd_nxlight)) {
853 plane->pln_land = -1;
854 putland(land->lnd_uid, land);
855 putplane(plane->pln_uid, plane);
864 can_be_on_ship(int p, int s)
868 struct plchrstr *pcp;
874 pcp = &plchr[(int)plane.pln_type];
875 mcp = &mchr[(int)ship.shp_type];
877 if (pcp->pl_flags & P_L)
878 if (mcp->m_flags & M_FLY)
881 if (pcp->pl_flags & P_K)
882 if (mcp->m_flags & M_CHOPPER)
885 if (pcp->pl_flags & P_M)
886 if (mcp->m_flags & M_MSL)
889 if (pcp->pl_flags & P_E)
890 if (mcp->m_flags & M_XLIGHT)
897 plane_sweep(struct emp_qelem *plane_list, coord x, coord y)
900 struct plchrstr *pcp;
901 struct emp_qelem *qp;
902 struct emp_qelem *next;
908 getsect(x, y, §);
909 mines_there = getvar(V_MINE, (s_char *)§, EF_SECTOR);
911 if (mines_there == 0)
914 if ((sect.sct_type != SCT_WATER) && (sect.sct_type != SCT_HARBR))
917 for (qp = plane_list->q_forw; ((qp != plane_list) && (mines_there));
920 ip = (struct plist *)qp;
923 if (!(pcp->pl_flags & P_SWEEP)) /* if it isn't an sweep plane */
926 if (chance(((double)(100 - pp->pln_acc)) / 100.0)) {
928 xyas(sect.sct_x, sect.sct_y, pp->pln_own));
934 if (found && map_set(player->cnum, sect.sct_x, sect.sct_y, 'X', 0))
935 writemap(player->cnum);
936 putvar(V_MINE, mines_there, (s_char *)§, EF_SECTOR);
941 count_planes(struct shpstr *sp)
945 struct plchrstr *pcp;
951 if (sp->shp_effic < SHIP_MINEFF)
954 mcp = &mchr[(int)sp->shp_type];
955 snxtitem_xy(&ni, EF_PLANE, sp->shp_x, sp->shp_y);
956 while (nxtitem(&ni, (s_char *)&plane)) {
957 if (plane.pln_own == 0)
959 if (plane.pln_ship == sp->shp_uid) {
960 pcp = &plchr[(int)plane.pln_type];
961 if ((pcp->pl_flags & P_K) && (nchoppers < mcp->m_nchoppers))
963 else if ((pcp->pl_flags & P_E) && (nxlight < mcp->m_nxlight))
965 else if ((pcp->pl_flags & P_L) || (pcp->pl_flags & P_M))
970 if (nplane != sp->shp_nplane ||
971 nxlight != sp->shp_nxlight || nchoppers != sp->shp_nchoppers) {
972 sp->shp_nplane = nplane;
973 sp->shp_nxlight = nxlight;
974 sp->shp_nchoppers = nchoppers;
975 putship(sp->shp_uid, sp);
980 count_land_planes(struct lndstr *lp)
986 if (lp->lnd_effic < LAND_MINEFF)
989 snxtitem_all(&ni, EF_PLANE);
990 while (nxtitem(&ni, (s_char *)&plane)) {
991 if (plane.pln_own == 0)
993 if (plane.pln_land == lp->lnd_uid)
997 if (lp->lnd_nxlight != nplane) {
998 lp->lnd_nxlight = nplane;
999 putland(lp->lnd_uid, lp);
1004 count_sect_planes(struct sctstr *sp)
1007 struct nstr_item ni;
1008 struct plnstr plane;
1010 snxtitem_all(&ni, EF_PLANE);
1011 while (nxtitem(&ni, (s_char *)&plane)) {
1014 if (plane.pln_flags & PLN_LAUNCHED)
1016 if (plane.pln_x == sp->sct_x && plane.pln_y == sp->sct_y)
1024 put_plane_on_land(struct plnstr *plane, struct lndstr *land)
1026 struct plchrstr *pcp;
1027 struct lchrstr *lcp;
1029 pcp = &plchr[(int)plane->pln_type];
1030 lcp = &lchr[(int)land->lnd_type];
1032 if (((int)plane->pln_land) == ((int)land->lnd_uid))
1033 return 1; /* Already on unit */
1035 /* Try to put on unit as an xlight plane */
1036 if ((pcp->pl_flags & P_E) &&
1037 (lcp->l_flags & L_XLIGHT) &&
1038 (land->lnd_nxlight < lcp->l_nxlight)) {
1040 land->lnd_nxlight++;
1041 plane->pln_x = land->lnd_x;
1042 plane->pln_y = land->lnd_y;
1043 plane->pln_land = land->lnd_uid;
1044 putland(land->lnd_uid, land);
1045 putplane(plane->pln_uid, plane);
1049 /* We have failed */
1054 pln_hitchance(struct plnstr *pp, int hardtarget, int type)
1056 struct plchrstr *pcp = plchr + pp->pln_type;
1057 float tfact = (float)(pp->pln_tech - pcp->pl_tech) /
1058 (pp->pln_tech - pcp->pl_tech / 2);
1059 int acc = pp->pln_acc;
1062 if (type == EF_SHIP) {
1063 if (pcp->pl_flags & P_A)
1065 if (!(pcp->pl_flags & P_T))
1068 hitchance = (int)(pp->pln_effic * (1.0 - 0.1 * tfact) *
1069 (1.0 - (float)acc / 100.0)) - hardtarget;
1071 /* smooth out the bottom of the graph with asymtote at 5 -KHS */
1073 hitchance = 5 + ldround(300.0 / (40.0 - hitchance), 1);
1074 if (hitchance > 100)
1079 /* return 0 if there was a nuclear detonation */
1082 pln_damage(struct plnstr *pp, coord x, coord y, s_char type, int *nukedamp,
1085 struct plchrstr *pcp = plchr + pp->pln_type;
1093 if (pp->pln_nuketype != (s_char)-1) {
1094 mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
1095 pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
1096 *nukedamp = detonate(pp, x, y);
1101 if (!pp->pln_load) /* e.g. ab, blowing up on launch pad */
1104 i = roll(pp->pln_load) + 1;
1105 if (i > pp->pln_load)
1108 if (pcp->pl_flags & P_M) {
1109 if (pcp->pl_flags & P_MAR)
1111 } else if (pcp->pl_flags & P_T)
1114 aim = 100 - pp->pln_acc;
1128 hitroll = roll(100);
1129 if (hitroll >= 90) {
1132 mpr(pp->pln_own, "BLAM");
1133 } else if (hitroll < aim) {
1136 mpr(pp->pln_own, "Blam");
1140 mpr(pp->pln_own, "blam");
1143 mpr(pp->pln_own, "-");
1146 mpr(pp->pln_own, "\n");
1153 pln_identchance(struct plnstr *pp, int hardtarget, int type)
1156 (100.0 - pln_hitchance(pp, hardtarget, type)) / 100.0;
1157 return (int)(100 - 100 * misschance * misschance);
1161 pln_mobcost(int dist, struct plnstr *pp, int flags)
1165 if ((flags & P_F) || (flags & P_ESC))
1166 cost = 10 * 100 / pp->pln_effic;
1168 cost = 20 * 100 / pp->pln_effic;
1170 cost = ldround((double)cost * dist / pp->pln_range_max, 1);
1172 return min(32 + pp->pln_mobil, cost + 5);