2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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
49 #include "prototypes.h"
56 static int shp_check_one_mines(struct ulist *);
57 static int shp_hit_mine(struct shpstr *, struct mchrstr *);
58 static void shp_mess(char *, struct ulist *);
61 shp_sel(struct nstr_item *ni, struct emp_qelem *list)
73 while (nxtitem(ni, &ship)) {
76 mcp = &mchr[(int)ship.shp_type];
77 /* if (wantflags && (mcp->m_flags & wantflags) != wantflags)
79 if (nowantflags && mcp->m_flags & nowantflags)
83 if (ontradingblock(EF_SHIP, &ship)) {
84 pr("ship #%d inelligible - it's for sale.\n",
89 /* This abuse is better fixed by building a ship with the normal negative
90 mobility that everything else is built with */
93 if (ship.shp_effic < 21 &&
94 ship.shp_mobil < etu_per_update) {
95 pr("%s needs at least %d mob to navigate.\n",
96 prship(&ship), etu_per_update);
101 ship.shp_mission = 0;
103 memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
104 putship(ship.shp_uid, &ship);
105 mlp = malloc(sizeof(struct ulist));
106 mlp->chrp = (struct empobj_chr *)mcp;
107 mlp->unit.ship = ship;
108 mlp->mobil = ship.shp_mobil;
109 emp_insque(&mlp->queue, list);
113 /* This function assumes that the list was created by shp_sel */
115 shp_nav(struct emp_qelem *list, double *minmobp, double *maxmobp,
116 int *togetherp, natid actor)
118 struct emp_qelem *qp;
119 struct emp_qelem *next;
130 for (qp = list->q_back; qp != list; qp = next) {
132 mlp = (struct ulist *)qp;
133 getship(mlp->unit.ship.shp_uid, &ship);
134 if (ship.shp_own != actor) {
135 mpr(actor, "%s was sunk at %s\n",
136 prship(&ship), xyas(ship.shp_x, ship.shp_y, actor));
137 emp_remque((struct emp_qelem *)mlp);
142 if (*ship.shp_path && !update_pending) {
143 shp_mess("has a sail path", mlp);
144 mpr(actor, "Use `sail <#> -' to reset\n");
148 /* check crew - uws don't count */
149 if (ship.shp_item[I_MILIT] == 0 && ship.shp_item[I_CIVIL] == 0) {
150 shp_mess("is crewless", mlp);
153 if (!getsect(ship.shp_x, ship.shp_y, §)) {
154 shp_mess("was sucked into the sky by a strange looking spaceship", mlp); /* heh -KHS */
157 switch (shp_check_nav(§, &ship)) {
158 case CN_CONSTRUCTION:
159 shp_mess("is caught in a construction zone", mlp);
162 shp_mess("is landlocked", mlp);
168 shp_mess("was just swallowed by a big green worm", mlp);
176 if (ship.shp_x != allx || ship.shp_y != ally)
178 if (ship.shp_mobil + 1 < (int)mlp->mobil) {
179 mlp->mobil = ship.shp_mobil;
181 if (mlp->mobil < *minmobp)
182 *minmobp = mlp->mobil;
183 if (mlp->mobil > *maxmobp)
184 *maxmobp = mlp->mobil;
185 mlp->unit.ship = ship;
190 shp_put(struct emp_qelem *list, natid actor)
192 struct emp_qelem *qp;
193 struct emp_qelem *newqp;
198 mlp = (struct ulist *)qp;
199 mpr(actor, "%s stopped at %s\n", prship(&mlp->unit.ship),
200 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
201 mlp->unit.ship.shp_own));
202 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
203 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
212 shp_sweep(struct emp_qelem *ship_list, int verbose, int takemob, natid actor)
214 struct emp_qelem *qp;
215 struct emp_qelem *next;
218 int mines, m, max, shells;
222 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
224 mlp = (struct ulist *)qp;
225 if (!(((struct mchrstr *)mlp->chrp)->m_flags & M_SWEEP)) {
227 mpr(actor, "%s doesn't have minesweeping capability!\n",
228 prship(&mlp->unit.ship));
231 if (takemob && mlp->mobil <= 0.0) {
233 mpr(actor, "%s is out of mobility!\n",
234 prship(&mlp->unit.ship));
237 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
238 if (sect.sct_type != SCT_WATER) {
240 mpr(actor, "%s is not at sea. No mines there!\n",
241 prship(&mlp->unit.ship));
245 mlp->mobil -= shp_mobcost(&mlp->unit.ship);
246 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
248 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
249 if (!(mines = sect.sct_mines))
251 max = ((struct mchrstr *)mlp->chrp)->m_item[I_SHELL];
252 shells = mlp->unit.ship.shp_item[I_SHELL];
253 for (m = 0; mines > 0 && m < 5; m++) {
255 mpr(actor, "Sweep...\n");
257 shells = MIN(max, shells + 1);
258 changed |= map_set(actor, sect.sct_x, sect.sct_y, 'X', 0);
261 sect.sct_mines = mines;
262 mlp->unit.ship.shp_item[I_SHELL] = shells;
263 if (shp_check_one_mines(mlp)) {
268 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
277 shp_check_one_mines(struct ulist *mlp)
282 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
283 if (sect.sct_type != SCT_WATER)
287 if (chance(DMINE_HITCHANCE(sect.sct_mines))) {
288 actor = mlp->unit.ship.shp_own;
289 shp_hit_mine(&mlp->unit.ship, ((struct mchrstr *)mlp->chrp));
291 if (map_set(actor, sect.sct_x, sect.sct_y, 'X', 0))
294 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
295 if (!mlp->unit.ship.shp_own)
302 shp_check_mines(struct emp_qelem *ship_list)
304 struct emp_qelem *qp;
305 struct emp_qelem *next;
309 for (qp = ship_list->q_back; qp != ship_list; qp = next) {
311 mlp = (struct ulist *)qp;
312 if (shp_check_one_mines(mlp)) {
323 shp_mess(char *str, struct ulist *mlp)
325 mpr(mlp->unit.ship.shp_own, "%s %s & stays in %s\n",
326 prship(&mlp->unit.ship),
327 str, xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
328 mlp->unit.ship.shp_own));
329 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
330 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
331 emp_remque((struct emp_qelem *)mlp);
336 shp_check_nav(struct sctstr *sect, struct shpstr *shp)
338 switch (dchr[sect->sct_type].d_nav) {
342 if (mchr[(int)shp->shp_type].m_flags & M_CANAL) {
343 if (sect->sct_effic < 2)
344 return CN_CONSTRUCTION;
346 return CN_LANDLOCKED;
349 if (sect->sct_effic < 2)
350 return CN_CONSTRUCTION;
353 if (sect->sct_effic < 60)
354 return CN_CONSTRUCTION;
357 return CN_LANDLOCKED;
363 sect_has_dock(struct sctstr *sect)
365 switch (dchr[sect->sct_type].d_nav) {
375 shp_count(struct emp_qelem *list, int wantflags, int nowantflags,
378 struct emp_qelem *qp;
379 struct emp_qelem *next;
383 for (qp = list->q_back; qp != list; qp = next) {
385 mlp = (struct ulist *)qp;
386 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
389 (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
392 ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
400 shp_damage_one(struct ulist *mlp, int dam)
402 shipdamage(&mlp->unit.ship, dam);
403 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
404 if (!mlp->unit.ship.shp_own) {
405 emp_remque((struct emp_qelem *)mlp);
411 shp_damage(struct emp_qelem *list, int totdam, int wantflags,
412 int nowantflags, int x, int y)
414 struct emp_qelem *qp;
415 struct emp_qelem *next;
421 || !(count = shp_count(list, wantflags, nowantflags, x, y)))
423 dam = ldround((double)totdam / count, 1);
424 for (qp = list->q_back; qp != list; qp = next) {
426 mlp = (struct ulist *)qp;
427 if (mlp->unit.ship.shp_x != x || mlp->unit.ship.shp_y != y)
430 (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
433 ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
435 shp_damage_one(mlp, dam);
441 shp_contains(struct emp_qelem *list, int newx, int newy, int wantflags,
444 struct emp_qelem *qp;
445 struct emp_qelem *next;
448 for (qp = list->q_back; qp != list; qp = next) {
450 mlp = (struct ulist *)qp;
451 /* If the ship isn't in the requested sector, then continue */
452 if (newx != mlp->unit.ship.shp_x || newy != mlp->unit.ship.shp_y)
455 (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
458 ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
465 static struct ulist *
466 most_valuable_ship(struct emp_qelem *list)
468 struct emp_qelem *qp;
469 struct emp_qelem *next;
471 struct ulist *mvs = 0;
473 for (qp = list->q_back; qp != list; qp = next) {
475 mlp = (struct ulist *)qp;
476 if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
478 if (!((struct mchrstr *)mlp->chrp)->m_nxlight &&
479 !((struct mchrstr *)mlp->chrp)->m_nchoppers &&
480 ((struct mchrstr *)mlp->chrp)->m_cost < 1000 &&
481 !((struct mchrstr *)mlp->chrp)->m_nplanes &&
482 !((struct mchrstr *)mlp->chrp)->m_nland)
488 if (((struct mchrstr *)mlp->chrp)->m_cost * mlp->unit.ship.shp_effic >
489 ((struct mchrstr *)mlp->chrp)->m_cost * mvs->unit.ship.shp_effic)
496 shp_easiest_target(struct emp_qelem *list, int wantflags, int nowantflags)
498 struct emp_qelem *qp;
499 struct emp_qelem *next;
502 int easiest = 9876; /* things start great for victim */
505 for (qp = list->q_back; qp != list; qp = next) {
507 mlp = (struct ulist *)qp;
509 (((struct mchrstr *)mlp->chrp)->m_flags & wantflags) != wantflags)
512 ((struct mchrstr *)mlp->chrp)->m_flags & nowantflags)
514 hard = shp_hardtarget(&mlp->unit.ship);
516 easiest = hard; /* things get worse for victim */
519 return easiest - count;
523 shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
529 struct emp_qelem msl_list, *qp, *newqp;
533 msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
536 while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
537 sprintf(what, "%s", prship(&mvs->unit.ship));
538 dam = msl_launch_mindam(&msl_list, newx, newy,
539 shp_hardtarget(&mvs->unit.ship),
540 EF_SHIP, 1, what, victim, MI_INTERDICT);
543 "missile interdiction mission does %d damage to %s!\n",
545 shp_damage_one(mvs, dam);
548 } else if (++twotries >= 2) {
552 qp = msl_list.q_forw;
553 while (qp != msl_list.q_forw) {
563 /* Note that this function has a side effect - it uses coastwatch
564 * ranges to see if it should fire upon a ship. So, this function
565 * is expected to return positive if a ship is in range, and 0 if a
566 * ship is not in range. */
568 notify_coastguard(struct emp_qelem *list, int trange, struct sctstr *sectp)
570 struct emp_qelem *qp;
571 struct emp_qelem *next;
576 natp = getnatp(sectp->sct_own);
578 vrange = sectp->sct_type == SCT_RADAR ? 14 : 4;
579 vrange *= tfact(sectp->sct_own, 1.0) * sectp->sct_effic / 100.0;
587 for (qp = list->q_back; qp != list; qp = next) {
589 mlp = (struct ulist *)qp;
590 if (((struct mchrstr *)mlp->chrp)->m_flags & M_SUB)
592 if (natp->nat_flags & NF_COASTWATCH)
593 wu(0, sectp->sct_own,
594 "%s %s sighted at %s\n",
595 cname(mlp->unit.ship.shp_own),
596 prship(&mlp->unit.ship),
597 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
600 setcont(sectp->sct_own, mlp->unit.ship.shp_own, FOUND_COAST);
607 shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
617 signed char notified[MAXNOC];
620 /* Inform neutral and worse */
621 for (i = 0; i < MAXNOC; ++i) {
622 if (getrel(getnatp(i), victim) <= NEUTRAL)
628 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
629 while (nxtsct(&ns, &fsect)) {
632 if (fsect.sct_own == victim)
634 if (notified[fsect.sct_own])
636 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
637 if (notify_coastguard(list, trange, &fsect))
638 notified[fsect.sct_own] = 1;
640 if (opt_NO_FORT_FIRE)
641 return 0; /* Only coastwatch notify in nofortfire */
642 /* Only fire at Hostile ships */
643 for (i = 0; i < MAXNOC; ++i) {
644 if (getrel(getnatp(i), victim) >= NEUTRAL)
647 snxtsct_dist(&ns, newx, newy, fort_max_interdiction_range);
648 while (nxtsct(&ns, &fsect)) {
649 if (!notified[fsect.sct_own])
651 gun = fsect.sct_item[I_GUN];
654 range = roundrange(fortrange(&fsect));
655 trange = mapdist(newx, newy, fsect.sct_x, fsect.sct_y);
658 if (fsect.sct_item[I_MILIT] < 5)
660 shell = fsect.sct_item[I_SHELL];
662 shell += supply_commod(fsect.sct_own, fsect.sct_x, fsect.sct_y,
667 fsect.sct_item[I_SHELL] = shell;
671 guneff = landgun((int)fsect.sct_effic, gun);
674 mpr(victim, "Incoming fire does %d damage!\n", dam);
676 mpr(victim, "%s fires at you for %d!\n",
677 xyas(fsect.sct_x,fsect.sct_y,victim),
681 "%s fires at %s ships in %s for %d!\n",
682 xyas(fsect.sct_x, fsect.sct_y,
684 cname(victim), xyas(newx, newy, fsect.sct_own), dam);
685 nreport(fsect.sct_own, N_SHP_SHELL, victim, 1);
688 return shp_damage(list, totdam, 0, M_SUB, newx, newy);
693 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
697 if (shp_contains(list, newx, newy, 0, M_SUB)) {
698 stopping |= shp_fort_interdiction(list, newx, newy, victim);
700 if (shp_contains(list, newx, newy, 0, M_SUB)) {
703 unit_interdict(newx, newy, victim, "ships",
704 shp_easiest_target(list, 0, M_SUB),
706 0, M_SUB, newx, newy);
707 if (most_valuable_ship(list)) {
709 shp_missile_interdiction(list, newx, newy, victim);
713 if (shp_contains(list, newx, newy, M_SUB, 0)) {
716 unit_interdict(newx, newy, victim, "subs",
717 shp_easiest_target(list, M_SUB, 0),
719 M_SUB, 0, newx, newy);
724 /* high value of hardtarget is harder to hit */
726 shp_hardtarget(struct shpstr *sp)
730 struct mchrstr *mcp = mchr + sp->shp_type;
733 getsect(sp->shp_x, sp->shp_y, §);
734 onsea = sect.sct_type == SCT_WATER;
735 if (mcp->m_flags & M_SUB)
737 return (int)((sp->shp_effic / 100.0) *
738 (20 + sp->shp_speed * onsea / 2.0 - vis));
742 shp_hit_mine(struct shpstr *sp, struct mchrstr *mcp)
746 mpr(sp->shp_own, "Kawhomp! Mine detected in %s!\n",
747 xyas(sp->shp_x, sp->shp_y, sp->shp_own));
749 nreport(sp->shp_own, N_HIT_MINE, 0, 1);
752 if (mcp->m_flags & M_SWEEP)
755 shipdamage(sp, ldround(m, 1));
761 shp_view(struct emp_qelem *list)
764 struct emp_qelem *qp;
765 struct emp_qelem *next;
768 for (qp = list->q_back; qp != list; qp = next) {
770 mlp = (struct ulist *)qp;
771 getsect(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, §);
772 if (((struct mchrstr *)mlp->chrp)->m_flags & M_FOOD)
773 mpr(mlp->unit.ship.shp_own, "[fert:%d] ", sect.sct_fertil);
774 if (((struct mchrstr *)mlp->chrp)->m_flags & M_OIL)
775 mpr(mlp->unit.ship.shp_own, "[oil:%d] ", sect.sct_oil);
776 mpr(mlp->unit.ship.shp_own, "%s @ %s %d%% %s\n",
777 prship(&mlp->unit.ship),
778 xyas(mlp->unit.ship.shp_x, mlp->unit.ship.shp_y, player->cnum),
779 sect.sct_effic, dchr[sect.sct_type].d_name);
784 shp_nav_one_sector(struct emp_qelem *list, int dir, natid actor,
788 struct emp_qelem *qp;
789 struct emp_qelem *next;
791 struct emp_qelem done;
798 double tech; /* for mapping */
799 double tf; /* for mapping */
803 if (dir <= DIR_STOP || dir >= DIR_VIEW) {
804 shp_put(list, actor);
809 for (qp = list->q_back; qp != list; qp = next) {
811 mlp = (struct ulist *)qp;
812 newx = xnorm(mlp->unit.ship.shp_x + dx);
813 newy = ynorm(mlp->unit.ship.shp_y + dy);
814 getsect(newx, newy, §);
815 navigate = shp_check_nav(§, &mlp->unit.ship);
816 if (navigate != CN_NAVIGABLE ||
817 (sect.sct_own && actor != sect.sct_own &&
818 getrel(getnatp(sect.sct_own), actor) < FRIENDLY)) {
819 if (dchr[sect.sct_type].d_nav == NAV_CANAL &&
820 !(((struct mchrstr *)mlp->chrp)->m_flags & M_CANAL) &&
821 navigate == CN_LANDLOCKED)
823 "is too large to fit into the canal system at %s",
824 xyas(newx, newy, actor));
826 sprintf(dp, "can't go to %s", xyas(newx, newy, actor));
828 mpr(actor, "%s\n", dp);
836 if (mlp->mobil <= 0.0) {
837 shp_mess("is out of mobility", mlp);
840 mobcost = shp_mobcost(&mlp->unit.ship);
841 mlp->unit.ship.shp_x = newx;
842 mlp->unit.ship.shp_y = newy;
843 if (mlp->mobil - mobcost < -127) {
846 mlp->mobil -= mobcost;
848 mlp->unit.ship.shp_mobil = (int)mlp->mobil;
849 putship(mlp->unit.ship.shp_uid, &mlp->unit.ship);
851 /* Now update the map for this ship */
852 tech = techfact(mlp->unit.ship.shp_tech,
853 ((struct mchrstr *)mlp->chrp)->m_vrnge);
854 if (((struct mchrstr *)mlp->chrp)->m_flags & M_SONAR)
855 tf = techfact(mlp->unit.ship.shp_tech, 1.0);
858 radmapupd(mlp->unit.ship.shp_own,
859 mlp->unit.ship.shp_x, mlp->unit.ship.shp_y,
860 (int)mlp->unit.ship.shp_effic, (int)tech, tf);
864 stopping |= shp_sweep(list, 0, 0, actor);
867 stopping |= shp_check_mines(list);
871 /* interdict ships sector by sector */
873 while (!QEMPTY(list)) {
874 mlp = (struct ulist *)list->q_back;
875 newx = mlp->unit.ship.shp_x;
876 newy = mlp->unit.ship.shp_y;
877 stopping |= shp_interdict(list, newx, newy, actor);
878 /* move survivors in this sector to done */
879 for (qp = list->q_back; qp != list; qp = next) {
881 mlp = (struct ulist *)qp;
882 if (mlp->unit.ship.shp_x == newx &&
883 mlp->unit.ship.shp_y == newy) {
885 emp_insque(qp, &done);
889 /* assign surviving ships back to list */
890 emp_insque(list, &done);
898 * Check for incoming missiles with a P_MAR flag.
899 * Return True=1 if the missile was shotdown.
902 * Chad Zabel, July 95
906 shp_missile_defense(coord dx, coord dy, natid bombown, int hardtarget)
912 double gun, eff, teff;
914 snxtitem_dist(&ni, EF_SHIP, dx, dy, 1);
916 while (nxtitem(&ni, &ship)) {
920 if (!(mchr[(int)ship.shp_type].m_flags & M_ANTIMISSILE))
923 if (getrel(getnatp(ship.shp_own), bombown) >= NEUTRAL)
926 if (ship.shp_effic < 60)
929 shell = ship.shp_item[I_SHELL];
930 if (ship.shp_item[I_MILIT] < 1) /* do we have mil? */
932 if (shell < 2) { /* do we need shells */
933 shell += supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
938 if (ship.shp_item[I_GUN] < 1) /* we need at least 1 gun */
941 /* now calculate the odds */
942 gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
943 eff = ship.shp_effic / 100.0;
944 teff = ship.shp_tech / (ship.shp_tech + 200.0);
945 /* raise 4.5 for better interception -KHS */
946 hitchance = (int)(gun * eff * teff * 4.5) - hardtarget;
952 mpr(bombown, "%s anti-missile system activated...",
953 cname(ship.shp_own));
954 mpr(ship.shp_own, "Ship #%i anti-missile system activated!\n",
956 mpr(ship.shp_own, "%d%% hitchance...", hitchance);
958 ship.shp_item[I_SHELL] = shell - 2;
959 putship(ship.shp_uid, &ship);
961 if (roll(100) <= hitchance) {
962 mpr(bombown, "KABOOOM!! Missile destroyed\n\n");
964 "KABOOOM!! Incoming missile destroyed!\n\n");
967 mpr(bombown, "SWOOSH!! anti-missile system failed!!\n");
969 "SWOOSH!! Missile evades anti-missile systems\n\n");
972 return 0; /* all attempts failed */
976 shp_path(int together, struct shpstr *shp, char *buf)
980 struct sctstr d_sect;
983 if (!sarg_xy(buf, &destx, &desty))
987 "Cannot go to a destination sector if not all starting in the same sector\n");
990 if (!getsect(destx, desty, &d_sect)) {
991 mpr(shp->shp_own, "%d,%d is not a sector\n", destx, desty);
995 cp = BestShipPath(buf, shp->shp_x, shp->shp_y,
996 d_sect.sct_x, d_sect.sct_y, player->cnum);
997 if (!cp || shp->shp_mobil <= 0) {
998 mpr(shp->shp_own, "Can't get to '%s' right now.\n",
999 xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
1005 /* Fire missiles at a ship which has fired shells */
1007 shp_missdef(struct shpstr *sp, natid victim)
1009 struct emp_qelem list;
1016 mlp = malloc(sizeof(struct ulist));
1017 mlp->chrp = (struct empobj_chr *)&mchr[(int)sp->shp_type];
1018 mlp->unit.ship = *sp;
1019 mlp->mobil = sp->shp_mobil;
1020 emp_insque(&mlp->queue, &list);
1021 sprintf(buf, "%s", prship(&mlp->unit.ship));
1023 eff = sp->shp_effic;
1024 if (most_valuable_ship(&list)) {
1025 shp_missile_interdiction(&list, sp->shp_x, sp->shp_y, sp->shp_own);
1026 getship(sp->shp_uid, sp);
1030 "missiles launched in defense did 100%% damage to %s\n",
1032 wu(0, victim, "%s sunk!\n", buf);
1033 } else if (eff > 0 && sp->shp_effic < eff) {
1035 "missiles launched in defense did %d%% damage to %s\n",
1036 100 * (eff - sp->shp_effic) / eff, buf);
1044 shp_mobcost(struct shpstr *sp)
1046 return speed_factor(sp->shp_effic * 0.01 * sp->shp_speed,
1051 * Set SP's tech to TLEV along with everything else that depends on it.
1054 shp_set_tech(struct shpstr *sp, int tlev)
1056 struct mchrstr *mcp = mchr + sp->shp_type;
1057 int tech_diff = tlev - mcp->m_tech;
1059 if (CANT_HAPPEN(tech_diff < 0)) {
1064 sp->shp_tech = tlev;
1065 sp->shp_armor = (short)SHP_DEF(mcp->m_armor, tech_diff);
1066 sp->shp_speed = (short)SHP_SPD(mcp->m_speed, tech_diff);
1067 sp->shp_visib = (short)SHP_VIS(mcp->m_visib, tech_diff);
1068 sp->shp_frnge = (short)SHP_RNG(mcp->m_frnge, tech_diff);
1069 sp->shp_glim = (short)SHP_FIR(mcp->m_glim, tech_diff);