2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2017, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * shpsub.c: Ship subroutine stuff
29 * Known contributors to this file:
31 * Steve McClure, 1996-2000
32 * Markus Armbruster, 2006-2015
49 #include "prototypes.h"
55 static void shp_nav_put_one(struct ulist *);
56 static int shp_check_one_mines(struct ulist *);
57 static int shp_hit_mine(struct shpstr *);
60 shp_find_capable(struct emp_qelem *list, int flags)
65 for (qp = list->q_back; qp != list; qp = qp->q_back) {
66 mlp = (struct ulist *)qp;
67 if (mchr[mlp->unit.ship.shp_type].m_flags & flags)
74 shp_may_nav(struct shpstr *sp, struct shpstr *flg, char *suffix)
78 if (!sp->shp_own || !getsect(sp->shp_x, sp->shp_y, §)) {
83 if (opt_MARKET && ontradingblock(EF_SHIP, sp)) {
84 mpr(sp->shp_own, "%s is on the trading block%s\n",
89 if (sp->shp_item[I_MILIT] == 0 && sp->shp_item[I_CIVIL] == 0) {
90 mpr(sp->shp_own, "%s is crewless%s\n", prship(sp), suffix);
94 switch (shp_check_nav(sp, §)) {
97 case SHP_STUCK_CONSTRUCTION:
98 mpr(sp->shp_own, "%s is caught in a construction zone%s\n",
104 case SHP_STUCK_CANAL:
105 case SHP_STUCK_IMPASSABLE:
106 mpr(sp->shp_own, "%s is landlocked%s\n", prship(sp), suffix);
110 if (flg && (sp->shp_x != flg->shp_x || sp->shp_y != flg->shp_y)) {
111 mpr(sp->shp_own, "%s is not with the flagship%s\n",
119 shp_sel(struct nstr_item *ni, struct emp_qelem *list)
121 struct shpstr ship, *flg = NULL;
125 while (nxtitem(ni, &ship)) {
127 * It would be nice to let deities navigate foreign ships, but
128 * much of the code assumes that only the ship's owner can
131 if (!ship.shp_own || ship.shp_own != player->cnum)
133 if (!shp_may_nav(&ship, flg, ""))
136 ship.shp_mission = 0;
138 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
139 putship(ship.shp_uid, &ship);
140 mlp = shp_insque(&ship, list);
142 flg = &mlp->unit.ship;
147 * Append @sp to @list.
148 * Return the new list link.
151 shp_insque(struct shpstr *sp, struct emp_qelem *list)
153 struct ulist *mlp = malloc(sizeof(struct ulist));
155 mlp->unit.ship = *sp;
156 mlp->mobil = sp->shp_mobil;
157 emp_insque(&mlp->queue, list);
162 shp_nav_stay_behind(struct emp_qelem *list, natid actor)
164 struct emp_qelem *qp;
165 struct emp_qelem *next;
167 struct shpstr *sp, *flg = NULL;
170 for (qp = list->q_back; qp != list; qp = next) {
172 mlp = (struct ulist *)qp;
173 sp = &mlp->unit.ship;
174 getship(sp->shp_uid, sp);
176 if (sp->shp_own != actor) {
177 mpr(actor, "%s was sunk at %s\n",
178 prship(sp), xyas(sp->shp_x, sp->shp_y, actor));
179 emp_remque(&mlp->queue);
184 snprintf(and_stays, sizeof(and_stays), " & stays in %s",
185 xyas(sp->shp_x, sp->shp_y, actor));
186 if (!shp_may_nav(sp, flg, and_stays)) {
187 shp_nav_put_one(mlp);
193 if (sp->shp_mobil + 1 < (int)mlp->mobil) {
194 mlp->mobil = sp->shp_mobil;
200 shp_nav_put(struct emp_qelem *list, natid actor)
202 struct emp_qelem *qp, *next;
206 for (qp = list->q_back; qp != list; qp = next) {
208 mlp = (struct ulist *)qp;
209 sp = &mlp->unit.ship;
210 mpr(actor, "%s stopped at %s\n",
211 prship(sp), xyas(sp->shp_x, sp->shp_y, actor));
212 shp_nav_put_one(mlp);
217 shp_nav_put_one(struct ulist *mlp)
219 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
220 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
221 emp_remque(&mlp->queue);
226 * Sweep seamines with engineers in @ship_list for @actor.
227 * All ships in @ship_list must be in the same sector.
228 * If @explicit is non-zero, this is for an explicit sweep command from
229 * a player. Else it's an automatic "on the move" sweep.
230 * If @takemob is non-zero, require and charge mobility.
231 * Return non-zero when the ships should stop.
234 shp_sweep(struct emp_qelem *ship_list, int explicit, int takemob,
237 struct emp_qelem *qp;
238 struct emp_qelem *next;
241 int mines, m, max, shells;
243 int stopping = 0, first = 1;
245 mlp = shp_find_capable(ship_list, M_SWEEP);
248 mpr(actor, "No minesweepers!\n");
252 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
253 if (sect.sct_type != SCT_WATER) {
255 mpr(actor, "%s is a %s. No seamines there!\n",
256 xyas(sect.sct_x, sect.sct_y, actor),
257 dchr[sect.sct_type].d_name);
261 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
263 mlp = (struct ulist *)qp;
264 if (!(mchr[mlp->unit.ship.shp_type].m_flags & M_SWEEP))
267 if (mlp->mobil <= 0.0) {
269 mpr(actor, "%s is out of mobility!\n",
270 prship(&mlp->unit.ship));
273 mlp->mobil -= shp_mobcost(&mlp->unit.ship);
274 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
276 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
277 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
278 if (!(mines = sect.sct_mines))
280 max = mchr[mlp->unit.ship.shp_type].m_item[I_SHELL];
281 shells = mlp->unit.ship.shp_item[I_SHELL];
282 for (m = 0; mines > 0 && m < 5; m++) {
285 mpr(actor, "Approaching minefield at %s...\n",
286 xyas(sect.sct_x, sect.sct_y, actor));
289 mpr(actor, "Sweep...\n");
291 shells = MIN(max, shells + 1);
292 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
295 sect.sct_mines = mines;
296 mlp->unit.ship.shp_item[I_SHELL] = shells;
297 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
299 stopping |= shp_check_one_mines(mlp);
307 shp_check_one_mines(struct ulist *mlp)
312 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
313 if (sect.sct_type != SCT_WATER)
317 if (chance(DMINE_HITCHANCE(sect.sct_mines))) {
318 actor = mlp->unit.ship.shp_own;
319 shp_hit_mine(&mlp->unit.ship);
321 if (map_set(actor, sect.sct_x, sect.sct_y, 'X', 0))
324 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
325 if (!mlp->unit.ship.shp_own) {
326 emp_remque(&mlp->queue);
335 shp_check_mines(struct emp_qelem *ship_list)
337 struct emp_qelem *qp;
338 struct emp_qelem *next;
341 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
343 stopping |= shp_check_one_mines((struct ulist *)qp);
349 * Return whether and why @sp would be stuck in @sectp.
352 shp_check_nav(struct shpstr *sp, struct sctstr *sectp)
354 switch (dchr[sectp->sct_type].d_nav) {
358 if (!(mchr[sp->shp_type].m_flags & M_CANAL)) {
359 return SHP_STUCK_CANAL;
363 if (sectp->sct_effic < 2)
364 return SHP_STUCK_CONSTRUCTION;
367 if (sectp->sct_effic < 60)
368 return SHP_STUCK_CONSTRUCTION;
374 return SHP_STUCK_IMPASSABLE;
376 return SHP_STUCK_NOT;
380 sect_has_dock(struct sctstr *sect)
382 switch (dchr[sect->sct_type].d_nav) {
392 shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
395 struct emp_qelem *qp;
396 struct emp_qelem *next;
400 for (qp = list->q_back; qp != list; qp = next) {
402 mlp = (struct ulist *)qp;
403 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
406 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
409 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
417 shp_damage_one(struct ulist *mlp, int dam)
419 /* ship might have changed (launched interceptors, missile defense) */
420 getship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
421 shipdamage(&mlp->unit.ship, dam);
422 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
423 if (!mlp->unit.ship.shp_own) {
424 emp_remque(&mlp->queue);
430 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
431 int nowantflags, int x, int y)
433 struct emp_qelem *qp;
434 struct emp_qelem *next;
440 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
442 dam = ldround((double)totdam / count, 1);
443 for (qp = list->q_back; qp != list; qp = next) {
445 mlp = (struct ulist *)qp;
446 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
449 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
452 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
454 shp_damage_one(mlp, dam);
460 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
463 struct emp_qelem *qp;
464 struct emp_qelem *next;
467 for (qp = list->q_back; qp != list; qp = next) {
469 mlp = (struct ulist *)qp;
470 /* If the ship isn't in the requested sector, then continue */
471 if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
474 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
477 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
484 static struct ulist *
485 most_valuable_ship(struct emp_qelem *list, coord x, coord y)
487 struct emp_qelem *qp;
488 struct emp_qelem *next;
490 struct ulist *mvs = NULL;
492 for (qp = list->q_back; qp != list; qp = next) {
494 mlp = (struct ulist *)qp;
495 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
497 if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
499 if (!mchr[mlp->unit.ship.shp_type].m_nxlight &&
500 !mchr[mlp->unit.ship.shp_type].m_nchoppers &&
501 mchr[mlp->unit.ship.shp_type].m_cost < 1000 &&
502 !mchr[mlp->unit.ship.shp_type].m_nplanes &&
503 !mchr[mlp->unit.ship.shp_type].m_nland)
509 if (mchr[mlp->unit.ship.shp_type].m_cost * mlp->unit.ship.shp_effic >
510 mchr[mvs->unit.ship.shp_type].m_cost * mvs->unit.ship.shp_effic)
517 shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
519 struct emp_qelem *qp;
520 struct emp_qelem *next;
523 int easiest = 9876; /* things start great for victim */
526 for (qp = list->q_back; qp != list; qp = next) {
528 mlp = (struct ulist *)qp;
530 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
533 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
535 hard = shp_hardtarget(&mlp->unit.ship);
537 easiest = hard; /* things get worse for victim */
540 return easiest - count;
544 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
549 struct emp_qelem msl_list, *qp, *newqp;
553 mvs = most_valuable_ship(list, newx, newy);
557 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
559 for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
561 plp = (struct plist *)qp;
563 if (mvs && mission_pln_equip(plp, NULL, 'p') >= 0) {
564 if (msl_launch(&plp->plane, EF_SHIP, prship(&mvs->unit.ship),
565 newx, newy, victim, &sublaunch) < 0)
568 if (msl_hit(&plp->plane,
569 shp_hardtarget(&mvs->unit.ship), EF_SHIP,
570 N_SHP_MISS, N_SHP_SMISS, sublaunch, victim)) {
571 dam = pln_damage(&plp->plane, 'p', "");
573 "missile interdiction mission does %d damage to %s!\n",
574 dam, prship(&mvs->unit.ship));
575 shp_damage_one(mvs, dam);
577 dam = pln_damage(&plp->plane, 'p', NULL);
578 collateral_damage(newx, newy, dam);
580 mvs = most_valuable_ship(list, newx, newy);
582 plp->plane.pln_effic = 0;
583 putplane(plp->plane.pln_uid, &plp->plane);
592 /* Note that this function has a side effect - it uses coastwatch
593 * ranges to see if it should fire upon a ship. So, this function
594 * is expected to return positive if a ship is in range, and 0 if a
595 * ship is not in range. */
597 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
599 struct emp_qelem *qp;
600 struct emp_qelem *next;
605 natp = getnatp(sectp->sct_own);
607 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
608 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
616 for (qp = list->q_back; qp != list; qp = next) {
618 mlp = (struct ulist *)qp;
619 if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
621 if (natp->nat_flags & NF_COASTWATCH)
622 wu(0, sectp->sct_own,
623 "%s %s sighted at %s\n",
624 cname(mlp->unit.ship.shp_own),
625 prship(&mlp->unit.ship),
626 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
629 setcont(sectp->sct_own, mlp->unit.ship.shp_own, FOUND_COAST);
636 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
645 signed char notified[MAXNOC];
648 /* Inform neutral and worse */
649 for (i = 0; i < MAXNOC; ++i) {
650 if (relations_with(i, victim) <= NEUTRAL)
656 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
657 while (nxtsct(&ns, &fsect)) {
660 if (fsect.sct_own == victim)
662 if (notified[fsect.sct_own])
664 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
665 if (notify_coastguard(list, trange, &fsect))
666 notified[fsect.sct_own] = 1;
668 if (opt_NO_FORT_FIRE)
669 return 0; /* Only coastwatch notify in nofortfire */
670 /* Only fire at Hostile ships */
671 for (i = 0; i < MAXNOC; ++i) {
672 if (relations_with(i, victim) >= NEUTRAL)
675 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
676 while (nxtsct(&ns, &fsect)) {
677 if (!notified[fsect.sct_own])
679 range = roundrange(fortrange(&fsect));
680 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
683 dam = fort_fire(&fsect);
689 mpr(victim, "Incoming fire does %d damage!\n", dam);
691 mpr(victim, "%s fires at you for %d!\n",
692 xyas(fsect.sct_x, fsect.sct_y, victim), dam);
695 "%s fires at %s ships in %s for %d!\n",
696 xyas(fsect.sct_x, fsect.sct_y,
698 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
699 nreport(fsect.sct_own, N_SHP_SHELL, victim, 1);
702 shp_damage(list, totdam, 0, M_SUB, newx, newy);
707 shp_mission_interdiction(struct emp_qelem *list, coord x, coord y,
708 natid victim, int subs)
710 char *what = subs ? "subs" : "ships";
711 int wantflags = subs ? M_SUB : 0;
712 int nowantflags = subs ? 0 : M_SUB;
713 int mission = subs ? MI_SINTERDICT : MI_INTERDICT;
716 dam = unit_interdict(x, y, victim, what,
717 shp_easiest_target(list, wantflags, nowantflags),
720 shp_damage(list, dam, wantflags, nowantflags, x, y);
725 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
729 if (shp_contains(list, newx, newy, 0, M_SUB)) {
730 stopping |= shp_fort_interdiction(list, newx, newy, victim);
732 if (shp_contains(list, newx, newy, 0, M_SUB)) {
733 stopping |= shp_mission_interdiction(list, newx, newy, victim, 0);
734 stopping |= shp_missile_interdiction(list, newx, newy, victim);
737 if (shp_contains(list, newx, newy, M_SUB, 0))
738 stopping |= shp_mission_interdiction(list, newx, newy, victim, 1);
742 /* high value of hardtarget is harder to hit */
744 shp_hardtarget(struct shpstr *sp)
748 struct mchrstr *mcp = mchr + sp->shp_type;
751 getsect(sp->shp_x, sp->shp_y, §);
752 onsea = sect.sct_type == SCT_WATER;
753 if (mcp->m_flags & M_SUB)
755 return (int)((sp->shp_effic / 100.0) *
756 (20 + shp_speed(sp) * onsea / 2.0 - vis));
760 shp_hit_mine(struct shpstr *sp)
764 mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n",
765 xyas(sp->shp_x, sp->shp_y, sp->shp_own));
767 nreport(sp->shp_own, N_HIT_MINE, 0, 1);
770 if (mchr[sp->shp_type].m_flags & M_SWEEP)
773 shipdamage(sp, ldround(m, 1));
779 shp_nav_dir(struct emp_qelem *list, int dir, natid actor)
782 struct emp_qelem *qp;
783 struct emp_qelem *next;
790 enum shp_stuck stuck;
793 if (CANT_HAPPEN(QEMPTY(list)))
796 if (dir <= DIR_STOP || dir > DIR_LAST) {
797 CANT_HAPPEN(dir != DIR_STOP);
798 shp_nav_put(list, actor);
804 mlp = (struct ulist *)list->q_back;
805 newx = xnorm(mlp->unit.ship.shp_x + dx);
806 newy = ynorm(mlp->unit.ship.shp_y + dy);
807 getsect(newx, newy, §);
809 if (sect.sct_own && relations_with(sect.sct_own, actor) < FRIENDLY) {
810 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
815 for (qp = list->q_back; qp != list; qp = next) {
817 mlp = (struct ulist *)qp;
818 switch (shp_check_nav(&mlp->unit.ship, §)) {
822 case SHP_STUCK_CANAL:
827 case SHP_STUCK_CONSTRUCTION:
828 case SHP_STUCK_IMPASSABLE:
829 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
834 mpr(actor, "is too large to fit into the canal system at %s\n",
835 xyas(newx, newy, actor));
839 for (qp = list->q_back; qp != list; qp = next) {
841 mlp = (struct ulist *)qp;
842 stuck = shp_check_nav(&mlp->unit.ship, §);
843 if (stuck == SHP_STUCK_CANAL) {
845 "%s is too large to fit into the canal system at %s"
847 prship(&mlp->unit.ship), xyas(newx, newy, actor),
848 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, actor));
849 shp_nav_put_one(mlp);
851 } else if (CANT_HAPPEN(stuck != SHP_STUCK_NOT)) {
852 mpr(actor, "%s can't go to %s & stays in %s\n",
853 prship(&mlp->unit.ship), xyas(newx, newy, actor),
854 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, actor));
855 shp_nav_put_one(mlp);
859 if (mlp->mobil <= 0.0) {
860 mpr(actor, "%s is out of mobility & stays in %s\n",
861 prship(&mlp->unit.ship),
862 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, actor));
863 shp_nav_put_one(mlp);
866 mobcost = shp_mobcost(&mlp->unit.ship);
867 mlp->unit.ship.shp_x = newx;
868 mlp->unit.ship.shp_y = newy;
869 if (mlp->mobil - mobcost < -127) {
872 mlp->mobil -= mobcost;
874 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
875 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
882 shp_nav_gauntlet(struct emp_qelem *list, int interdict, natid actor)
884 struct ulist *mlp = (struct ulist *)list->q_back;
888 if (CANT_HAPPEN(QEMPTY(list)))
890 newx = mlp->unit.ship.shp_x;
891 newy = mlp->unit.ship.shp_y;
892 stopping = shp_sweep(list, 0, 0, actor);
895 stopping |= shp_check_mines(list);
899 stopping |= shp_interdict(list, newx, newy, actor);
906 * Check for incoming missiles with a P_MAR flag.
907 * Return True=1 if the missile was shotdown.
910 * Chad Zabel, July 95
914 shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
919 double gun, eff, teff;
921 snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
923 while (nxtitem(&ni, &ship)) {
927 if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE))
930 if (relations_with(ship.shp_own, bombown) >= NEUTRAL)
933 if (ship.shp_effic < 60)
936 if (ship.shp_item[I_MILIT] < 1) /* do we have mil? */
938 if (ship.shp_item[I_GUN] < 1) /* we need at least 1 gun */
940 if (!shp_supply(&ship, I_SHELL, 2))
942 ship.shp_item[I_SHELL] -= 2;
943 putship(ship.shp_uid, &ship);
945 /* now calculate the odds */
946 gun = shp_usable_guns(&ship);
947 eff = ship.shp_effic / 100.0;
948 teff = ship.shp_tech / (ship.shp_tech + 200.0);
949 /* raise 4.5 for better interception -KHS */
950 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
951 hitchance = LIMIT_TO(hitchance, 0, 100);
952 hit = pct_chance(hitchance);
954 mpr(bombown, "%s anti-missile system activated...%s\n",
956 hit ? "KABOOOM!! Missile destroyed\n"
957 : "SWOOSH!! anti-missile system failed!!");
958 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
960 mpr(ship.shp_own, "%d%% hitchance...%s\n", hitchance,
961 hit ? "KABOOOM!! Incoming missile destroyed!\n"
962 : "SWOOSH!! Missile evades anti-missile systems\n");
967 return 0; /* all attempts failed */
971 /* Fire missiles at a ship which has fired shells */
973 shp_missdef(struct shpstr *sp, natid victim)
975 struct emp_qelem list;
981 mlp = shp_insque(sp, &list);
982 sprintf(buf, "%s", prship(&mlp->unit.ship));
985 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
986 getship(sp->shp_uid, sp);
990 "missiles launched in defense did 100%% damage to %s\n",
992 wu(0, victim, "%s sunk!\n", buf);
993 } else if (eff > 0 && sp->shp_effic < eff) {
995 "missiles launched in defense did %d%% damage to %s\n",
996 100 * (eff - sp->shp_effic) / eff, buf);
1003 shp_mobcost(struct shpstr *sp)
1005 return speed_factor(sp->shp_effic * 0.01 * shp_speed(sp),
1010 * Set @sp's tech to @tlev along with everything else that depends on it.
1013 shp_set_tech(struct shpstr *sp, int tlev)
1015 struct mchrstr *mcp = mchr + sp->shp_type;
1017 if (CANT_HAPPEN(tlev < mcp->m_tech))
1020 sp->shp_tech = tlev;