2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2015, 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
50 #include "prototypes.h"
56 static void shp_nav_put_one(struct ulist *);
57 static int shp_check_one_mines(struct ulist *);
58 static int shp_hit_mine(struct shpstr *);
59 static void shp_stays(natid, char *, struct ulist *);
62 shp_find_capable(struct emp_qelem *list, int flags)
67 for (qp = list->q_back; qp != list; qp = qp->q_back) {
68 mlp = (struct ulist *)qp;
69 if (mchr[mlp->unit.ship.shp_type].m_flags & flags)
76 shp_may_nav(struct shpstr *sp, struct shpstr *flg, char *suffix)
80 if (!sp->shp_own || !getsect(sp->shp_x, sp->shp_y, §)) {
85 if (sp->shp_item[I_MILIT] == 0 && sp->shp_item[I_CIVIL] == 0) {
86 mpr(sp->shp_own, "%s is crewless%s\n", prship(sp), suffix);
90 switch (shp_check_nav(sp, §)) {
93 case SHP_STUCK_CONSTRUCTION:
94 mpr(sp->shp_own, "%s is caught in a construction zone%s\n",
100 case SHP_STUCK_CANAL:
101 case SHP_STUCK_IMPASSABLE:
102 mpr(sp->shp_own, "%s is landlocked%s\n", prship(sp), suffix);
106 if (flg && (sp->shp_x != flg->shp_x || sp->shp_y != flg->shp_y)) {
107 mpr(sp->shp_own, "%s is not with the flagship%s\n",
115 shp_sel(struct nstr_item *ni, struct emp_qelem *list)
120 while (nxtitem(ni, &ship)) {
122 * It would be nice to let deities navigate foreign ships, but
123 * much of the code assumes that only the ship's owner can
126 if (!ship.shp_own || ship.shp_own != player->cnum)
129 if (ontradingblock(EF_SHIP, &ship)) {
130 pr("ship #%d inelligible - it's for sale.\n",
135 ship.shp_mission = 0;
137 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
138 putship(ship.shp_uid, &ship);
139 shp_insque(&ship, list);
145 * Return the new list link.
148 shp_insque(struct shpstr *sp, struct emp_qelem *list)
150 struct ulist *mlp = malloc(sizeof(struct ulist));
152 mlp->unit.ship = *sp;
153 mlp->mobil = sp->shp_mobil;
154 emp_insque(&mlp->queue, list);
158 /* This function assumes that the list was created by shp_sel */
160 shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
163 struct emp_qelem *qp;
164 struct emp_qelem *next;
166 struct shpstr *sp, *flg = NULL;
171 for (qp = list->q_back; qp != list; qp = next) {
173 mlp = (struct ulist *)qp;
174 sp = &mlp->unit.ship;
175 getship(sp->shp_uid, sp);
177 if (sp->shp_own != actor) {
178 mpr(actor, "%s was sunk at %s\n",
179 prship(sp), xyas(sp->shp_x, sp->shp_y, actor));
180 emp_remque(&mlp->queue);
185 snprintf(and_stays, sizeof(and_stays), " & stays in %s",
186 xyas(sp->shp_x, sp->shp_y, actor));
187 if (!shp_may_nav(sp, flg, and_stays)) {
188 shp_nav_put_one(mlp);
194 if (sp->shp_mobil + 1 < (int)mlp->mobil) {
195 mlp->mobil = sp->shp_mobil;
197 if (mlp->mobil < *minmobp)
198 *minmobp = mlp->mobil;
199 if (mlp->mobil > *maxmobp)
200 *maxmobp = mlp->mobil;
205 shp_nav_put(struct emp_qelem *list, natid actor)
207 struct emp_qelem *qp, *next;
211 for (qp = list->q_back; qp != list; qp = next) {
213 mlp = (struct ulist *)qp;
214 sp = &mlp->unit.ship;
215 mpr(actor, "%s stopped at %s\n",
216 prship(sp), xyas(sp->shp_x, sp->shp_y, actor));
217 shp_nav_put_one(mlp);
222 shp_nav_put_one(struct ulist *mlp)
224 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
225 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
226 emp_remque(&mlp->queue);
231 * Sweep seamines with engineers in SHIP_LIST for ACTOR.
232 * All ships in SHIP_LIST must be in the same sector.
233 * If EXPLICIT is non-zero, this is for an explicit sweep command from
234 * a player. Else it's an automatic "on the move" sweep.
235 * If TAKEMOB is non-zero, require and charge mobility.
236 * Return non-zero when the ships should stop.
239 shp_sweep(struct emp_qelem *ship_list, int explicit, int takemob,
242 struct emp_qelem *qp;
243 struct emp_qelem *next;
246 int mines, m, max, shells;
248 int stopping = 0, first = 1;
250 mlp = shp_find_capable(ship_list, M_SWEEP);
253 mpr(actor, "No minesweepers!\n");
257 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
258 if (sect.sct_type != SCT_WATER) {
260 mpr(actor, "%s is a %s. No seamines there!\n",
261 xyas(sect.sct_x, sect.sct_y, actor),
262 dchr[sect.sct_type].d_name);
266 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
268 mlp = (struct ulist *)qp;
269 if (!(mchr[mlp->unit.ship.shp_type].m_flags & M_SWEEP))
272 if (mlp->mobil <= 0.0) {
274 mpr(actor, "%s is out of mobility!\n",
275 prship(&mlp->unit.ship));
278 mlp->mobil -= shp_mobcost(&mlp->unit.ship);
279 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
281 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
282 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
283 if (!(mines = sect.sct_mines))
285 max = mchr[mlp->unit.ship.shp_type].m_item[I_SHELL];
286 shells = mlp->unit.ship.shp_item[I_SHELL];
287 for (m = 0; mines > 0 && m < 5; m++) {
290 mpr(actor, "Approaching minefield at %s...\n",
291 xyas(sect.sct_x, sect.sct_y, actor));
294 mpr(actor, "Sweep...\n");
296 shells = MIN(max, shells + 1);
297 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
300 sect.sct_mines = mines;
301 mlp->unit.ship.shp_item[I_SHELL] = shells;
302 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
304 if (shp_check_one_mines(mlp)) {
316 shp_check_one_mines(struct ulist *mlp)
321 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
322 if (sect.sct_type != SCT_WATER)
326 if (chance(DMINE_HITCHANCE(sect.sct_mines))) {
327 actor = mlp->unit.ship.shp_own;
328 shp_hit_mine(&mlp->unit.ship);
330 if (map_set(actor, sect.sct_x, sect.sct_y, 'X', 0))
333 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
334 if (!mlp->unit.ship.shp_own)
341 shp_check_mines(struct emp_qelem *ship_list)
343 struct emp_qelem *qp;
344 struct emp_qelem *next;
348 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
350 mlp = (struct ulist *)qp;
351 if (shp_check_one_mines(mlp)) {
362 shp_stays(natid actor, char *str, struct ulist *mlp)
364 mpr(actor, "%s %s & stays in %s\n",
365 prship(&mlp->unit.ship), str,
366 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, actor));
367 shp_nav_put_one(mlp);
371 * Return whether and why SP would be stuck in SECTP.
374 shp_check_nav(struct shpstr *sp, struct sctstr *sectp)
376 switch (dchr[sectp->sct_type].d_nav) {
380 if (!(mchr[sp->shp_type].m_flags & M_CANAL)) {
381 return SHP_STUCK_CANAL;
385 if (sectp->sct_effic < 2)
386 return SHP_STUCK_CONSTRUCTION;
389 if (sectp->sct_effic < 60)
390 return SHP_STUCK_CONSTRUCTION;
396 return SHP_STUCK_IMPASSABLE;
398 return SHP_STUCK_NOT;
402 sect_has_dock(struct sctstr *sect)
404 switch (dchr[sect->sct_type].d_nav) {
414 shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
417 struct emp_qelem *qp;
418 struct emp_qelem *next;
422 for (qp = list->q_back; qp != list; qp = next) {
424 mlp = (struct ulist *)qp;
425 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
428 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
431 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
439 shp_damage_one(struct ulist *mlp, int dam)
441 /* ship might have changed (launched interceptors, missile defense) */
442 getship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
443 shipdamage(&mlp->unit.ship, dam);
444 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
445 if (!mlp->unit.ship.shp_own) {
446 emp_remque(&mlp->queue);
452 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
453 int nowantflags, int x, int y)
455 struct emp_qelem *qp;
456 struct emp_qelem *next;
462 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
464 dam = ldround((double)totdam / count, 1);
465 for (qp = list->q_back; qp != list; qp = next) {
467 mlp = (struct ulist *)qp;
468 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
471 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
474 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
476 shp_damage_one(mlp, dam);
482 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
485 struct emp_qelem *qp;
486 struct emp_qelem *next;
489 for (qp = list->q_back; qp != list; qp = next) {
491 mlp = (struct ulist *)qp;
492 /* If the ship isn't in the requested sector, then continue */
493 if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
496 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
499 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
506 static struct ulist *
507 most_valuable_ship(struct emp_qelem *list, coord x, coord y)
509 struct emp_qelem *qp;
510 struct emp_qelem *next;
512 struct ulist *mvs = NULL;
514 for (qp = list->q_back; qp != list; qp = next) {
516 mlp = (struct ulist *)qp;
517 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
519 if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
521 if (!mchr[mlp->unit.ship.shp_type].m_nxlight &&
522 !mchr[mlp->unit.ship.shp_type].m_nchoppers &&
523 mchr[mlp->unit.ship.shp_type].m_cost < 1000 &&
524 !mchr[mlp->unit.ship.shp_type].m_nplanes &&
525 !mchr[mlp->unit.ship.shp_type].m_nland)
531 if (mchr[mlp->unit.ship.shp_type].m_cost * mlp->unit.ship.shp_effic >
532 mchr[mvs->unit.ship.shp_type].m_cost * mvs->unit.ship.shp_effic)
539 shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
541 struct emp_qelem *qp;
542 struct emp_qelem *next;
545 int easiest = 9876; /* things start great for victim */
548 for (qp = list->q_back; qp != list; qp = next) {
550 mlp = (struct ulist *)qp;
552 (mchr[mlp->unit.ship.shp_type].m_flags & wantflags) != wantflags)
555 mchr[mlp->unit.ship.shp_type].m_flags & nowantflags)
557 hard = shp_hardtarget(&mlp->unit.ship);
559 easiest = hard; /* things get worse for victim */
562 return easiest - count;
566 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
571 struct emp_qelem msl_list, *qp, *newqp;
575 mvs = most_valuable_ship(list, newx, newy);
579 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
581 for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
583 plp = (struct plist *)qp;
585 if (mvs && mission_pln_equip(plp, NULL, 'p') >= 0) {
586 if (msl_launch(&plp->plane, EF_SHIP, prship(&mvs->unit.ship),
587 newx, newy, victim, &sublaunch) < 0)
590 if (msl_hit(&plp->plane,
591 shp_hardtarget(&mvs->unit.ship), EF_SHIP,
592 N_SHP_MISS, N_SHP_SMISS, sublaunch, victim)) {
593 dam = pln_damage(&plp->plane, 'p', 1);
595 "missile interdiction mission does %d damage to %s!\n",
596 dam, prship(&mvs->unit.ship));
597 shp_damage_one(mvs, dam);
599 dam = pln_damage(&plp->plane, 'p', 0);
600 collateral_damage(newx, newy, dam);
602 mvs = most_valuable_ship(list, newx, newy);
604 plp->plane.pln_effic = 0;
605 putplane(plp->plane.pln_uid, &plp->plane);
614 /* Note that this function has a side effect - it uses coastwatch
615 * ranges to see if it should fire upon a ship. So, this function
616 * is expected to return positive if a ship is in range, and 0 if a
617 * ship is not in range. */
619 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
621 struct emp_qelem *qp;
622 struct emp_qelem *next;
627 natp = getnatp(sectp->sct_own);
629 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
630 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
638 for (qp = list->q_back; qp != list; qp = next) {
640 mlp = (struct ulist *)qp;
641 if (mchr[mlp->unit.ship.shp_type].m_flags & M_SUB)
643 if (natp->nat_flags & NF_COASTWATCH)
644 wu(0, sectp->sct_own,
645 "%s %s sighted at %s\n",
646 cname(mlp->unit.ship.shp_own),
647 prship(&mlp->unit.ship),
648 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
651 setcont(sectp->sct_own, mlp->unit.ship.shp_own, FOUND_COAST);
658 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
667 signed char notified[MAXNOC];
670 /* Inform neutral and worse */
671 for (i = 0; i < MAXNOC; ++i) {
672 if (relations_with(i, victim) <= NEUTRAL)
678 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
679 while (nxtsct(&ns, &fsect)) {
682 if (fsect.sct_own == victim)
684 if (notified[fsect.sct_own])
686 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
687 if (notify_coastguard(list, trange, &fsect))
688 notified[fsect.sct_own] = 1;
690 if (opt_NO_FORT_FIRE)
691 return 0; /* Only coastwatch notify in nofortfire */
692 /* Only fire at Hostile ships */
693 for (i = 0; i < MAXNOC; ++i) {
694 if (relations_with(i, victim) >= NEUTRAL)
697 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
698 while (nxtsct(&ns, &fsect)) {
699 if (!notified[fsect.sct_own])
701 range = roundrange(fortrange(&fsect));
702 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
705 dam = fort_fire(&fsect);
711 mpr(victim, "Incoming fire does %d damage!\n", dam);
713 mpr(victim, "%s fires at you for %d!\n",
714 xyas(fsect.sct_x, fsect.sct_y, victim), dam);
717 "%s fires at %s ships in %s for %d!\n",
718 xyas(fsect.sct_x, fsect.sct_y,
720 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
721 nreport(fsect.sct_own, N_SHP_SHELL, victim, 1);
724 shp_damage(list, totdam, 0, M_SUB, newx, newy);
729 shp_mission_interdiction(struct emp_qelem *list, coord x, coord y,
730 natid victim, int subs)
732 char *what = subs ? "subs" : "ships";
733 int wantflags = subs ? M_SUB : 0;
734 int nowantflags = subs ? 0 : M_SUB;
735 int mission = subs ? MI_SINTERDICT : MI_INTERDICT;
738 dam = unit_interdict(x, y, victim, what,
739 shp_easiest_target(list, wantflags, nowantflags),
742 shp_damage(list, dam, wantflags, nowantflags, x, y);
747 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
751 if (shp_contains(list, newx, newy, 0, M_SUB)) {
752 stopping |= shp_fort_interdiction(list, newx, newy, victim);
754 if (shp_contains(list, newx, newy, 0, M_SUB)) {
755 stopping |= shp_mission_interdiction(list, newx, newy, victim, 0);
756 stopping |= shp_missile_interdiction(list, newx, newy, victim);
759 if (shp_contains(list, newx, newy, M_SUB, 0))
760 stopping |= shp_mission_interdiction(list, newx, newy, victim, 1);
764 /* high value of hardtarget is harder to hit */
766 shp_hardtarget(struct shpstr *sp)
770 struct mchrstr *mcp = mchr + sp->shp_type;
773 getsect(sp->shp_x, sp->shp_y, §);
774 onsea = sect.sct_type == SCT_WATER;
775 if (mcp->m_flags & M_SUB)
777 return (int)((sp->shp_effic / 100.0) *
778 (20 + shp_speed(sp) * onsea / 2.0 - vis));
782 shp_hit_mine(struct shpstr *sp)
786 mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n",
787 xyas(sp->shp_x, sp->shp_y, sp->shp_own));
789 nreport(sp->shp_own, N_HIT_MINE, 0, 1);
792 if (mchr[sp->shp_type].m_flags & M_SWEEP)
795 shipdamage(sp, ldround(m, 1));
801 shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor)
804 struct emp_qelem *qp;
805 struct emp_qelem *next;
812 enum shp_stuck stuck;
817 if (CANT_HAPPEN(QEMPTY(list)))
820 if (dir <= DIR_STOP || dir > DIR_LAST) {
821 CANT_HAPPEN(dir != DIR_STOP);
822 shp_nav_put(list, actor);
828 mlp = (struct ulist *)list->q_back;
829 newx = xnorm(mlp->unit.ship.shp_x + dx);
830 newy = ynorm(mlp->unit.ship.shp_y + dy);
831 getsect(newx, newy, §);
833 if (sect.sct_own && relations_with(sect.sct_own, actor) < FRIENDLY) {
834 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
839 for (qp = list->q_back; qp != list; qp = next) {
841 mlp = (struct ulist *)qp;
842 switch (shp_check_nav(&mlp->unit.ship, §)) {
846 case SHP_STUCK_CANAL:
851 case SHP_STUCK_CONSTRUCTION:
852 case SHP_STUCK_IMPASSABLE:
853 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
858 mpr(actor, "is too large to fit into the canal system at %s\n",
859 xyas(newx, newy, actor));
863 for (qp = list->q_back; qp != list; qp = next) {
865 mlp = (struct ulist *)qp;
866 stuck = shp_check_nav(&mlp->unit.ship, §);
867 if (stuck == SHP_STUCK_CANAL) {
869 "is too large to fit into the canal system at %s",
870 xyas(newx, newy, actor));
871 shp_stays(actor, dp, mlp);
873 } else if (CANT_HAPPEN(stuck != SHP_STUCK_NOT)) {
874 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
875 shp_stays(actor, dp, mlp);
879 if (mlp->mobil <= 0.0) {
880 shp_stays(actor, "is out of mobility", mlp);
883 mobcost = shp_mobcost(&mlp->unit.ship);
884 mlp->unit.ship.shp_x = newx;
885 mlp->unit.ship.shp_y = newy;
886 if (mlp->mobil - mobcost < -127) {
889 mlp->mobil -= mobcost;
891 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
892 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
894 /* Now update the map for this ship */
895 rad_map_set(mlp->unit.ship.shp_own,
896 mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
897 mlp->unit.ship.shp_effic, mlp->unit.ship.shp_tech,
898 mchr[mlp->unit.ship.shp_type].m_vrnge);
902 stopping |= shp_sweep(list, 0, 0, actor);
905 stopping |= shp_check_mines(list);
908 stopping |= shp_interdict(list, newx, newy, actor);
915 * Check for incoming missiles with a P_MAR flag.
916 * Return True=1 if the missile was shotdown.
919 * Chad Zabel, July 95
923 shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
928 double gun, eff, teff;
930 snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
932 while (nxtitem(&ni, &ship)) {
936 if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE))
939 if (relations_with(ship.shp_own, bombown) >= NEUTRAL)
942 if (ship.shp_effic < 60)
945 if (ship.shp_item[I_MILIT] < 1) /* do we have mil? */
947 if (ship.shp_item[I_GUN] < 1) /* we need at least 1 gun */
949 if (!shp_supply(&ship, I_SHELL, 2))
951 ship.shp_item[I_SHELL] -= 2;
952 putship(ship.shp_uid, &ship);
954 /* now calculate the odds */
955 gun = shp_usable_guns(&ship);
956 eff = ship.shp_effic / 100.0;
957 teff = ship.shp_tech / (ship.shp_tech + 200.0);
958 /* raise 4.5 for better interception -KHS */
959 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
960 hitchance = LIMIT_TO(hitchance, 0, 100);
961 hit = pct_chance(hitchance);
963 mpr(bombown, "%s anti-missile system activated...%s\n",
965 hit ? "KABOOOM!! Missile destroyed\n"
966 : "SWOOSH!! anti-missile system failed!!");
967 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
969 mpr(ship.shp_own, "%d%% hitchance...%s\n", hitchance,
970 hit ? "KABOOOM!! Incoming missile destroyed!\n"
971 : "SWOOSH!! Missile evades anti-missile systems\n");
976 return 0; /* all attempts failed */
980 /* Fire missiles at a ship which has fired shells */
982 shp_missdef(struct shpstr *sp, natid victim)
984 struct emp_qelem list;
990 mlp = shp_insque(sp, &list);
991 sprintf(buf, "%s", prship(&mlp->unit.ship));
994 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
995 getship(sp->shp_uid, sp);
999 "missiles launched in defense did 100%% damage to %s\n",
1001 wu(0, victim, "%s sunk!\n", buf);
1002 } else if (eff > 0 && sp->shp_effic < eff) {
1004 "missiles launched in defense did %d%% damage to %s\n",
1005 100 * (eff - sp->shp_effic) / eff, buf);
1012 shp_mobcost(struct shpstr *sp)
1014 return speed_factor(sp->shp_effic * 0.01 * shp_speed(sp),
1019 * Set SP's tech to TLEV along with everything else that depends on it.
1022 shp_set_tech(struct shpstr *sp, int tlev)
1024 struct mchrstr *mcp = mchr + sp->shp_type;
1026 if (CANT_HAPPEN(tlev < mcp->m_tech))
1029 sp->shp_tech = tlev;