1 /* $NetBSD: move.c,v 1.9 2009/05/24 21:44:56 dholland Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: move.c,v 1.9 2009/05/24 21:44:56 dholland Exp $");
46 ** Move Under Warp or Impulse Power
48 ** `Ramflag' is set if we are to be allowed to ram stars,
49 ** Klingons, etc. This is passed from warp(), which gets it from
50 ** either play() or ram(). Course is the course (0 -> 360) at
51 ** which we want to move. `Speed' is the speed we
52 ** want to go, and `time' is the expected time. It
53 ** can get cut short if a long range tractor beam is to occur. We
54 ** cut short the move so that the user doesn't get docked time and
55 ** energy for distance which he didn't travel.
57 ** We check the course through the current quadrant to see that he
58 ** doesn't run into anything. After that, though, space sort of
59 ** bends around him. Note that this puts us in the awkward posi-
60 ** tion of being able to be dropped into a sector which is com-
61 ** pletely surrounded by stars. Oh Well.
63 ** If the SINS (Space Inertial Navigation System) is out, we ran-
64 ** domize the course accordingly before ever starting to move.
65 ** We will still move in a straight line.
67 ** Note that if your computer is out, you ram things anyway. In
68 ** other words, if your computer and sins are both out, you're in
69 ** potentially very bad shape.
71 ** Klingons get a chance to zap you as you leave the quadrant.
72 ** By the way, they also try to follow you (heh heh).
74 ** Return value is the actual amount of time used.
81 move(int ramflag
, int course
, double time
, double speed
)
96 printf("move: ramflag %d course %d time %.2f speed %.2f\n",
97 ramflag
, course
, time
, speed
);
100 /* initialize delta factors for move */
101 angle
= course
* 0.0174532925;
103 angle
+= Param
.navigcrud
[1] * (franf() - 0.5);
106 angle
+= Param
.navigcrud
[0] * (franf() - 0.5);
116 /* check for long range tractor beams */
117 /**** TEMPORARY CODE == DEBUGGING ****/
118 evtime
= Now
.eventptr
[E_LRTB
]->date
- Now
.date
;
121 printf("E.ep = %p, ->evcode = %d, ->date = %.2f, "
123 Now
.eventptr
[E_LRTB
], Now
.eventptr
[E_LRTB
]->evcode
,
124 Now
.eventptr
[E_LRTB
]->date
, evtime
);
126 if (time
> evtime
&& Etc
.nkling
< 3) {
127 /* then we got a LRTB */
134 /* move within quadrant */
135 Sect
[Ship
.sectx
][Ship
.secty
] = EMPTY
;
136 x
= Ship
.sectx
+ 0.5;
137 y
= Ship
.secty
+ 0.5;
138 xn
= NSECTS
* dist
* bigger
;
142 printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n",
147 for (i
= 0; i
< n
; i
++) {
152 printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n",
155 if (x
< 0.0 || y
< 0.0 || x
>= sectsize
|| y
>= sectsize
) {
156 /* enter new quadrant */
157 dx
= Ship
.quadx
* NSECTS
+ Ship
.sectx
+ dx
* xn
;
158 dy
= Ship
.quady
* NSECTS
+ Ship
.secty
+ dy
* xn
;
169 printf("New quad: ix = %d, iy = %d\n", ix
, iy
);
177 Ship
.quadx
= ix
/ NSECTS
;
178 Ship
.quady
= iy
/ NSECTS
;
179 Ship
.sectx
= ix
% NSECTS
;
180 Ship
.secty
= iy
% NSECTS
;
181 if (ix
< 0 || Ship
.quadx
>= NQUADS
|| iy
< 0 ||
182 Ship
.quady
>= NQUADS
) {
183 if (!damaged(COMPUTER
)) {
192 if (Sect
[ix
][iy
] != EMPTY
) {
193 /* we just hit something */
194 if (!damaged(COMPUTER
) && ramflag
<= 0) {
197 printf("Computer reports navigation error; "
198 "%s stopped at %d,%d\n",
199 Ship
.shipname
, ix
, iy
);
200 Ship
.energy
-= Param
.stopengy
* speed
;
203 /* test for a black hole */
204 if (Sect
[ix
][iy
] == HOLE
) {
205 /* get dumped elsewhere in the galaxy */
216 dx
= Ship
.sectx
- ix
;
217 dy
= Ship
.secty
- iy
;
218 dist
= sqrt(dx
* dx
+ dy
* dy
) / NSECTS
;
221 /* spring the LRTB trap */
227 Sect
[Ship
.sectx
][Ship
.secty
] = Ship
.ship
;