2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)move.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/trek/move.c,v 1.6 1999/11/30 03:49:50 billf Exp $
35 * $DragonFly: src/games/trek/move.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
41 ** Move Under Warp or Impulse Power
43 ** `Ramflag' is set if we are to be allowed to ram stars,
44 ** Klingons, etc. This is passed from warp(), which gets it from
45 ** either play() or ram(). Course is the course (0 -> 360) at
46 ** which we want to move. `Speed' is the speed we
47 ** want to go, and `p_time' is the expected time. It
48 ** can get cut short if a long range tractor beam is to occur. We
49 ** cut short the move so that the user doesn't get docked time and
50 ** energy for distance which he didn't travel.
52 ** We check the course through the current quadrant to see that he
53 ** doesn't run into anything. After that, though, space sort of
54 ** bends around him. Note that this puts us in the awkward posi-
55 ** tion of being able to be dropped into a sector which is com-
56 ** pletely surrounded by stars. Oh Well.
58 ** If the SINS (Space Inertial Navigation System) is out, we ran-
59 ** domize the course accordingly before ever starting to move.
60 ** We will still move in a straight line.
62 ** Note that if your computer is out, you ram things anyway. In
63 ** other words, if your computer and sins are both out, you're in
64 ** potentially very bad shape.
66 ** Klingons get a chance to zap you as you leave the quadrant.
67 ** By the way, they also try to follow you (heh heh).
69 ** Return value is the actual amount of time used.
76 move(int ramflag, int course, double p_time, double speed)
92 printf("move: ramflag %d course %d time %.2f speed %.2f\n",
93 ramflag, course, p_time, speed);
96 /* initialize delta factors for move */
97 angle = course * 0.0174532925;
99 angle += Param.navigcrud[1] * (franf() - 0.5);
102 angle += Param.navigcrud[0] * (franf() - 0.5);
112 /* check for long range tractor beams */
113 /**** TEMPORARY CODE == DEBUGGING ****/
114 evtime = Now.eventptr[E_LRTB]->date - Now.date;
117 printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
118 (void *)Now.eventptr[E_LRTB],
119 Now.eventptr[E_LRTB]->evcode,
120 Now.eventptr[E_LRTB]->date, evtime);
122 if (p_time > evtime && Etc.nkling < 3)
124 /* then we got a LRTB */
130 dist = p_time * speed;
132 /* move within quadrant */
133 Sect[Ship.sectx][Ship.secty] = EMPTY;
134 x = Ship.sectx + 0.5;
135 y = Ship.secty + 0.5;
136 xn = NSECTS * dist * bigger;
140 printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
144 for (i = 0; i < n; i++)
150 printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y);
152 if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize)
154 /* enter new quadrant */
155 dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn;
156 dy = Ship.quady * NSECTS + Ship.secty + dy * xn;
167 printf("New quad: ix = %d, iy = %d\n", ix, iy);
175 Ship.quadx = ix / NSECTS;
176 Ship.quady = iy / NSECTS;
177 Ship.sectx = ix % NSECTS;
178 Ship.secty = iy % NSECTS;
179 if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 || Ship.quady >= NQUADS)
181 if (!damaged(COMPUTER))
192 if (Sect[ix][iy] != EMPTY)
194 /* we just hit something */
195 if (!damaged(COMPUTER) && ramflag <= 0)
199 printf("Computer reports navigation error; %s stopped at %d,%d\n",
200 Ship.shipname, ix, iy);
201 Ship.energy -= Param.stopengy * speed;
204 /* test for a black hole */
205 if (Sect[ix][iy] == HOLE)
207 /* get dumped elsewhere in the galaxy */
219 dx = Ship.sectx - ix;
220 dy = Ship.secty - iy;
221 dist = sqrt(dx * dx + dy * dy) / NSECTS;
222 p_time = dist / speed;
224 p_time = evtime; /* spring the LRTB trap */
228 Sect[Ship.sectx][Ship.secty] = Ship.ship;