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 * shpsub.c: Ship subroutine stuff
30 * Known contributors to this file:
32 * Steve McClure, 1996-2000
54 #include "prototypes.h"
56 static int shp_check_nav(struct sctstr *);
57 static int shp_check_one_mines(struct mlist *);
58 static int shp_hit_mine(struct shpstr *, struct mchrstr *);
59 static void shp_mess(s_char *, struct mlist *);
62 shp_sel(struct nstr_item *ni, struct emp_qelem *list)
74 while (nxtitem(ni, (s_char *)&ship)) {
77 mcp = &mchr[(int)ship.shp_type];
78 /* if (wantflags && (mcp->m_flags & wantflags) != wantflags)
80 if (nowantflags && mcp->m_flags & nowantflags)
84 if (ontradingblock(EF_SHIP, (int *)&ship)) {
85 pr("ship #%d inelligible - it's for sale.\n",
90 /* This abuse is better fixed by building a ship with the normal negative
91 mobility that everything else is built with */
94 if (ship.shp_effic < 21 &&
95 ship.shp_mobil < etu_per_update) {
96 pr("%s needs at least %d mob to navigate.\n",
97 prship(&ship), etu_per_update);
102 ship.shp_mission = 0;
104 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
105 putship(ship.shp_uid, &ship);
106 mlp = (struct mlist *)malloc(sizeof(struct mlist));
109 mlp->mobil = (double)ship.shp_mobil;
110 emp_insque(&mlp->queue, list);
114 /* This function assumes that the list was created by shp_sel */
116 shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
117 int *togetherp, natid actor)
119 struct emp_qelem *qp;
120 struct emp_qelem *next;
131 for (qp = list->q_back; qp != list; qp = next) {
133 mlp = (struct mlist *)qp;
134 getship(mlp->ship.shp_uid, &ship);
135 if (ship.shp_own != actor) {
136 mpr(actor, "%s was sunk at %s\n",
137 prship(&ship), xyas(ship.shp_x, ship.shp_y, actor));
138 emp_remque((struct emp_qelem *)mlp);
143 if (*ship.shp_path && !update_pending) {
144 shp_mess("has a sail path", mlp);
145 mpr(actor, "Use `sail <#> -' to reset\n");
149 /* check crew - uws don't count */
150 if (ship.shp_item[I_MILIT] == 0 && ship.shp_item[I_CIVIL] == 0) {
151 shp_mess("is crewless", mlp);
154 if (!getsect(ship.shp_x, ship.shp_y, §)) {
155 shp_mess("was sucked into the sky by a strange looking spaceship", mlp); /* heh -KHS */
158 switch (shp_check_nav(§)) {
159 case CN_CONSTRUCTION:
160 shp_mess("is caught in a construction zone", mlp);
163 shp_mess("is landlocked", mlp);
169 shp_mess("was just swallowed by a big green worm", mlp);
177 if (ship.shp_x != allx || ship.shp_y != ally)
179 if (ship.shp_mobil + 1 < (int)mlp->mobil) {
180 mlp->mobil = (double)ship.shp_mobil;
182 if (mlp->mobil < *minmobp)
183 *minmobp = mlp->mobil;
184 if (mlp->mobil > *maxmobp)
185 *maxmobp = mlp->mobil;
191 shp_put(struct emp_qelem *list, natid actor)
193 struct emp_qelem *qp;
194 struct emp_qelem *newqp;
199 mlp = (struct mlist *)qp;
200 mpr(actor, "%s stopped at %s\n", prship(&mlp->ship),
201 xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
202 mlp->ship.shp_mobil = (int)mlp->mobil;
203 putship(mlp->ship.shp_uid, &mlp->ship);
212 shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor)
214 struct emp_qelem *qp;
215 struct emp_qelem *next;
218 int mines, m, max, shells;
223 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
225 mlp = (struct mlist *)qp;
226 if (!(mlp->mcp->m_flags & M_SWEEP)) {
228 mpr(actor, "%s doesn't have minesweeping capability!\n",
232 if (mlp->mobil <= 0.0) {
234 mpr(actor, "%s is out of mobility!\n", prship(&mlp->ship));
237 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
238 if (sect.sct_type != SCT_WATER) {
240 mpr(actor, "%s is not at sea. No mines there!\n",
244 mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
245 mobcost = 480.0 / (mobcost +
246 techfact(mlp->ship.shp_tech, mobcost));
247 mlp->mobil -= mobcost;
248 mlp->ship.shp_mobil = (int)mlp->mobil;
249 putship(mlp->ship.shp_uid, &mlp->ship);
250 if (!(mines = sect.sct_mines))
252 max = mlp->mcp->m_item[I_SHELL];
253 shells = mlp->ship.shp_item[I_SHELL];
254 for (m = 0; mines > 0 && m < 5; m++) {
256 mpr(actor, "Sweep...\n");
258 shells = min(max, shells + 1);
259 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
262 sect.sct_mines = mines;
263 mlp->ship.shp_item[I_SHELL] = shells;
264 if (shp_check_one_mines(mlp)) {
269 putship(mlp->ship.shp_uid, &mlp->ship);
278 shp_check_one_mines(struct mlist *mlp)
284 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
285 if (sect.sct_type != SCT_WATER)
289 if (chance(DMINE_HITCHANCE(sect.sct_mines))) {
290 actor = mlp->ship.shp_own;
291 shp_hit_mine(&mlp->ship, mlp->mcp);
293 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
297 putship(mlp->ship.shp_uid, (s_char *)&mlp->ship);
298 if (!mlp->ship.shp_own)
305 shp_check_mines(struct emp_qelem *ship_list)
307 struct emp_qelem *qp;
308 struct emp_qelem *next;
312 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
314 mlp = (struct mlist *)qp;
315 if (shp_check_one_mines(mlp)) {
325 shp_list(struct emp_qelem *ship_list)
327 struct emp_qelem *qp;
328 struct emp_qelem *next;
332 pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
334 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
336 mlp = (struct mlist *)qp;
338 pr("%4d ", shp->shp_uid);
339 pr("%-16.16s ", mlp->mcp->m_name);
340 prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->ship.shp_own);
341 pr("%1c", shp->shp_fleet);
342 pr("%4d%%", shp->shp_effic);
343 pr("%4d", shp->shp_item[I_MILIT]);
344 pr("%4d", shp->shp_item[I_SHELL]);
345 pr("%4d", shp->shp_item[I_GUN]);
347 pr("%3d", shp->shp_nplane);
348 pr("%3d", shp->shp_nchoppers);
349 pr("%3d", shp->shp_nxlight);
351 pr("%3d", shp->shp_nland);
352 pr("%4d", shp->shp_mobil);
353 pr("%4d\n", shp->shp_tech);
358 shp_mess(s_char *str, struct mlist *mlp)
360 mpr(mlp->ship.shp_own, "%s %s & stays in %s\n",
362 str, xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
363 mlp->ship.shp_mobil = (int)mlp->mobil;
364 putship(mlp->ship.shp_uid, &mlp->ship);
365 emp_remque((struct emp_qelem *)mlp);
370 shp_check_nav(struct sctstr *sect)
372 switch (dchr[sect->sct_type].d_flg & 03) {
377 if (sect->sct_effic < 2)
378 return CN_CONSTRUCTION;
381 if (sect->sct_effic < 60)
382 return CN_CONSTRUCTION;
385 return CN_LANDLOCKED;
391 shp_count(struct emp_qelem *list, int wantflags, int nowantflags, int x,
394 struct emp_qelem *qp;
395 struct emp_qelem *next;
399 for (qp = list->q_back; qp != list; qp = next) {
401 mlp = (struct mlist *)qp;
402 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
404 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
406 if (nowantflags && mlp->mcp->m_flags & nowantflags)
414 shp_damage_one(struct mlist *mlp, int dam)
416 shipdamage(&mlp->ship, dam);
417 putship(mlp->ship.shp_uid, &mlp->ship);
418 if (!mlp->ship.shp_own) {
419 emp_remque((struct emp_qelem *)mlp);
425 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
426 int nowantflags, int x, int y)
428 struct emp_qelem *qp;
429 struct emp_qelem *next;
435 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
437 dam = ldround(((double)totdam / (double)count), 1);
438 for (qp = list->q_back; qp != list; qp = next) {
440 mlp = (struct mlist *)qp;
441 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
443 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
445 if (nowantflags && mlp->mcp->m_flags & nowantflags)
447 shp_damage_one(mlp, dam);
453 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
456 struct emp_qelem *qp;
457 struct emp_qelem *next;
460 for (qp = list->q_back; qp != list; qp = next) {
462 mlp = (struct mlist *)qp;
463 /* If the ship isn't in the requested sector, then continue */
464 if (newx != mlp->ship.shp_x || newy != mlp->ship.shp_y)
466 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
468 if (nowantflags && mlp->mcp->m_flags & nowantflags)
475 static struct mlist *
476 most_valuable_ship(struct emp_qelem *list)
478 struct emp_qelem *qp;
479 struct emp_qelem *next;
481 struct mlist *mvs = 0;
483 for (qp = list->q_back; qp != list; qp = next) {
485 mlp = (struct mlist *)qp;
486 if (mlp->mcp->m_flags & M_SUB)
488 if (!mlp->mcp->m_nxlight &&
489 !mlp->mcp->m_nchoppers &&
490 mlp->mcp->m_cost < 1000 &&
491 !mlp->mcp->m_nplanes && !mlp->mcp->m_nland)
497 if (mlp->mcp->m_cost * mlp->ship.shp_effic >
498 mvs->mcp->m_cost * mvs->ship.shp_effic)
505 shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
507 struct emp_qelem *qp;
508 struct emp_qelem *next;
511 int easiest = 9876; /* things start great for victim */
514 for (qp = list->q_back; qp != list; qp = next) {
516 mlp = (struct mlist *)qp;
517 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
519 if (nowantflags && mlp->mcp->m_flags & nowantflags)
521 hard = shp_hardtarget(&mlp->ship);
523 easiest = hard; /* things get worse for victim */
526 return easiest - count;
530 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
536 struct emp_qelem msl_list, *qp, *newqp;
540 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
543 while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
544 sprintf(what, "%s", prship(&mvs->ship));
545 dam = msl_launch_mindam(&msl_list, newx, newy,
546 shp_hardtarget(&mvs->ship),
547 EF_SHIP, 1, what, victim, MI_INTERDICT);
550 "missile interdiction mission does %d damage to %s!\n",
552 shp_damage_one(mvs, dam);
555 } else if (++twotries >= 2) {
559 qp = msl_list.q_forw;
560 while (qp != msl_list.q_forw) {
570 /* Note that this function has a side effect - it uses coastwatch
571 * ranges to see if it should fire upon a ship. So, this function
572 * is expected to return positive if a ship is in range, and 0 if a
573 * ship is not in range. */
575 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
577 struct emp_qelem *qp;
578 struct emp_qelem *next;
583 natp = getnatp(sectp->sct_own);
585 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
586 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
594 /* We got here, so we could theoretically see the ship. Now,
595 * do we want to see it in our telebox? If not, return positive
596 * since we could see the ship and want forts to fire. */
597 if (!(natp->nat_flags & NF_COASTWATCH))
600 for (qp = list->q_back; qp != list; qp = next) {
602 mlp = (struct mlist *)qp;
603 if (mlp->mcp->m_flags & M_SUB)
605 wu(0, sectp->sct_own,
606 "%s %s sighted at %s\n",
607 cname(mlp->ship.shp_own),
609 xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own));
611 setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_LOOK);
619 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
625 double range, range2, guneff;
629 s_char notified[MAXNOC];
632 /* Inform neutral and worse */
633 for (i = 0; i < MAXNOC; ++i) {
634 if (getrel(getnatp(i), victim) <= NEUTRAL)
640 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
641 while (nxtsct(&ns, &fsect)) {
644 if (fsect.sct_own == victim)
646 if (notified[fsect.sct_own])
648 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
649 if (notify_coastguard(list, trange, &fsect))
650 notified[fsect.sct_own] = 1;
652 if (opt_NO_FORT_FIRE)
653 return 0; /* Only coastwatch notify in nofortfire */
654 /* Only fire at Hostile ships */
655 for (i = 0; i < MAXNOC; ++i) {
656 if (getrel(getnatp(i), victim) >= NEUTRAL)
659 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
660 while (nxtsct(&ns, &fsect)) {
661 if (!notified[fsect.sct_own])
663 if (fsect.sct_type != SCT_FORTR)
665 gun = fsect.sct_item[I_GUN];
668 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
669 if (fsect.sct_effic > 59)
671 range2 = roundrange(range);
672 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
675 if (fsect.sct_item[I_MILIT] < 5)
677 shell = fsect.sct_item[I_SHELL];
679 shell += supply_commod(fsect.sct_own,
680 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
684 fsect.sct_item[I_SHELL] = shell;
688 guneff = landgun((int)fsect.sct_effic, gun);
691 mpr(victim, "Incoming fire does %d damage!\n", dam);
693 mpr(victim, "%s fires at you for %d!\n",
694 xyas(fsect.sct_x,fsect.sct_y,victim),
698 "%s fires at %s ships in %s for %d!\n",
699 xyas(fsect.sct_x, fsect.sct_y,
701 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
702 nreport(fsect.sct_own, N_SHP_SHELL, victim, 1);
705 return shp_damage(list, totdam, 0, M_SUB, newx, newy);
710 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
714 if (shp_contains(list, newx, newy, 0, M_SUB)) {
715 stopping |= shp_fort_interdiction(list, newx, newy, victim);
717 if (shp_contains(list, newx, newy, 0, M_SUB)) {
720 unit_interdict(newx, newy, victim, "ships",
721 shp_easiest_target(list, 0, M_SUB),
723 0, M_SUB, newx, newy);
724 if (most_valuable_ship(list)) {
726 shp_missile_interdiction(list, newx, newy, victim);
730 if (shp_contains(list, newx, newy, M_SUB, 0)) {
733 unit_interdict(newx, newy, victim, "subs",
734 shp_easiest_target(list, M_SUB, 0),
736 M_SUB, 0, newx, newy);
741 /* high value of hardtarget is harder to hit */
743 shp_hardtarget(struct shpstr *sp)
747 struct mchrstr *mcp = mchr + sp->shp_type;
750 getsect(sp->shp_x, sp->shp_y, §);
751 onsea = (sect.sct_type == SCT_WATER);
752 if (mcp->m_flags & M_SUB)
754 return (int)(((double)sp->shp_effic / 100.0) *
755 (20 + (double)sp->shp_speed * onsea / 2.0 - vis));
759 shp_hit_mine(struct shpstr *sp, struct mchrstr *mcp)
763 mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n",
764 xyas(sp->shp_x, sp->shp_y, sp->shp_own));
766 nreport(sp->shp_own, N_HIT_MINE, 0, 1);
768 m = 22.0 + (double)(random() % 21);
769 if (mcp->m_flags & M_SWEEP)
772 shipdamage(sp, ldround(m, 1));
778 shp_view(struct emp_qelem *list)
781 struct emp_qelem *qp;
782 struct emp_qelem *next;
785 for (qp = list->q_back; qp != list; qp = next) {
787 mlp = (struct mlist *)qp;
788 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
789 if (mlp->mcp->m_flags & M_FOOD)
790 mpr(mlp->ship.shp_own, "[fert:%d] ", sect.sct_fertil);
791 if (mlp->mcp->m_flags & M_OIL)
792 mpr(mlp->ship.shp_own, "[oil:%d] ", sect.sct_oil);
793 mpr(mlp->ship.shp_own, "%s @ %s %d%% %s\n",
795 xyas(mlp->ship.shp_x, mlp->ship.shp_y, player->cnum),
796 sect.sct_effic, dchr[sect.sct_type].d_name);
801 shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
805 struct emp_qelem *qp;
806 struct emp_qelem *next;
808 struct emp_qelem done;
815 double tech; /* for mapping */
816 double tf; /* for mapping */
819 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
820 shp_put(list, actor);
825 for (qp = list->q_back; qp != list; qp = next) {
827 mlp = (struct mlist *)qp;
828 newx = xnorm(mlp->ship.shp_x + dx);
829 newy = ynorm(mlp->ship.shp_y + dy);
830 getsect(newx, newy, §);
831 if (shp_check_nav(§) != CN_NAVIGABLE ||
832 (sect.sct_own && actor != sect.sct_own &&
833 getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
835 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
838 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
843 if (opt_BIG_CITY && sect.sct_type == SCT_CAPIT) {
844 if (mlp->mcp->m_lcm + 2 * mlp->mcp->m_hcm >= 60) {
846 "is too large to fit into the canal system at %s",
847 xyas(newx, newy, actor));
852 if (mlp->mobil <= 0.0) {
853 shp_mess("is out of mobility", mlp);
856 mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
858 (mobcost + techfact(mlp->ship.shp_tech, mobcost));
859 mlp->ship.shp_x = newx;
860 mlp->ship.shp_y = newy;
861 if (mlp->mobil - mobcost < -127) {
864 mlp->mobil -= mobcost;
866 mlp->ship.shp_mobil = (int)mlp->mobil;
867 putship(mlp->ship.shp_uid, &mlp->ship);
869 /* Now update the map for this ship */
870 tech = techfact(mlp->ship.shp_tech, (double)mlp->mcp->m_vrnge);
871 if (mlp->mcp->m_flags & M_SONAR)
872 tf = techfact(mlp->ship.shp_tech, 1.0);
875 radmapupd(mlp->ship.shp_own, mlp->ship.shp_x, mlp->ship.shp_y,
876 (int)mlp->ship.shp_effic, (int)tech, tf);
880 stopping |= shp_sweep(list, 0, actor);
883 stopping |= shp_check_mines(list);
887 /* interdict ships sector by sector */
889 while (!QEMPTY(list)) {
890 mlp = (struct mlist *)list->q_back;
891 newx = mlp->ship.shp_x;
892 newy = mlp->ship.shp_y;
893 stopping |= shp_interdict(list, newx, newy, actor);
894 /* move survivors in this sector to done */
895 for (qp = list->q_back; qp != list; qp = next) {
897 mlp = (struct mlist *)qp;
898 if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy) {
900 emp_insque(qp, &done);
904 /* assign surviving ships back to list */
905 emp_insque(list, &done);
913 * Check for incoming missiles with a P_MAR flag.
914 * Return True=1 if the missile was shotdown.
917 * Chad Zabel, July 95
921 shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
927 double gun, eff, teff;
929 snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
931 while (nxtitem(&ni, &ship)) {
935 if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE))
938 if (getrel(getnatp(ship.shp_own), bombown) >= NEUTRAL)
941 if (ship.shp_effic < 60)
944 shell = ship.shp_item[I_SHELL];
945 if (ship.shp_item[I_MILIT] < 1) /* do we have mil? */
947 if (shell < 2) { /* do we need shells */
948 shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
953 if (ship.shp_item[I_GUN] < 1) /* we need at least 1 gun */
956 /* now calculate the odds */
957 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
958 eff = (double)ship.shp_effic / 100.0;
960 (((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0));
961 /* raise 4.5 for better interception -KHS */
962 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
968 mpr(bombown, "%s anti-missile system activated...",
969 cname(ship.shp_own));
970 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
972 mpr(ship.shp_own, "%d%% hitchance...", hitchance);
974 ship.shp_item[I_SHELL] = shell - 2;
975 putship(ship.shp_uid, &ship);
977 if (roll(100) <= hitchance) {
978 mpr(bombown, "KABOOOM!! Missile destroyed\n\n");
980 "KABOOOM!! Incoming missile destroyed!\n\n");
983 mpr(bombown, "SWOOSH!! anti-missile system failed!!\n");
985 "SWOOSH!! Missile evades anti-missile systems\n\n");
988 return 0; /* all attempts failed */
992 shp_path(int together, struct shpstr *shp, s_char *buf)
996 struct sctstr d_sect;
999 if (!sarg_xy(buf, &destx, &desty))
1003 "Cannot go to a destination sector if not all starting in the same sector\n");
1006 if (!getsect(destx, desty, &d_sect)) {
1007 mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty);
1011 cp = (s_char *)BestShipPath(buf, shp->shp_x, shp->shp_y,
1012 d_sect.sct_x, d_sect.sct_y, player->cnum);
1013 if (!cp || shp->shp_mobil <= 0) {
1014 mpr(shp->shp_own, "Can't get to '%s' right now.\n",
1015 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1021 /* Fire missiles at a ship which has fired shells */
1023 shp_missdef(struct shpstr *sp, natid victim)
1025 struct emp_qelem list;
1032 mlp = (struct mlist *)malloc(sizeof(struct mlist));
1033 mlp->mcp = &mchr[(int)sp->shp_type];
1035 mlp->mobil = (double)sp->shp_mobil;
1036 emp_insque(&mlp->queue, &list);
1037 sprintf(buf, "%s", prship(&mlp->ship));
1039 eff = sp->shp_effic;
1040 if (most_valuable_ship(&list)) {
1041 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
1042 getship(sp->shp_uid, sp);
1046 "missiles launched in defense did 100%% damage to %s\n",
1048 wu(0, victim, "%s sunk!\n", buf);
1049 } else if (eff > 0 && sp->shp_effic < eff) {
1051 "missiles launched in defense did %d%% damage to %s\n",
1052 100 * (eff - sp->shp_effic) / eff, buf);
1060 * Set SP's tech to TLEV along with everything else that depends on it.
1063 shp_set_tech(struct shpstr *sp, int tlev)
1065 struct mchrstr *mcp = mchr + sp->shp_type;
1066 int tech_diff = tlev - mcp->m_tech;
1068 if (CANT_HAPPEN(tech_diff < 0)) {
1073 sp->shp_tech = tlev;
1074 sp->shp_armor = (short)SHP_DEF(mcp->m_armor, tech_diff);
1075 sp->shp_speed = (short)SHP_SPD(mcp->m_speed, tech_diff);
1076 sp->shp_visib = (short)SHP_VIS(mcp->m_visib, tech_diff);
1077 sp->shp_frnge = (short)SHP_RNG(mcp->m_frnge, tech_diff);
1078 sp->shp_glim = (short)SHP_FIR(mcp->m_glim, tech_diff);