2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-1999, 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
55 #include "prototypes.h"
57 static int shp_check_nav(struct sctstr *);
58 static int shp_check_one_mines(struct mlist *);
59 static int shp_hit_mine(struct shpstr *, struct mchrstr *);
60 static void shp_mess(s_char *, struct mlist *);
63 shp_sel(struct nstr_item *ni, struct emp_qelem *list)
75 while (nxtitem(ni, (s_char *)&ship)) {
78 mcp = &mchr[(int)ship.shp_type];
79 /* if (wantflags && (mcp->m_flags & wantflags) != wantflags)
81 if (nowantflags && mcp->m_flags & nowantflags)
85 if (ontradingblock(EF_SHIP, (int *)&ship)) {
86 pr("ship #%d inelligible - it's for sale.\n",
91 /* This abuse is better fixed by building a ship with the normal negative
92 mobility that everything else is built with */
95 if (ship.shp_effic < 21 &&
96 ship.shp_mobil < etu_per_update) {
97 pr("%s needs at least %d mob to navigate.\n",
98 prship(&ship), etu_per_update);
103 ship.shp_mission = 0;
105 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
106 putship(ship.shp_uid, &ship);
107 mlp = (struct mlist *)malloc(sizeof(struct mlist));
110 mlp->mobil = (double)ship.shp_mobil;
111 emp_insque(&mlp->queue, list);
115 /* This function assumes that the list was created by shp_sel */
117 shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
118 int *togetherp, natid actor)
120 struct emp_qelem *qp;
121 struct emp_qelem *next;
132 for (qp = list->q_back; qp != list; qp = next) {
134 mlp = (struct mlist *)qp;
135 getship(mlp->ship.shp_uid, &ship);
136 if (ship.shp_own != actor) {
137 mpr(actor, "%s was sunk at %s\n",
138 prship(&ship), xyas(ship.shp_x, ship.shp_y, actor));
139 emp_remque((struct emp_qelem *)mlp);
144 if (*ship.shp_path && !update_pending) {
145 shp_mess("has a sail path", mlp);
146 mpr(actor, "Use `sail <#> -' to reset\n");
150 /* check crew - uws don't count */
151 if (ship.shp_item[I_MILIT] == 0 && ship.shp_item[I_CIVIL] == 0) {
152 shp_mess("is crewless", mlp);
155 if (!getsect(ship.shp_x, ship.shp_y, §)) {
156 shp_mess("was sucked into the sky by a strange looking spaceship", mlp); /* heh -KHS */
159 switch (shp_check_nav(§)) {
160 case CN_CONSTRUCTION:
161 shp_mess("is caught in a construction zone", mlp);
164 shp_mess("is landlocked", mlp);
170 shp_mess("was just swallowed by a big green worm", mlp);
178 if (ship.shp_x != allx || ship.shp_y != ally)
180 if (ship.shp_mobil + 1 < (int)mlp->mobil) {
181 mlp->mobil = (double)ship.shp_mobil;
183 if (mlp->mobil < *minmobp)
184 *minmobp = mlp->mobil;
185 if (mlp->mobil > *maxmobp)
186 *maxmobp = mlp->mobil;
192 shp_put(struct emp_qelem *list, natid actor)
194 register struct emp_qelem *qp;
195 register struct emp_qelem *newqp;
200 mlp = (struct mlist *)qp;
201 mpr(actor, "%s stopped at %s\n", prship(&mlp->ship),
202 xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
203 mlp->ship.shp_mobil = (int)mlp->mobil;
204 putship(mlp->ship.shp_uid, &mlp->ship);
213 shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor)
215 struct emp_qelem *qp;
216 struct emp_qelem *next;
219 int mines, m, max, shells;
224 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
226 mlp = (struct mlist *)qp;
227 if (!(mlp->mcp->m_flags & M_SWEEP)) {
229 mpr(actor, "%s doesn't have minesweeping capability!\n",
233 if (mlp->mobil <= 0.0) {
235 mpr(actor, "%s is out of mobility!\n", prship(&mlp->ship));
238 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
239 if (sect.sct_type != SCT_WATER) {
241 mpr(actor, "%s is not at sea. No mines there!\n",
245 mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
246 mobcost = 480.0 / (mobcost +
247 techfact(mlp->ship.shp_tech, mobcost));
248 mlp->mobil -= mobcost;
249 mlp->ship.shp_mobil = (int)mlp->mobil;
250 putship(mlp->ship.shp_uid, &mlp->ship);
251 if (!(mines = sect.sct_mines))
253 max = vl_find(V_SHELL, mlp->mcp->m_vtype,
254 mlp->mcp->m_vamt, (int)mlp->mcp->m_nv);
255 shells = mlp->ship.shp_item[I_SHELL];
256 for (m = 0; mines > 0 && m < 5; m++) {
258 mpr(actor, "Sweep...\n");
260 shells = min(max, shells + 1);
261 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
264 sect.sct_mines = mines;
265 mlp->ship.shp_item[I_SHELL] = shells;
266 if (shp_check_one_mines(mlp)) {
271 putship(mlp->ship.shp_uid, &mlp->ship);
280 shp_check_one_mines(struct mlist *mlp)
286 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
287 if (sect.sct_type != SCT_WATER)
291 if (chance(DMINE_HITCHANCE(sect.sct_mines))) {
292 actor = mlp->ship.shp_own;
293 shp_hit_mine(&mlp->ship, mlp->mcp);
295 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
299 putship(mlp->ship.shp_uid, (s_char *)&mlp->ship);
300 if (!mlp->ship.shp_own)
307 shp_check_mines(struct emp_qelem *ship_list)
309 struct emp_qelem *qp;
310 struct emp_qelem *next;
314 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
316 mlp = (struct mlist *)qp;
317 if (shp_check_one_mines(mlp)) {
327 shp_list(struct emp_qelem *ship_list)
329 struct emp_qelem *qp;
330 struct emp_qelem *next;
334 pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
336 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
338 mlp = (struct mlist *)qp;
340 pr("%4d ", shp->shp_uid);
341 pr("%-16.16s ", mlp->mcp->m_name);
342 prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->ship.shp_own);
343 pr("%1c", shp->shp_fleet);
344 pr("%4d%%", shp->shp_effic);
345 pr("%4d", shp->shp_item[I_MILIT]);
346 pr("%4d", shp->shp_item[I_SHELL]);
347 pr("%4d", shp->shp_item[I_GUN]);
349 pr("%3d", shp->shp_nplane);
350 pr("%3d", shp->shp_nchoppers);
351 pr("%3d", shp->shp_nxlight);
353 pr("%3d", shp->shp_nland);
354 pr("%4d", shp->shp_mobil);
355 pr("%4d\n", shp->shp_tech);
360 shp_mess(s_char *str, struct mlist *mlp)
362 mpr(mlp->ship.shp_own, "%s %s & stays in %s\n",
364 str, xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
365 mlp->ship.shp_mobil = (int)mlp->mobil;
366 putship(mlp->ship.shp_uid, &mlp->ship);
367 emp_remque((struct emp_qelem *)mlp);
372 shp_check_nav(struct sctstr *sect)
374 switch (dchr[sect->sct_type].d_flg & 03) {
379 if (sect->sct_effic < 2)
380 return CN_CONSTRUCTION;
383 if (sect->sct_effic < 60)
384 return CN_CONSTRUCTION;
387 return CN_LANDLOCKED;
393 shp_count(struct emp_qelem *list, int wantflags, int nowantflags, int x,
396 struct emp_qelem *qp;
397 struct emp_qelem *next;
401 for (qp = list->q_back; qp != list; qp = next) {
403 mlp = (struct mlist *)qp;
404 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
406 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
408 if (nowantflags && mlp->mcp->m_flags & nowantflags)
416 shp_damage_one(struct mlist *mlp, int dam)
418 shipdamage(&mlp->ship, dam);
419 putship(mlp->ship.shp_uid, &mlp->ship);
420 if (!mlp->ship.shp_own) {
421 emp_remque((struct emp_qelem *)mlp);
427 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
428 int nowantflags, int x, int y)
430 struct emp_qelem *qp;
431 struct emp_qelem *next;
437 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
439 dam = ldround(((double)totdam / (double)count), 1);
440 for (qp = list->q_back; qp != list; qp = next) {
442 mlp = (struct mlist *)qp;
443 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
445 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
447 if (nowantflags && mlp->mcp->m_flags & nowantflags)
449 shp_damage_one(mlp, dam);
455 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
458 struct emp_qelem *qp;
459 struct emp_qelem *next;
462 for (qp = list->q_back; qp != list; qp = next) {
464 mlp = (struct mlist *)qp;
465 /* If the ship isn't in the requested sector, then continue */
466 if (newx != mlp->ship.shp_x || newy != mlp->ship.shp_y)
468 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
470 if (nowantflags && mlp->mcp->m_flags & nowantflags)
477 static struct mlist *
478 most_valuable_ship(struct emp_qelem *list)
480 struct emp_qelem *qp;
481 struct emp_qelem *next;
483 struct mlist *mvs = 0;
485 for (qp = list->q_back; qp != list; qp = next) {
487 mlp = (struct mlist *)qp;
488 if (mlp->mcp->m_flags & M_SUB)
490 if (!mlp->mcp->m_nxlight &&
491 !mlp->mcp->m_nchoppers &&
492 mlp->mcp->m_cost < 1000 &&
493 !mlp->mcp->m_nplanes && !mlp->mcp->m_nland)
499 if (mlp->mcp->m_cost * mlp->ship.shp_effic >
500 mvs->mcp->m_cost * mvs->ship.shp_effic)
507 shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
509 struct emp_qelem *qp;
510 struct emp_qelem *next;
513 int easiest = 9876; /* things start great for victim */
516 for (qp = list->q_back; qp != list; qp = next) {
518 mlp = (struct mlist *)qp;
519 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
521 if (nowantflags && mlp->mcp->m_flags & nowantflags)
523 hard = shp_hardtarget(&mlp->ship);
525 easiest = hard; /* things get worse for victim */
528 return easiest - count;
532 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
538 struct emp_qelem msl_list, *qp, *newqp;
542 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
545 while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
546 sprintf(what, "%s", prship(&mvs->ship));
547 dam = msl_launch_mindam(&msl_list, newx, newy,
548 shp_hardtarget(&mvs->ship),
549 EF_SHIP, 1, what, victim, MI_INTERDICT);
552 "missile interdiction mission does %d damage to %s!\n",
554 shp_damage_one(mvs, dam);
557 } else if (++twotries >= 2) {
561 qp = msl_list.q_forw;
562 while (qp != msl_list.q_forw) {
572 /* Note that this function has a side effect - it uses coastwatch
573 * ranges to see if it should fire upon a ship. So, this function
574 * is expected to return positive if a ship is in range, and 0 if a
575 * ship is not in range. */
577 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
579 struct emp_qelem *qp;
580 struct emp_qelem *next;
585 natp = getnatp(sectp->sct_own);
587 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
588 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
596 /* We got here, so we could theoretically see the ship. Now,
597 * do we want to see it in our telebox? If not, return positive
598 * since we could see the ship and want forts to fire. */
599 if (!(natp->nat_flags & NF_COASTWATCH))
602 for (qp = list->q_back; qp != list; qp = next) {
604 mlp = (struct mlist *)qp;
605 if (mlp->mcp->m_flags & M_SUB)
607 wu(0, sectp->sct_own,
608 "%s %s sighted at %s\n",
609 cname(mlp->ship.shp_own),
611 xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own));
613 setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_LOOK);
621 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
627 double range, range2, guneff;
631 s_char notified[MAXNOC];
634 /* Inform neutral and worse */
635 for (i = 0; i < MAXNOC; ++i) {
636 if (getrel(getnatp(i), victim) <= NEUTRAL)
642 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
643 while (nxtsct(&ns, &fsect)) {
646 if (fsect.sct_own == victim)
648 if (notified[fsect.sct_own])
650 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
651 if (notify_coastguard(list, trange, &fsect))
652 notified[fsect.sct_own] = 1;
654 if (opt_NO_FORT_FIRE)
655 return 0; /* Only coastwatch notify in nofortfire */
656 /* Only fire at Hostile ships */
657 for (i = 0; i < MAXNOC; ++i) {
658 if (getrel(getnatp(i), victim) >= NEUTRAL)
661 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
662 while (nxtsct(&ns, &fsect)) {
663 if (!notified[fsect.sct_own])
665 if (fsect.sct_type != SCT_FORTR)
667 gun = fsect.sct_item[I_GUN];
670 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
671 if (fsect.sct_effic > 59)
673 range2 = roundrange(range);
674 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
677 if (fsect.sct_item[I_MILIT] < 5)
679 shell = fsect.sct_item[I_SHELL];
681 shell += supply_commod(fsect.sct_own,
682 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
686 fsect.sct_item[I_SHELL] = shell;
690 guneff = landgun((int)fsect.sct_effic, gun);
693 mpr(victim, "Incoming fire does %d damage!\n", dam);
695 mpr(victim, "%s fires at you for %d!\n",
696 xyas(fsect.sct_x,fsect.sct_y,victim),
700 "%s fires at %s ships in %s for %d!\n",
701 xyas(fsect.sct_x, fsect.sct_y,
703 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
704 nreport(fsect.sct_own, N_SHP_SHELL, victim, 1);
707 return shp_damage(list, totdam, 0, M_SUB, newx, newy);
712 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
716 if (shp_contains(list, newx, newy, 0, M_SUB)) {
717 stopping |= shp_fort_interdiction(list, newx, newy, victim);
719 if (shp_contains(list, newx, newy, 0, M_SUB)) {
722 unit_interdict(newx, newy, victim, "ships",
723 shp_easiest_target(list, 0,
725 MI_INTERDICT), 0, M_SUB, newx,
727 if (most_valuable_ship(list)) {
729 shp_missile_interdiction(list, newx, newy, victim);
733 if (shp_contains(list, newx, newy, M_SUB, 0)) {
736 unit_interdict(newx, newy, victim, "subs",
737 shp_easiest_target(list, M_SUB, 0),
738 MI_SINTERDICT), M_SUB, 0, newx,
744 /* high value of hardtarget is harder to hit */
746 shp_hardtarget(struct shpstr *sp)
750 struct mchrstr *mcp = mchr + sp->shp_type;
753 getsect(sp->shp_x, sp->shp_y, §);
754 onsea = (sect.sct_type == SCT_WATER);
755 if (mcp->m_flags & M_SUB)
757 return (int)(((double)sp->shp_effic / 100.0) *
758 (20 + (double)sp->shp_speed * onsea / 2.0 - vis));
762 shp_hit_mine(struct shpstr *sp, struct mchrstr *mcp)
766 mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n",
767 xyas(sp->shp_x, sp->shp_y, sp->shp_own));
769 nreport(sp->shp_own, N_HIT_MINE, 0, 1);
771 m = 22.0 + (double)(random() % 21);
772 if (mcp->m_flags & M_SWEEP)
775 shipdamage(sp, ldround(m, 1));
781 shp_view(struct emp_qelem *list)
784 struct emp_qelem *qp;
785 struct emp_qelem *next;
788 for (qp = list->q_back; qp != list; qp = next) {
790 mlp = (struct mlist *)qp;
791 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
792 if (mlp->mcp->m_flags & M_FOOD)
793 mpr(mlp->ship.shp_own, "[fert:%d] ", sect.sct_fertil);
794 if (mlp->mcp->m_flags & M_OIL)
795 mpr(mlp->ship.shp_own, "[oil:%d] ", sect.sct_oil);
796 mpr(mlp->ship.shp_own, "%s @ %s %d%% %s\n",
798 xyas(mlp->ship.shp_x, mlp->ship.shp_y, player->cnum),
799 sect.sct_effic, dchr[sect.sct_type].d_name);
804 shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
808 struct emp_qelem *qp;
809 struct emp_qelem *next;
810 struct emp_qelem *nqp;
811 struct emp_qelem *nnext;
819 double tech; /* for mapping */
820 double tf; /* for mapping */
823 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
824 shp_put(list, actor);
829 for (qp = list->q_back; qp != list; qp = next) {
831 mlp = (struct mlist *)qp;
832 newx = xnorm(mlp->ship.shp_x + dx);
833 newy = ynorm(mlp->ship.shp_y + dy);
834 getsect(newx, newy, §);
835 if (shp_check_nav(§) != CN_NAVIGABLE ||
836 (sect.sct_own && actor != sect.sct_own &&
837 getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
839 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
842 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
847 if (opt_BIG_CITY && sect.sct_type == SCT_CAPIT) {
848 if (mlp->mcp->m_lcm + 2 * mlp->mcp->m_hcm >= 60) {
850 "is too large to fit into the canal system at %s",
851 xyas(newx, newy, actor));
856 if (mlp->mobil <= 0.0) {
857 shp_mess("is out of mobility", mlp);
860 mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
862 (mobcost + techfact(mlp->ship.shp_tech, mobcost));
863 mlp->ship.shp_x = newx;
864 mlp->ship.shp_y = newy;
865 if (mlp->mobil - mobcost < -127) {
868 mlp->mobil -= mobcost;
870 mlp->ship.shp_mobil = (int)mlp->mobil;
871 putship(mlp->ship.shp_uid, &mlp->ship);
872 mlp->done = 0; /* We haven't interdicted this ship yet */
874 /* Now update the map for this ship */
875 tech = techfact(mlp->ship.shp_tech, (double)mlp->mcp->m_vrnge);
876 if (mlp->mcp->m_flags & M_SONAR)
877 tf = techfact(mlp->ship.shp_tech, 1.0);
880 radmapupd(mlp->ship.shp_own, mlp->ship.shp_x, mlp->ship.shp_y,
881 (int)mlp->ship.shp_effic, (int)tech, tf);
885 stopping |= shp_sweep(list, 0, actor);
888 stopping |= shp_check_mines(list);
892 /* Ok, run through each ship and interdict each coordinate */
893 for (qp = list->q_back; qp != list; qp = next) {
895 mlp = (struct mlist *)qp;
896 /* Has this ship been interdicted yet? */
899 newx = mlp->ship.shp_x;
900 newy = mlp->ship.shp_y;
901 stopping |= shp_interdict(list, newx, newy, actor);
904 /* Now, set all ships in this coordinate to done */
905 for (nqp = list->q_back; nqp != list; nqp = nnext) {
907 mlp = (struct mlist *)nqp;
908 if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy)
918 * Check for incoming missiles with a P_MAR flag.
919 * Return True=1 if the missile was shotdown.
922 * Chad Zabel, July 95
926 shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
932 double gun, eff, teff;
934 snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
936 while (nxtitem(&ni, (caddr_t)&ship)) {
940 if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE))
943 if (getrel(getnatp(ship.shp_own), bombown) >= NEUTRAL)
946 if (ship.shp_effic < 60)
949 shell = ship.shp_item[I_SHELL];
950 if (ship.shp_item[I_MILIT] < 1) /* do we have mil? */
952 if (shell < 2) { /* do we need shells */
953 shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
958 if (ship.shp_item[I_GUN] < 1) /* we need at least 1 gun */
961 /* now calculate the odds */
962 gun = min(ship.shp_item[I_GUN], ship.shp_glim);
963 eff = (double)ship.shp_effic / 100.0;
965 (((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0));
966 /* raise 4.5 for better interception -KHS */
967 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
973 mpr(bombown, "%s anti-missile system activated...",
974 cname(ship.shp_own));
975 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
977 mpr(ship.shp_own, "%d%% hitchance...", hitchance);
979 ship.shp_item[I_SHELL] = shell - 2;
980 putship(ship.shp_uid, &ship);
982 if (roll(100) <= hitchance) {
983 mpr(bombown, "KABOOOM!! Missile destroyed\n\n");
985 "KABOOOM!! Incoming missile destroyed!\n\n");
988 mpr(bombown, "SWOOSH!! anti-missile system failed!!\n");
990 "SWOOSH!! Missile evades anti-missile systems\n\n");
993 return 0; /* all attempts failed */
997 shp_path(int together, struct shpstr *shp, s_char *buf)
1001 struct sctstr d_sect;
1004 if (!sarg_xy(buf, &destx, &desty))
1008 "Cannot go to a destination sector if not all starting in the same sector\n");
1011 if (!getsect(destx, desty, &d_sect)) {
1012 mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty);
1016 cp = (s_char *)BestShipPath(buf, shp->shp_x, shp->shp_y,
1017 d_sect.sct_x, d_sect.sct_y, player->cnum);
1018 if (!cp || shp->shp_mobil <= 0) {
1019 mpr(shp->shp_own, "Can't get to '%s' right now.\n",
1020 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1026 /* Fire missiles at a ship which has fired shells */
1028 shp_missdef(struct shpstr *sp, natid victim)
1030 struct emp_qelem list;
1037 mlp = (struct mlist *)malloc(sizeof(struct mlist));
1038 mlp->mcp = &mchr[(int)sp->shp_type];
1040 mlp->mobil = (double)sp->shp_mobil;
1041 emp_insque(&mlp->queue, &list);
1042 sprintf(buf, "%s", prship(&mlp->ship));
1044 eff = sp->shp_effic;
1045 if (most_valuable_ship(&list)) {
1046 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
1047 getship(sp->shp_uid, sp);
1051 "missiles launched in defense did 100%% damage to %s\n",
1053 wu(0, victim, "%s sunk!\n", buf);
1054 } else if (eff > 0 && sp->shp_effic < eff) {
1056 "missiles launched in defense did %d%% damage to %s\n",
1057 100 * (eff - sp->shp_effic) / eff, buf);
1065 * Set SP's tech to TLEV along with everything else that depends on it.
1068 shp_set_tech(struct shpstr *sp, int tlev)
1070 struct mchrstr *mcp = mchr + sp->shp_type;
1071 int tech_diff = tlev - mcp->m_tech;
1073 if (CANT_HAPPEN(tech_diff < 0)) {
1078 sp->shp_tech = tlev;
1079 sp->shp_armor = (short)SHP_DEF(mcp->m_armor, tech_diff);
1080 sp->shp_speed = (short)SHP_SPD(mcp->m_speed, tech_diff);
1081 sp->shp_visib = (short)SHP_VIS(mcp->m_visib, tech_diff);
1082 sp->shp_frnge = (short)SHP_RNG(mcp->m_frnge, tech_diff);
1083 sp->shp_glim = (short)SHP_FIR(mcp->m_glim, tech_diff);