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 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
56 #include "prototypes.h"
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, &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 = 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 struct emp_qelem *qp;
195 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 = mlp->mcp->m_item[I_SHELL];
254 shells = mlp->ship.shp_item[I_SHELL];
255 for (m = 0; mines > 0 && m < 5; m++) {
257 mpr(actor, "Sweep...\n");
259 shells = MIN(max, shells + 1);
260 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
263 sect.sct_mines = mines;
264 mlp->ship.shp_item[I_SHELL] = shells;
265 if (shp_check_one_mines(mlp)) {
270 putship(mlp->ship.shp_uid, &mlp->ship);
279 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 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
298 putship(mlp->ship.shp_uid, &mlp->ship);
299 if (!mlp->ship.shp_own)
306 shp_check_mines(struct emp_qelem *ship_list)
308 struct emp_qelem *qp;
309 struct emp_qelem *next;
313 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
315 mlp = (struct mlist *)qp;
316 if (shp_check_one_mines(mlp)) {
326 shp_list(struct emp_qelem *ship_list)
328 struct emp_qelem *qp;
329 struct emp_qelem *next;
333 pr("shp# ship type x,y fl eff mil sh gun pn he xl ln mob tech\n");
335 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
337 mlp = (struct mlist *)qp;
339 pr("%4d ", shp->shp_uid);
340 pr("%-16.16s ", mlp->mcp->m_name);
341 prxy("%4d,%-4d ", shp->shp_x, shp->shp_y, mlp->ship.shp_own);
342 pr("%c", shp->shp_fleet);
343 pr("%4d%%", shp->shp_effic);
344 pr("%4d", shp->shp_item[I_MILIT]);
345 pr("%4d", shp->shp_item[I_SHELL]);
346 pr("%4d", shp->shp_item[I_GUN]);
348 pr("%3d", shp->shp_nplane);
349 pr("%3d", shp->shp_nchoppers);
350 pr("%3d", shp->shp_nxlight);
352 pr("%3d", shp->shp_nland);
353 pr("%4d", shp->shp_mobil);
354 pr("%4d\n", shp->shp_tech);
359 shp_mess(s_char *str, struct mlist *mlp)
361 mpr(mlp->ship.shp_own, "%s %s & stays in %s\n",
363 str, xyas(mlp->ship.shp_x, mlp->ship.shp_y, mlp->ship.shp_own));
364 mlp->ship.shp_mobil = (int)mlp->mobil;
365 putship(mlp->ship.shp_uid, &mlp->ship);
366 emp_remque((struct emp_qelem *)mlp);
371 shp_check_nav(struct sctstr *sect)
373 switch (dchr[sect->sct_type].d_nav) {
378 if (sect->sct_effic < 2)
379 return CN_CONSTRUCTION;
382 if (sect->sct_effic < 60)
383 return CN_CONSTRUCTION;
386 return CN_LANDLOCKED;
392 sect_has_dock(struct sctstr *sect)
394 switch (dchr[sect->sct_type].d_nav) {
403 shp_count(struct emp_qelem *list, int wantflags, int nowantflags, int x,
406 struct emp_qelem *qp;
407 struct emp_qelem *next;
411 for (qp = list->q_back; qp != list; qp = next) {
413 mlp = (struct mlist *)qp;
414 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
416 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
418 if (nowantflags && mlp->mcp->m_flags & nowantflags)
426 shp_damage_one(struct mlist *mlp, int dam)
428 shipdamage(&mlp->ship, dam);
429 putship(mlp->ship.shp_uid, &mlp->ship);
430 if (!mlp->ship.shp_own) {
431 emp_remque((struct emp_qelem *)mlp);
437 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
438 int nowantflags, int x, int y)
440 struct emp_qelem *qp;
441 struct emp_qelem *next;
447 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
449 dam = ldround(((double)totdam / (double)count), 1);
450 for (qp = list->q_back; qp != list; qp = next) {
452 mlp = (struct mlist *)qp;
453 if (mlp->ship.shp_x != x || mlp->ship.shp_y != y)
455 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
457 if (nowantflags && mlp->mcp->m_flags & nowantflags)
459 shp_damage_one(mlp, dam);
465 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
468 struct emp_qelem *qp;
469 struct emp_qelem *next;
472 for (qp = list->q_back; qp != list; qp = next) {
474 mlp = (struct mlist *)qp;
475 /* If the ship isn't in the requested sector, then continue */
476 if (newx != mlp->ship.shp_x || newy != mlp->ship.shp_y)
478 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
480 if (nowantflags && mlp->mcp->m_flags & nowantflags)
487 static struct mlist *
488 most_valuable_ship(struct emp_qelem *list)
490 struct emp_qelem *qp;
491 struct emp_qelem *next;
493 struct mlist *mvs = 0;
495 for (qp = list->q_back; qp != list; qp = next) {
497 mlp = (struct mlist *)qp;
498 if (mlp->mcp->m_flags & M_SUB)
500 if (!mlp->mcp->m_nxlight &&
501 !mlp->mcp->m_nchoppers &&
502 mlp->mcp->m_cost < 1000 &&
503 !mlp->mcp->m_nplanes && !mlp->mcp->m_nland)
509 if (mlp->mcp->m_cost * mlp->ship.shp_effic >
510 mvs->mcp->m_cost * mvs->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 mlist *)qp;
529 if (wantflags && (mlp->mcp->m_flags & wantflags) != wantflags)
531 if (nowantflags && mlp->mcp->m_flags & nowantflags)
533 hard = shp_hardtarget(&mlp->ship);
535 easiest = hard; /* things get worse for victim */
538 return easiest - count;
542 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
548 struct emp_qelem msl_list, *qp, *newqp;
552 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
555 while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
556 sprintf(what, "%s", prship(&mvs->ship));
557 dam = msl_launch_mindam(&msl_list, newx, newy,
558 shp_hardtarget(&mvs->ship),
559 EF_SHIP, 1, what, victim, MI_INTERDICT);
562 "missile interdiction mission does %d damage to %s!\n",
564 shp_damage_one(mvs, dam);
567 } else if (++twotries >= 2) {
571 qp = msl_list.q_forw;
572 while (qp != msl_list.q_forw) {
582 /* Note that this function has a side effect - it uses coastwatch
583 * ranges to see if it should fire upon a ship. So, this function
584 * is expected to return positive if a ship is in range, and 0 if a
585 * ship is not in range. */
587 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
589 struct emp_qelem *qp;
590 struct emp_qelem *next;
595 natp = getnatp(sectp->sct_own);
597 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
598 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
606 for (qp = list->q_back; qp != list; qp = next) {
608 mlp = (struct mlist *)qp;
609 if (mlp->mcp->m_flags & M_SUB)
611 if (natp->nat_flags & NF_COASTWATCH)
612 wu(0, sectp->sct_own,
613 "%s %s sighted at %s\n",
614 cname(mlp->ship.shp_own),
616 xyas(mlp->ship.shp_x, mlp->ship.shp_y, sectp->sct_own));
618 setcont(sectp->sct_own, mlp->ship.shp_own, FOUND_COAST);
625 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
631 double range, range2, guneff;
635 s_char notified[MAXNOC];
638 /* Inform neutral and worse */
639 for (i = 0; i < MAXNOC; ++i) {
640 if (getrel(getnatp(i), victim) <= NEUTRAL)
646 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
647 while (nxtsct(&ns, &fsect)) {
650 if (fsect.sct_own == victim)
652 if (notified[fsect.sct_own])
654 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
655 if (notify_coastguard(list, trange, &fsect))
656 notified[fsect.sct_own] = 1;
658 if (opt_NO_FORT_FIRE)
659 return 0; /* Only coastwatch notify in nofortfire */
660 /* Only fire at Hostile ships */
661 for (i = 0; i < MAXNOC; ++i) {
662 if (getrel(getnatp(i), victim) >= NEUTRAL)
665 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
666 while (nxtsct(&ns, &fsect)) {
667 if (!notified[fsect.sct_own])
669 if (fsect.sct_type != SCT_FORTR)
671 gun = fsect.sct_item[I_GUN];
674 range = tfactfire(fsect.sct_own, (double)MIN(gun, 7));
675 if (fsect.sct_effic > 59)
677 range2 = roundrange(range);
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,
686 fsect.sct_x, fsect.sct_y, I_SHELL, 1);
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)(((double)sp->shp_effic / 100.0) *
761 (20 + (double)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);
774 m = 22.0 + (double)(random() % 21);
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 */
825 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
826 shp_put(list, actor);
831 for (qp = list->q_back; qp != list; qp = next) {
833 mlp = (struct mlist *)qp;
834 newx = xnorm(mlp->ship.shp_x + dx);
835 newy = ynorm(mlp->ship.shp_y + dy);
836 getsect(newx, newy, §);
837 if (shp_check_nav(§) != CN_NAVIGABLE ||
838 (sect.sct_own && actor != sect.sct_own &&
839 getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
841 mpr(actor, "can't go to %s\n", xyas(newx, newy, actor));
844 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
849 if (IS_BIG_CITY(sect.sct_type)) {
850 if (!(mlp->mcp->m_flags & M_CANAL)) {
852 "is too large to fit into the canal system at %s",
853 xyas(newx, newy, actor));
858 if (mlp->mobil <= 0.0) {
859 shp_mess("is out of mobility", mlp);
862 mobcost = mlp->ship.shp_effic * 0.01 * mlp->ship.shp_speed;
864 (mobcost + techfact(mlp->ship.shp_tech, mobcost));
865 mlp->ship.shp_x = newx;
866 mlp->ship.shp_y = newy;
867 if (mlp->mobil - mobcost < -127) {
870 mlp->mobil -= mobcost;
872 mlp->ship.shp_mobil = (int)mlp->mobil;
873 putship(mlp->ship.shp_uid, &mlp->ship);
875 /* Now update the map for this ship */
876 tech = techfact(mlp->ship.shp_tech, (double)mlp->mcp->m_vrnge);
877 if (mlp->mcp->m_flags & M_SONAR)
878 tf = techfact(mlp->ship.shp_tech, 1.0);
881 radmapupd(mlp->ship.shp_own, mlp->ship.shp_x, mlp->ship.shp_y,
882 (int)mlp->ship.shp_effic, (int)tech, tf);
886 stopping |= shp_sweep(list, 0, actor);
889 stopping |= shp_check_mines(list);
893 /* interdict ships sector by sector */
895 while (!QEMPTY(list)) {
896 mlp = (struct mlist *)list->q_back;
897 newx = mlp->ship.shp_x;
898 newy = mlp->ship.shp_y;
899 stopping |= shp_interdict(list, newx, newy, actor);
900 /* move survivors in this sector to done */
901 for (qp = list->q_back; qp != list; qp = next) {
903 mlp = (struct mlist *)qp;
904 if (mlp->ship.shp_x == newx && mlp->ship.shp_y == newy) {
906 emp_insque(qp, &done);
910 /* assign surviving ships back to list */
911 emp_insque(list, &done);
919 * Check for incoming missiles with a P_MAR flag.
920 * Return True=1 if the missile was shotdown.
923 * Chad Zabel, July 95
927 shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
933 double gun, eff, teff;
935 snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
937 while (nxtitem(&ni, &ship)) {
941 if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE))
944 if (getrel(getnatp(ship.shp_own), bombown) >= NEUTRAL)
947 if (ship.shp_effic < 60)
950 shell = ship.shp_item[I_SHELL];
951 if (ship.shp_item[I_MILIT] < 1) /* do we have mil? */
953 if (shell < 2) { /* do we need shells */
954 shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
959 if (ship.shp_item[I_GUN] < 1) /* we need at least 1 gun */
962 /* now calculate the odds */
963 gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
964 eff = (double)ship.shp_effic / 100.0;
966 (((double)ship.shp_tech) / (((double)ship.shp_tech) + 200.0));
967 /* raise 4.5 for better interception -KHS */
968 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
974 mpr(bombown, "%s anti-missile system activated...",
975 cname(ship.shp_own));
976 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
978 mpr(ship.shp_own, "%d%% hitchance...", hitchance);
980 ship.shp_item[I_SHELL] = shell - 2;
981 putship(ship.shp_uid, &ship);
983 if (roll(100) <= hitchance) {
984 mpr(bombown, "KABOOOM!! Missile destroyed\n\n");
986 "KABOOOM!! Incoming missile destroyed!\n\n");
989 mpr(bombown, "SWOOSH!! anti-missile system failed!!\n");
991 "SWOOSH!! Missile evades anti-missile systems\n\n");
994 return 0; /* all attempts failed */
998 shp_path(int together, struct shpstr *shp, s_char *buf)
1002 struct sctstr d_sect;
1005 if (!sarg_xy(buf, &destx, &desty))
1009 "Cannot go to a destination sector if not all starting in the same sector\n");
1012 if (!getsect(destx, desty, &d_sect)) {
1013 mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty);
1017 cp = BestShipPath(buf, shp->shp_x, shp->shp_y,
1018 d_sect.sct_x, d_sect.sct_y, player->cnum);
1019 if (!cp || shp->shp_mobil <= 0) {
1020 mpr(shp->shp_own, "Can't get to '%s' right now.\n",
1021 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1027 /* Fire missiles at a ship which has fired shells */
1029 shp_missdef(struct shpstr *sp, natid victim)
1031 struct emp_qelem list;
1038 mlp = malloc(sizeof(struct mlist));
1039 mlp->mcp = &mchr[(int)sp->shp_type];
1041 mlp->mobil = (double)sp->shp_mobil;
1042 emp_insque(&mlp->queue, &list);
1043 sprintf(buf, "%s", prship(&mlp->ship));
1045 eff = sp->shp_effic;
1046 if (most_valuable_ship(&list)) {
1047 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
1048 getship(sp->shp_uid, sp);
1052 "missiles launched in defense did 100%% damage to %s\n",
1054 wu(0, victim, "%s sunk!\n", buf);
1055 } else if (eff > 0 && sp->shp_effic < eff) {
1057 "missiles launched in defense did %d%% damage to %s\n",
1058 100 * (eff - sp->shp_effic) / eff, buf);
1066 * Set SP's tech to TLEV along with everything else that depends on it.
1069 shp_set_tech(struct shpstr *sp, int tlev)
1071 struct mchrstr *mcp = mchr + sp->shp_type;
1072 int tech_diff = tlev - mcp->m_tech;
1074 if (CANT_HAPPEN(tech_diff < 0)) {
1079 sp->shp_tech = tlev;
1080 sp->shp_armor = (short)SHP_DEF(mcp->m_armor, tech_diff);
1081 sp->shp_speed = (short)SHP_SPD(mcp->m_speed, tech_diff);
1082 sp->shp_visib = (short)SHP_VIS(mcp->m_visib, tech_diff);
1083 sp->shp_frnge = (short)SHP_RNG(mcp->m_frnge, tech_diff);
1084 sp->shp_glim = (short)SHP_FIR(mcp->m_glim, tech_diff);