2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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
33 * Markus Armbruster, 2006
54 #include "prototypes.h"
61 static int shp_check_one_mines(struct mlist *);
62 static int shp_hit_mine(struct shpstr *, struct mchrstr *);
63 static void shp_mess(char *, struct mlist *);
66 shp_sel(struct nstr_item *ni, struct emp_qelem *list)
78 while (nxtitem(ni, &ship)) {
81 mcp = &mchr[(int)ship.shp_type];
82 /* if (wantflags && (mcp->m_flags & wantflags) != wantflags)
84 if (nowantflags && mcp->m_flags & nowantflags)
88 if (ontradingblock(EF_SHIP, &ship)) {
89 pr("ship #%d inelligible - it's for sale.\n",
94 /* This abuse is better fixed by building a ship with the normal negative
95 mobility that everything else is built with */
98 if (ship.shp_effic < 21 &&
99 ship.shp_mobil < etu_per_update) {
100 pr("%s needs at least %d mob to navigate.\n",
101 prship(&ship), etu_per_update);
106 ship.shp_mission = 0;
108 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
109 putship(ship.shp_uid, &ship);
110 mlp = malloc(sizeof(struct mlist));
113 mlp->mobil = ship.shp_mobil;
114 emp_insque(&mlp->queue, list);
118 /* This function assumes that the list was created by shp_sel */
120 shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
121 int *togetherp, natid actor)
123 struct emp_qelem *qp;
124 struct emp_qelem *next;
135 for (qp = list->q_back; qp != list; qp = next) {
137 mlp = (struct mlist *)qp;
138 getship(mlp->ship.shp_uid, &ship);
139 if (ship.shp_own != actor) {
140 mpr(actor, "%s was sunk at %s\n",
141 prship(&ship), xyas(ship.shp_x, ship.shp_y, actor));
142 emp_remque((struct emp_qelem *)mlp);
147 if (*ship.shp_path && !update_pending) {
148 shp_mess("has a sail path", mlp);
149 mpr(actor, "Use `sail <#> -' to reset\n");
153 /* check crew - uws don't count */
154 if (ship.shp_item[I_MILIT] == 0 && ship.shp_item[I_CIVIL] == 0) {
155 shp_mess("is crewless", mlp);
158 if (!getsect(ship.shp_x, ship.shp_y, §)) {
159 shp_mess("was sucked into the sky by a strange looking spaceship", mlp); /* heh -KHS */
162 switch (shp_check_nav(§, &ship)) {
163 case CN_CONSTRUCTION:
164 shp_mess("is caught in a construction zone", mlp);
167 shp_mess("is landlocked", mlp);
173 shp_mess("was just swallowed by a big green worm", mlp);
181 if (ship.shp_x != allx || ship.shp_y != ally)
183 if (ship.shp_mobil + 1 < (int)mlp->mobil) {
184 mlp->mobil = ship.shp_mobil;
186 if (mlp->mobil < *minmobp)
187 *minmobp = mlp->mobil;
188 if (mlp->mobil > *maxmobp)
189 *maxmobp = mlp->mobil;
195 shp_put(struct emp_qelem *list, natid actor)
197 struct emp_qelem *qp;
198 struct emp_qelem *newqp;
203 mlp = (struct mlist *)qp;
204 mpr(actor, "%s stopped at %s\n", prship(&mlp->ship),
205 xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
206 mlp->ship.shp_mobil = (int)mlp->mobil;
207 putship(mlp->ship.shp_uid, &mlp->ship);
216 shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
218 struct emp_qelem *qp;
219 struct emp_qelem *next;
222 int mines, m, max, shells;
226 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
228 mlp = (struct mlist *)qp;
229 if (!(mlp->mcp->m_flags & M_SWEEP)) {
231 mpr(actor, "%s doesn't have minesweeping capability!\n",
235 if (takemob && mlp->mobil <= 0.0) {
237 mpr(actor, "%s is out of mobility!\n", prship(&mlp->ship));
240 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
241 if (sect.sct_type != SCT_WATER) {
243 mpr(actor, "%s is not at sea. No mines there!\n",
248 mlp->mobil -= shp_mobcost(&mlp->ship);
249 mlp->ship.shp_mobil = (int)mlp->mobil;
251 putship(mlp->ship.shp_uid, &mlp->ship);
252 if (!(mines = sect.sct_mines))
254 max = mlp->mcp->m_item[I_SHELL];
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)
285 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
286 if (sect.sct_type != SCT_WATER)
290 if (chance(DMINE_HITCHANCE(sect.sct_mines))) {
291 actor = mlp->ship.shp_own;
292 shp_hit_mine(&mlp->ship, mlp->mcp);
294 if (map_set(actor, sect.sct_x, sect.sct_y, 'X', 0))
297 putship(mlp->ship.shp_uid, &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("%1.1s", &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(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, struct shpstr *shp)
372 switch (dchr[sect->sct_type].d_nav) {
376 if (mchr[(int)shp->shp_type].m_flags & M_CANAL) {
377 if (sect->sct_effic < 2)
378 return CN_CONSTRUCTION;
380 return CN_LANDLOCKED;
383 if (sect->sct_effic < 2)
384 return CN_CONSTRUCTION;
387 if (sect->sct_effic < 60)
388 return CN_CONSTRUCTION;
391 return CN_LANDLOCKED;
397 sect_has_dock(struct sctstr *sect)
399 switch (dchr[sect->sct_type].d_nav) {
408 shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
411 struct emp_qelem *qp;
412 struct emp_qelem *next;
416 for (qp = list->q_back; qp != list; qp = next) {
418 mlp = (struct mlist *)qp;
419 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
421 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
423 if (nowantflags && mlp->mcp->m_flags & nowantflags)
431 shp_damage_one(struct mlist *mlp, int dam)
433 shipdamage(&mlp->ship, dam);
434 putship(mlp->ship.shp_uid, &mlp->ship);
435 if (!mlp->ship.shp_own) {
436 emp_remque((struct emp_qelem *)mlp);
442 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
443 int nowantflags, int x, int y)
445 struct emp_qelem *qp;
446 struct emp_qelem *next;
452 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
454 dam = ldround((double)totdam / count, 1);
455 for (qp = list->q_back; qp != list; qp = next) {
457 mlp = (struct mlist *)qp;
458 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
460 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
462 if (nowantflags && mlp->mcp->m_flags & nowantflags)
464 shp_damage_one(mlp, dam);
470 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
473 struct emp_qelem *qp;
474 struct emp_qelem *next;
477 for (qp = list->q_back; qp != list; qp = next) {
479 mlp = (struct mlist *)qp;
480 /* If the ship isn't in the requested sector, then continue */
481 if (newx != mlp->ship.shp_x || newy != mlp->ship.shp_y)
483 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
485 if (nowantflags && mlp->mcp->m_flags & nowantflags)
492 static struct mlist *
493 most_valuable_ship(struct emp_qelem *list)
495 struct emp_qelem *qp;
496 struct emp_qelem *next;
498 struct mlist *mvs = 0;
500 for (qp = list->q_back; qp != list; qp = next) {
502 mlp = (struct mlist *)qp;
503 if (mlp->mcp->m_flags & M_SUB)
505 if (!mlp->mcp->m_nxlight &&
506 !mlp->mcp->m_nchoppers &&
507 mlp->mcp->m_cost < 1000 &&
508 !mlp->mcp->m_nplanes && !mlp->mcp->m_nland)
514 if (mlp->mcp->m_cost * mlp->ship.shp_effic >
515 mvs->mcp->m_cost * mvs->ship.shp_effic)
522 shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
524 struct emp_qelem *qp;
525 struct emp_qelem *next;
528 int easiest = 9876; /* things start great for victim */
531 for (qp = list->q_back; qp != list; qp = next) {
533 mlp = (struct mlist *)qp;
534 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
536 if (nowantflags && mlp->mcp->m_flags & nowantflags)
538 hard = shp_hardtarget(&mlp->ship);
540 easiest = hard; /* things get worse for victim */
543 return easiest - count;
547 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
553 struct emp_qelem msl_list, *qp, *newqp;
557 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
560 while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
561 sprintf(what, "%s", prship(&mvs->ship));
562 dam = msl_launch_mindam(&msl_list, newx, newy,
563 shp_hardtarget(&mvs->ship),
564 EF_SHIP, 1, what, victim, MI_INTERDICT);
567 "missile interdiction mission does %d damage to %s!\n",
569 shp_damage_one(mvs, dam);
572 } else if (++twotries >= 2) {
576 qp = msl_list.q_forw;
577 while (qp != msl_list.q_forw) {
587 /* Note that this function has a side effect - it uses coastwatch
588 * ranges to see if it should fire upon a ship. So, this function
589 * is expected to return positive if a ship is in range, and 0 if a
590 * ship is not in range. */
592 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
594 struct emp_qelem *qp;
595 struct emp_qelem *next;
600 natp = getnatp(sectp->sct_own);
602 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
603 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
611 for (qp = list->q_back; qp != list; qp = next) {
613 mlp = (struct mlist *)qp;
614 if (mlp->mcp->m_flags & M_SUB)
616 if (natp->nat_flags & NF_COASTWATCH)
617 wu(0, sectp->sct_own,
618 "%s %s sighted at %s\n",
619 cname(mlp->ship.shp_own),
621 xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own));
623 setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_COAST);
630 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
640 signed 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 gun = fsect.sct_item[I_GUN];
677 range = roundrange(fortrange(&fsect));
678 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
681 if (fsect.sct_item[I_MILIT] < 5)
683 shell = fsect.sct_item[I_SHELL];
685 shell += supply_commod(fsect.sct_own, fsect.sct_x, fsect.sct_y,
690 fsect.sct_item[I_SHELL] = shell;
694 guneff = landgun((int)fsect.sct_effic, gun);
697 mpr(victim, "Incoming fire does %d damage!\n", dam);
699 mpr(victim, "%s fires at you for %d!\n",
700 xyas(fsect.sct_x,fsect.sct_y,victim),
704 "%s fires at %s ships in %s for %d!\n",
705 xyas(fsect.sct_x, fsect.sct_y,
707 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
708 nreport(fsect.sct_own, N_SHP_SHELL, victim, 1);
711 return shp_damage(list, totdam, 0, M_SUB, newx, newy);
716 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
720 if (shp_contains(list, newx, newy, 0, M_SUB)) {
721 stopping |= shp_fort_interdiction(list, newx, newy, victim);
723 if (shp_contains(list, newx, newy, 0, M_SUB)) {
726 unit_interdict(newx, newy, victim, "ships",
727 shp_easiest_target(list, 0, M_SUB),
729 0, M_SUB, newx, newy);
730 if (most_valuable_ship(list)) {
732 shp_missile_interdiction(list, newx, newy, victim);
736 if (shp_contains(list, newx, newy, M_SUB, 0)) {
739 unit_interdict(newx, newy, victim, "subs",
740 shp_easiest_target(list, M_SUB, 0),
742 M_SUB, 0, newx, newy);
747 /* high value of hardtarget is harder to hit */
749 shp_hardtarget(struct shpstr *sp)
753 struct mchrstr *mcp = mchr + sp->shp_type;
756 getsect(sp->shp_x, sp->shp_y, §);
757 onsea = sect.sct_type == SCT_WATER;
758 if (mcp->m_flags & M_SUB)
760 return (int)((sp->shp_effic / 100.0) *
761 (20 + sp->shp_speed * onsea / 2.0 - vis));
765 shp_hit_mine(struct shpstr *sp, struct mchrstr *mcp)
769 mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n",
770 xyas(sp->shp_x, sp->shp_y, sp->shp_own));
772 nreport(sp->shp_own, N_HIT_MINE, 0, 1);
775 if (mcp->m_flags & M_SWEEP)
778 shipdamage(sp, ldround(m, 1));
784 shp_view(struct emp_qelem *list)
787 struct emp_qelem *qp;
788 struct emp_qelem *next;
791 for (qp = list->q_back; qp != list; qp = next) {
793 mlp = (struct mlist *)qp;
794 getsect(mlp->ship.shp_x, mlp->ship.shp_y, §);
795 if (mlp->mcp->m_flags & M_FOOD)
796 mpr(mlp->ship.shp_own, "[fert:%d] ", sect.sct_fertil);
797 if (mlp->mcp->m_flags & M_OIL)
798 mpr(mlp->ship.shp_own, "[oil:%d] ", sect.sct_oil);
799 mpr(mlp->ship.shp_own, "%s @ %s %d%% %s\n",
801 xyas(mlp->ship.shp_x, mlp->ship.shp_y, player->cnum),
802 sect.sct_effic, dchr[sect.sct_type].d_name);
807 shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
811 struct emp_qelem *qp;
812 struct emp_qelem *next;
814 struct emp_qelem done;
821 double tech; /* for mapping */
822 double tf; /* for mapping */
826 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
827 shp_put(list, actor);
832 for (qp = list->q_back; qp != list; qp = next) {
834 mlp = (struct mlist *)qp;
835 newx = xnorm(mlp->ship.shp_x + dx);
836 newy = ynorm(mlp->ship.shp_y + dy);
837 getsect(newx, newy, §);
838 navigate = shp_check_nav(§, &mlp->ship);
839 if (navigate != CN_NAVIGABLE ||
840 (sect.sct_own && actor != sect.sct_own &&
841 getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
842 if (dchr[sect.sct_type].d_nav == NAV_CANAL &&
843 !(mlp->mcp->m_flags & M_CANAL) &&
844 navigate == CN_LANDLOCKED)
846 "is too large to fit into the canal system at %s",
847 xyas(newx, newy, actor));
849 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
851 mpr(actor, "%s\n", dp);
859 if (mlp->mobil <= 0.0) {
860 shp_mess("is out of mobility", mlp);
863 mobcost = shp_mobcost(&mlp->ship);
864 mlp->ship.shp_x = newx;
865 mlp->ship.shp_y = newy;
866 if (mlp->mobil - mobcost < -127) {
869 mlp->mobil -= mobcost;
871 mlp->ship.shp_mobil = (int)mlp->mobil;
872 putship(mlp->ship.shp_uid, &mlp->ship);
874 /* Now update the map for this ship */
875 tech = techfact(mlp->ship.shp_tech, 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, 0, actor);
888 stopping |= shp_check_mines(list);
892 /* interdict ships sector by sector */
894 while (!QEMPTY(list)) {
895 mlp = (struct mlist *)list->q_back;
896 newx = mlp->ship.shp_x;
897 newy = mlp->ship.shp_y;
898 stopping |= shp_interdict(list, newx, newy, actor);
899 /* move survivors in this sector to done */
900 for (qp = list->q_back; qp != list; qp = next) {
902 mlp = (struct mlist *)qp;
903 if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy) {
905 emp_insque(qp, &done);
909 /* assign surviving ships back to list */
910 emp_insque(list, &done);
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, &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 = ship.shp_effic / 100.0;
964 teff = ship.shp_tech / (ship.shp_tech + 200.0);
965 /* raise 4.5 for better interception -KHS */
966 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
972 mpr(bombown, "%s anti-missile system activated...",
973 cname(ship.shp_own));
974 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
976 mpr(ship.shp_own, "%d%% hitchance...", hitchance);
978 ship.shp_item[I_SHELL] = shell - 2;
979 putship(ship.shp_uid, &ship);
981 if (roll(100) <= hitchance) {
982 mpr(bombown, "KABOOOM!! Missile destroyed\n\n");
984 "KABOOOM!! Incoming missile destroyed!\n\n");
987 mpr(bombown, "SWOOSH!! anti-missile system failed!!\n");
989 "SWOOSH!! Missile evades anti-missile systems\n\n");
992 return 0; /* all attempts failed */
996 shp_path(int together, struct shpstr *shp, char *buf)
1000 struct sctstr d_sect;
1003 if (!sarg_xy(buf, &destx, &desty))
1007 "Cannot go to a destination sector if not all starting in the same sector\n");
1010 if (!getsect(destx, desty, &d_sect)) {
1011 mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty);
1015 cp = BestShipPath(buf, shp->shp_x, shp->shp_y,
1016 d_sect.sct_x, d_sect.sct_y, player->cnum);
1017 if (!cp || shp->shp_mobil <= 0) {
1018 mpr(shp->shp_own, "Can't get to '%s' right now.\n",
1019 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1025 /* Fire missiles at a ship which has fired shells */
1027 shp_missdef(struct shpstr *sp, natid victim)
1029 struct emp_qelem list;
1036 mlp = malloc(sizeof(struct mlist));
1037 mlp->mcp = &mchr[(int)sp->shp_type];
1039 mlp->mobil = sp->shp_mobil;
1040 emp_insque(&mlp->queue, &list);
1041 sprintf(buf, "%s", prship(&mlp->ship));
1043 eff = sp->shp_effic;
1044 if (most_valuable_ship(&list)) {
1045 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
1046 getship(sp->shp_uid, sp);
1050 "missiles launched in defense did 100%% damage to %s\n",
1052 wu(0, victim, "%s sunk!\n", buf);
1053 } else if (eff > 0 && sp->shp_effic < eff) {
1055 "missiles launched in defense did %d%% damage to %s\n",
1056 100 * (eff - sp->shp_effic) / eff, buf);
1064 shp_mobcost(struct shpstr *sp)
1066 return speed_factor(sp->shp_effic * 0.01 * sp->shp_speed,
1071 * Set SP's tech to TLEV along with everything else that depends on it.
1074 shp_set_tech(struct shpstr *sp, int tlev)
1076 struct mchrstr *mcp = mchr + sp->shp_type;
1077 int tech_diff = tlev - mcp->m_tech;
1079 if (CANT_HAPPEN(tech_diff < 0)) {
1084 sp->shp_tech = tlev;
1085 sp->shp_armor = (short)SHP_DEF(mcp->m_armor, tech_diff);
1086 sp->shp_speed = (short)SHP_SPD(mcp->m_speed, tech_diff);
1087 sp->shp_visib = (short)SHP_VIS(mcp->m_visib, tech_diff);
1088 sp->shp_frnge = (short)SHP_RNG(mcp->m_frnge, tech_diff);
1089 sp->shp_glim = (short)SHP_FIR(mcp->m_glim, tech_diff);