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
53 #include "prototypes.h"
55 extern double tfactfire(natid, double);
57 extern int etu_per_update;
59 static int shp_check_nav(struct sctstr *);
60 static int shp_check_one_mines(struct mlist *);
61 static int shp_hit_mine(struct shpstr *, struct mchrstr *);
62 static void shp_mess(s_char *, struct mlist *);
65 shp_sel(struct nstr_item *ni, struct emp_qelem *list)
77 while (nxtitem(ni, (s_char *)&ship)) {
80 mcp = &mchr[(int)ship.shp_type];
81 /* if (wantflags && (mcp->m_flags & wantflags) != wantflags)
83 if (nowantflags && mcp->m_flags & nowantflags)
87 if (ontradingblock(EF_SHIP, (int *)&ship)) {
88 pr("ship #%d inelligible - it's for sale.\n",
93 /* This abuse is better fixed by building a ship with the normal negative
94 mobility that everything else is built with */
97 if (ship.shp_effic < 21 &&
98 ship.shp_mobil < etu_per_update) {
99 pr("%s needs at least %d mob to navigate.\n",
100 prship(&ship), etu_per_update);
105 ship.shp_mission = 0;
107 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
108 putship(ship.shp_uid, &ship);
109 mlp = (struct mlist *)malloc(sizeof(struct mlist));
112 mlp->mobil = (double)ship.shp_mobil;
113 emp_insque(&mlp->queue, list);
117 /* This function assumes that the list was created by shp_sel */
119 shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
120 int *togetherp, natid actor)
122 extern int update_pending;
123 struct emp_qelem *qp;
124 struct emp_qelem *next;
136 for (qp = list->q_back; qp != list; qp = next) {
138 mlp = (struct mlist *)qp;
139 getship(mlp->ship.shp_uid, &ship);
140 if (ship.shp_own != actor) {
141 mpr(actor, "%s was sunk at %s\n",
142 prship(&ship), xyas(ship.shp_x, ship.shp_y, actor));
143 emp_remque((struct emp_qelem *)mlp);
148 if (*ship.shp_path && !update_pending) {
149 shp_mess("has a sail path", mlp);
150 mpr(actor, "Use `sail <#> -' to reset\n");
154 /* check crew - uws don't count */
155 getvec(VT_ITEM, vec, (s_char *)&ship, EF_SHIP);
156 if (vec[I_MILIT] == 0 && vec[I_CIVIL] == 0) {
157 shp_mess("is crewless", mlp);
160 if (!getsect(ship.shp_x, ship.shp_y, §)) {
161 shp_mess("was sucked into the sky by a strange looking spaceship", mlp); /* heh -KHS */
164 switch (shp_check_nav(§)) {
165 case CN_CONSTRUCTION:
166 shp_mess("is caught in a construction zone", mlp);
169 shp_mess("is landlocked", mlp);
175 shp_mess("was just swallowed by a big green worm", mlp);
183 if (ship.shp_x != allx || ship.shp_y != ally)
185 if (ship.shp_mobil + 1 < (int)mlp->mobil) {
186 mlp->mobil = (double)ship.shp_mobil;
188 if (mlp->mobil < *minmobp)
189 *minmobp = mlp->mobil;
190 if (mlp->mobil > *maxmobp)
191 *maxmobp = mlp->mobil;
197 shp_put(struct emp_qelem *list, natid actor)
199 register struct emp_qelem *qp;
200 register struct emp_qelem *newqp;
205 mlp = (struct mlist *)qp;
206 mpr(actor, "%s stopped at %s\n", prship(&mlp->ship),
207 xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
208 mlp->ship.shp_mobil = (int)mlp->mobil;
209 putship(mlp->ship.shp_uid, &mlp->ship);
218 shp_sweep(struct emp_qelem *ship_list, int verbose, natid actor)
220 struct emp_qelem *qp;
221 struct emp_qelem *next;
224 int mines, m, max, shells;
229 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
231 mlp = (struct mlist *)qp;
232 if (!(mlp->mcp->m_flags & M_SWEEP)) {
234 mpr(actor, "%s doesn't have minesweeping capability!\n",
238 if (mlp->mobil <= 0.0) {
240 mpr(actor, "%s is out of mobility!\n", prship(&mlp->ship));
243 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
244 if (sect.sct_type != SCT_WATER) {
246 mpr(actor, "%s is not at sea. No mines there!\n",
250 mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
251 mobcost = 480.0 / (mobcost +
252 techfact(mlp->ship.shp_tech, mobcost));
253 mlp->mobil -= mobcost;
254 mlp->ship.shp_mobil = (int)mlp->mobil;
255 putship(mlp->ship.shp_uid, &mlp->ship);
256 if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR)))
258 max = vl_find(V_SHELL, mlp->mcp->m_vtype,
259 mlp->mcp->m_vamt, (int)mlp->mcp->m_nv);
260 shells = getvar(V_SHELL, (s_char *)&mlp->ship, EF_SHIP);
261 for (m = 0; mines > 0 && m < 5; m++) {
263 mpr(actor, "Sweep...\n");
265 shells = min(max, shells + 1);
266 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
269 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
270 putvar(V_SHELL, shells, (s_char *)&mlp->ship, EF_SHIP);
271 if (shp_check_one_mines(mlp)) {
276 putship(mlp->ship.shp_uid, &mlp->ship);
285 shp_check_one_mines(struct mlist *mlp)
292 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
293 if (sect.sct_type != SCT_WATER)
295 if (!(mines = getvar(V_MINE, (s_char *)§, EF_SECTOR)))
297 if (chance(DMINE_HITCHANCE(mines))) {
298 actor = mlp->ship.shp_own;
299 shp_hit_mine(&mlp->ship, mlp->mcp);
301 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
304 putvar(V_MINE, mines, (s_char *)§, EF_SECTOR);
306 putship(mlp->ship.shp_uid, (s_char *)&mlp->ship);
307 if (!mlp->ship.shp_own)
314 shp_check_mines(struct emp_qelem *ship_list)
316 struct emp_qelem *qp;
317 struct emp_qelem *next;
321 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
323 mlp = (struct mlist *)qp;
324 if (shp_check_one_mines(mlp)) {
334 shp_list(struct emp_qelem *ship_list)
336 struct emp_qelem *qp;
337 struct emp_qelem *next;
342 pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
344 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
346 mlp = (struct mlist *)qp;
348 pr("%4d ", shp->shp_uid);
349 pr("%-16.16s ", mlp->mcp->m_name);
350 prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->ship.shp_own);
351 pr("%1c", shp->shp_fleet);
352 pr("%4d%%", shp->shp_effic);
353 getvec(VT_ITEM, vec, (s_char *)shp, EF_SHIP);
354 pr("%4d", vec[I_MILIT]);
355 pr("%4d", vec[I_SHELL]);
356 pr("%4d", vec[I_GUN]);
358 pr("%3d", shp->shp_nplane);
359 pr("%3d", shp->shp_nchoppers);
360 pr("%3d", shp->shp_nxlight);
362 pr("%3d", shp->shp_nland);
363 pr("%4d", shp->shp_mobil);
364 pr("%4d\n", shp->shp_tech);
369 shp_mess(s_char *str, struct mlist *mlp)
371 mpr(mlp->ship.shp_own, "%s %s & stays in %s\n",
373 str, xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
374 mlp->ship.shp_mobil = (int)mlp->mobil;
375 putship(mlp->ship.shp_uid, &mlp->ship);
376 emp_remque((struct emp_qelem *)mlp);
381 shp_check_nav(struct sctstr *sect)
383 switch (dchr[sect->sct_type].d_flg & 03) {
388 if (sect->sct_effic < 2)
389 return CN_CONSTRUCTION;
392 if (sect->sct_effic < 60)
393 return CN_CONSTRUCTION;
396 return CN_LANDLOCKED;
402 shp_count(struct emp_qelem *list, int wantflags, int nowantflags, int x,
405 struct emp_qelem *qp;
406 struct emp_qelem *next;
410 for (qp = list->q_back; qp != list; qp = next) {
412 mlp = (struct mlist *)qp;
413 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
415 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
417 if (nowantflags && mlp->mcp->m_flags & nowantflags)
425 shp_damage_one(struct mlist *mlp, int dam)
427 shipdamage(&mlp->ship, dam);
428 putship(mlp->ship.shp_uid, &mlp->ship);
429 if (!mlp->ship.shp_own) {
430 emp_remque((struct emp_qelem *)mlp);
436 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
437 int nowantflags, int x, int y)
439 struct emp_qelem *qp;
440 struct emp_qelem *next;
446 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
448 dam = ldround(((double)totdam / (double)count), 1);
449 for (qp = list->q_back; qp != list; qp = next) {
451 mlp = (struct mlist *)qp;
452 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
454 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
456 if (nowantflags && mlp->mcp->m_flags & nowantflags)
458 shp_damage_one(mlp, dam);
464 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
467 struct emp_qelem *qp;
468 struct emp_qelem *next;
471 for (qp = list->q_back; qp != list; qp = next) {
473 mlp = (struct mlist *)qp;
474 /* If the ship isn't in the requested sector, then continue */
475 if (newx != mlp->ship.shp_x || newy != mlp->ship.shp_y)
477 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
479 if (nowantflags && mlp->mcp->m_flags & nowantflags)
486 static struct mlist *
487 most_valuable_ship(struct emp_qelem *list)
489 struct emp_qelem *qp;
490 struct emp_qelem *next;
492 struct mlist *mvs = 0;
494 for (qp = list->q_back; qp != list; qp = next) {
496 mlp = (struct mlist *)qp;
497 if (mlp->mcp->m_flags & M_SUB)
499 if (!mlp->mcp->m_nxlight &&
500 !mlp->mcp->m_nchoppers &&
501 mlp->mcp->m_cost < 1000 &&
502 !mlp->mcp->m_nplanes && !mlp->mcp->m_nland)
508 if (mlp->mcp->m_cost * mlp->ship.shp_effic >
509 mvs->mcp->m_cost * mvs->ship.shp_effic)
516 shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
518 struct emp_qelem *qp;
519 struct emp_qelem *next;
522 int easiest = 9876; /* things start great for victim */
525 for (qp = list->q_back; qp != list; qp = next) {
527 mlp = (struct mlist *)qp;
528 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
530 if (nowantflags && mlp->mcp->m_flags & nowantflags)
532 hard = shp_hardtarget(&mlp->ship);
534 easiest = hard; /* things get worse for victim */
537 return easiest - count;
541 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
547 struct emp_qelem msl_list, *qp, *newqp;
551 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
554 while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
555 sprintf(what, "%s", prship(&mvs->ship));
556 dam = msl_launch_mindam(&msl_list, newx, newy,
557 shp_hardtarget(&mvs->ship),
558 EF_SHIP, 1, what, victim, MI_INTERDICT);
561 "missile interdiction mission does %d damage to %s!\n",
563 shp_damage_one(mvs, dam);
566 } else if (++twotries >= 2) {
570 qp = msl_list.q_forw;
571 while (qp != msl_list.q_forw) {
581 /* Note that this function has a side effect - it uses coastwatch
582 * ranges to see if it should fire upon a ship. So, this function
583 * is expected to return positive if a ship is in range, and 0 if a
584 * ship is not in range. */
586 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
588 struct emp_qelem *qp;
589 struct emp_qelem *next;
594 natp = getnatp(sectp->sct_own);
596 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
597 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
605 /* We got here, so we could theoretically see the ship. Now,
606 * do we want to see it in our telebox? If not, return positive
607 * since we could see the ship and want forts to fire. */
608 if (!(natp->nat_flags & NF_COASTWATCH))
611 for (qp = list->q_back; qp != list; qp = next) {
613 mlp = (struct mlist *)qp;
614 if (mlp->mcp->m_flags & M_SUB)
616 wu(0, sectp->sct_own,
617 "%s %s sighted at %s\n",
618 cname(mlp->ship.shp_own),
620 xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own));
622 setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_LOOK);
630 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
636 double range, range2, guneff;
640 s_char notified[MAXNOC];
643 /* Inform neutral and worse */
644 for (i = 0; i < MAXNOC; ++i) {
645 if (getrel(getnatp(i), victim) <= NEUTRAL)
651 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
652 while (nxtsct(&ns, &fsect)) {
655 if (fsect.sct_own == victim)
657 if (notified[fsect.sct_own])
659 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
660 if (notify_coastguard(list, trange, &fsect))
661 notified[fsect.sct_own] = 1;
663 if (opt_NO_FORT_FIRE)
664 return 0; /* Only coastwatch notify in nofortfire */
665 /* Only fire at Hostile ships */
666 for (i = 0; i < MAXNOC; ++i) {
667 if (getrel(getnatp(i), victim) >= NEUTRAL)
670 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
671 while (nxtsct(&ns, &fsect)) {
672 if (!notified[fsect.sct_own])
674 if (fsect.sct_type != SCT_FORTR)
676 gun = getvar(V_GUN, (s_char *)&fsect, EF_SECTOR);
679 range = tfactfire(fsect.sct_own, (double)min(gun, 7));
680 if (fsect.sct_effic > 59)
682 range2 = roundrange(range);
683 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
686 if (getvar(V_MILIT, (s_char *)&fsect, EF_SECTOR) < 5)
688 shell = getvar(V_SHELL, (s_char *)&fsect, EF_SECTOR);
690 shell += supply_commod(fsect.sct_own,
691 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
695 putvar(V_SHELL, shell, (s_char *)&fsect, EF_SECTOR);
699 guneff = landgun((int)fsect.sct_effic, gun);
702 mpr(victim, "Incoming fire does %d damage!\n", dam);
704 mpr(victim, "%s fires at you for %d!\n",
705 xyas(fsect.sct_x,fsect.sct_y,victim),
709 "%s fires at %s ships in %s for %d!\n",
710 xyas(fsect.sct_x, fsect.sct_y,
712 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
713 nreport(fsect.sct_own, N_SHP_SHELL, victim, 1);
716 return shp_damage(list, totdam, 0, M_SUB, newx, newy);
721 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
725 if (shp_contains(list, newx, newy, 0, M_SUB)) {
726 stopping |= shp_fort_interdiction(list, newx, newy, victim);
728 if (shp_contains(list, newx, newy, 0, M_SUB)) {
731 unit_interdict(newx, newy, victim, "ships",
732 shp_easiest_target(list, 0,
734 MI_INTERDICT), 0, M_SUB, newx,
736 if (most_valuable_ship(list)) {
738 shp_missile_interdiction(list, newx, newy, victim);
742 if (shp_contains(list, newx, newy, M_SUB, 0)) {
745 unit_interdict(newx, newy, victim, "subs",
746 shp_easiest_target(list, M_SUB, 0),
747 MI_SINTERDICT), M_SUB, 0, newx,
753 /* high value of hardtarget is harder to hit */
755 shp_hardtarget(struct shpstr *sp)
759 struct mchrstr *mcp = mchr + sp->shp_type;
762 getsect(sp->shp_x, sp->shp_y, §);
763 onsea = (sect.sct_type == SCT_WATER);
764 if (mcp->m_flags & M_SUB)
766 return (int)(((double)sp->shp_effic / 100.0) *
767 (20 + (double)sp->shp_speed * onsea / 2.0 - vis));
771 shp_hit_mine(struct shpstr *sp, struct mchrstr *mcp)
775 mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n",
776 xyas(sp->shp_x, sp->shp_y, sp->shp_own));
778 nreport(sp->shp_own, N_HIT_MINE, 0, 1);
780 m = 22.0 + (double)(random() % 21);
781 if (mcp->m_flags & M_SWEEP)
784 shipdamage(sp, ldround(m, 1));
790 shp_view(struct emp_qelem *list)
793 struct emp_qelem *qp;
794 struct emp_qelem *next;
797 for (qp = list->q_back; qp != list; qp = next) {
799 mlp = (struct mlist *)qp;
800 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
801 if (mlp->mcp->m_flags & M_FOOD)
802 mpr(mlp->ship.shp_own, "[fert:%d] ", sect.sct_fertil);
803 if (mlp->mcp->m_flags & M_OIL)
804 mpr(mlp->ship.shp_own, "[oil:%d] ", sect.sct_oil);
805 mpr(mlp->ship.shp_own, "%s @ %s %d%% %s\n",
807 xyas(mlp->ship.shp_x, mlp->ship.shp_y, player->cnum),
808 sect.sct_effic, dchr[sect.sct_type].d_name);
813 shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
817 struct emp_qelem *qp;
818 struct emp_qelem *next;
819 struct emp_qelem *nqp;
820 struct emp_qelem *nnext;
828 double tech; /* for mapping */
829 double tf; /* for mapping */
832 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
833 shp_put(list, actor);
838 for (qp = list->q_back; qp != list; qp = next) {
840 mlp = (struct mlist *)qp;
841 newx = xnorm(mlp->ship.shp_x + dx);
842 newy = ynorm(mlp->ship.shp_y + dy);
843 getsect(newx, newy, §);
844 if (shp_check_nav(§) != CN_NAVIGABLE ||
845 (sect.sct_own && actor != sect.sct_own &&
846 getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
848 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
851 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
856 if (opt_BIG_CITY && sect.sct_type == SCT_CAPIT) {
857 if (mlp->mcp->m_lcm + 2 * mlp->mcp->m_hcm >= 60) {
859 "is too large to fit into the canal system at %s",
860 xyas(newx, newy, actor));
865 if (mlp->mobil <= 0.0) {
866 shp_mess("is out of mobility", mlp);
869 mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
871 (mobcost + techfact(mlp->ship.shp_tech, mobcost));
872 mlp->ship.shp_x = newx;
873 mlp->ship.shp_y = newy;
874 if (mlp->mobil - mobcost < -127) {
877 mlp->mobil -= mobcost;
879 mlp->ship.shp_mobil = (int)mlp->mobil;
880 putship(mlp->ship.shp_uid, &mlp->ship);
881 mlp->done = 0; /* We haven't interdicted this ship yet */
883 /* Now update the map for this ship */
884 tech = techfact(mlp->ship.shp_tech, (double)mlp->mcp->m_vrnge);
885 if (mlp->mcp->m_flags & M_SONAR)
886 tf = techfact(mlp->ship.shp_tech, 1.0);
889 radmapupd(mlp->ship.shp_own, mlp->ship.shp_x, mlp->ship.shp_y,
890 (int)mlp->ship.shp_effic, (int)tech, tf);
894 stopping |= shp_sweep(list, 0, actor);
897 stopping |= shp_check_mines(list);
901 /* Ok, run through each ship and interdict each coordinate */
902 for (qp = list->q_back; qp != list; qp = next) {
904 mlp = (struct mlist *)qp;
905 /* Has this ship been interdicted yet? */
908 newx = mlp->ship.shp_x;
909 newy = mlp->ship.shp_y;
910 stopping |= shp_interdict(list, newx, newy, actor);
913 /* Now, set all ships in this coordinate to done */
914 for (nqp = list->q_back; nqp != list; nqp = nnext) {
916 mlp = (struct mlist *)nqp;
917 if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy)
927 * Check for incoming missiles with a P_MAR flag.
928 * Return True=1 if the missile was shotdown.
931 * Chad Zabel, July 95
935 shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
941 double gun, eff, teff;
943 snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
945 while (nxtitem(&ni, (caddr_t)&ship)) {
949 if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE))
952 if (getrel(getnatp(ship.shp_own), bombown) >= NEUTRAL)
955 if (ship.shp_effic < 60)
958 if (getvec(VT_ITEM, vec, (caddr_t)&ship, EF_SHIP) < 0)
960 if (vec[I_MILIT] < 1) /* do we have mil? */
962 if (vec[I_SHELL] < 2) { /* do we need shells */
963 if (vec[I_SHELL] += supply_commod(ship.shp_own,
965 ship.shp_y, I_SHELL, 2) < 2)
968 if (vec[I_GUN] < 1) /* we need at least 1 gun */
971 /* now calculate the odds */
972 gun = ((double)min(vec[I_GUN], ship.shp_glim));
973 eff = (double)ship.shp_effic / 100.0;
975 (((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0));
976 /* raise 4.5 for better interception -KHS */
977 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
983 mpr(bombown, "%s anti-missile system activated...",
984 cname(ship.shp_own));
985 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
987 mpr(ship.shp_own, "%d%% hitchance...", hitchance);
989 putvar(V_SHELL, vec[I_SHELL] - 2, (caddr_t)&ship, EF_SHIP);
990 putship(ship.shp_uid, &ship);
992 if (roll(100) <= hitchance) {
993 mpr(bombown, "KABOOOM!! Missile destroyed\n\n");
995 "KABOOOM!! Incoming missile destroyed!\n\n");
998 mpr(bombown, "SWOOSH!! anti-missile system failed!!\n");
1000 "SWOOSH!! Missile evades anti-missile systems\n\n");
1003 return 0; /* all attempts failed */
1007 shp_path(int together, struct shpstr *shp, s_char *buf)
1011 struct sctstr d_sect;
1014 if (!sarg_xy(buf, &destx, &desty))
1018 "Cannot go to a destination sector if not all starting in the same sector\n");
1021 if (!getsect(destx, desty, &d_sect)) {
1022 mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty);
1026 cp = (s_char *)BestShipPath(buf, shp->shp_x, shp->shp_y,
1027 d_sect.sct_x, d_sect.sct_y, player->cnum);
1028 if (!cp || shp->shp_mobil <= 0) {
1029 mpr(shp->shp_own, "Can't get to '%s' right now.\n",
1030 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1036 /* Fire missiles at a ship which has fired shells */
1038 shp_missdef(struct shpstr *sp, natid victim)
1040 struct emp_qelem list;
1047 mlp = (struct mlist *)malloc(sizeof(struct mlist));
1048 mlp->mcp = &mchr[(int)sp->shp_type];
1050 mlp->mobil = (double)sp->shp_mobil;
1051 emp_insque(&mlp->queue, &list);
1052 sprintf(buf, "%s", prship(&mlp->ship));
1054 eff = sp->shp_effic;
1055 if (most_valuable_ship(&list)) {
1056 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
1057 getship(sp->shp_uid, sp);
1061 "missiles launched in defense did 100%% damage to %s\n",
1063 wu(0, victim, "%s sunk!\n", buf);
1064 } else if (eff > 0 && sp->shp_effic < eff) {
1066 "missiles launched in defense did %d%% damage to %s\n",
1067 100 * (eff - sp->shp_effic) / eff, buf);