* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)move.c 5.3 (Berkeley) %G%";
** Move Under Warp or Impulse Power
** `Ramflag' is set if we are to be allowed to ram stars,
** Klingons, etc. This is passed from warp(), which gets it from
** either play() or ram(). Course is the course (0 -> 360) at
** which we want to move. `Speed' is the speed we
** want to go, and `time' is the expected time. It
** can get cut short if a long range tractor beam is to occur. We
** cut short the move so that the user doesn't get docked time and
** energy for distance which he didn't travel.
** We check the course through the current quadrant to see that he
** doesn't run into anything. After that, though, space sort of
** bends around him. Note that this puts us in the awkward posi-
** tion of being able to be dropped into a sector which is com-
** pletely surrounded by stars. Oh Well.
** If the SINS (Space Inertial Navigation System) is out, we ran-
** domize the course accordingly before ever starting to move.
** We will still move in a straight line.
** Note that if your computer is out, you ram things anyway. In
** other words, if your computer and sins are both out, you're in
** potentially very bad shape.
** Klingons get a chance to zap you as you leave the quadrant.
** By the way, they also try to follow you (heh heh).
** Return value is the actual amount of time used.
double move(ramflag
, course
, time
, speed
)
printf("move: ramflag %d course %d time %.2f speed %.2f\n",
ramflag
, course
, time
, speed
);
/* initialize delta factors for move */
angle
= course
* 0.0174532925;
angle
+= Param
.navigcrud
[1] * (franf() - 0.5);
angle
+= Param
.navigcrud
[0] * (franf() - 0.5);
/* check for long range tractor beams */
/**** TEMPORARY CODE == DEBUGGING ****/
evtime
= Now
.eventptr
[E_LRTB
]->date
- Now
.date
;
printf("E.ep = %u, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
Now
.eventptr
[E_LRTB
], Now
.eventptr
[E_LRTB
]->evcode
,
Now
.eventptr
[E_LRTB
]->date
, evtime
);
if (time
> evtime
&& Etc
.nkling
< 3)
/* move within quadrant */
Sect
[Ship
.sectx
][Ship
.secty
] = EMPTY
;
xn
= NSECTS
* dist
* bigger
;
printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx
, dy
, xn
, n
);
printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix
, x
, iy
, y
);
if (x
< 0.0 || y
< 0.0 || x
>= sectsize
|| y
>= sectsize
)
dx
= Ship
.quadx
* NSECTS
+ Ship
.sectx
+ dx
* xn
;
dy
= Ship
.quady
* NSECTS
+ Ship
.secty
+ dy
* xn
;
printf("New quad: ix = %d, iy = %d\n", ix
, iy
);
Ship
.quadx
= ix
/ NSECTS
;
Ship
.quady
= iy
/ NSECTS
;
Ship
.sectx
= ix
% NSECTS
;
Ship
.secty
= iy
% NSECTS
;
if (ix
< 0 || Ship
.quadx
>= NQUADS
|| iy
< 0 || Ship
.quady
>= NQUADS
)
if (Sect
[ix
][iy
] != EMPTY
)
/* we just hit something */
if (!damaged(COMPUTER
) && ramflag
<= 0)
printf("Computer reports navigation error; %s stopped at %d,%d\n",
Ship
.energy
-= Param
.stopengy
* speed
;
/* test for a black hole */
if (Sect
[ix
][iy
] == HOLE
)
/* get dumped elsewhere in the galaxy */
dist
= sqrt(dx
* dx
+ dy
* dy
) / NSECTS
;
time
= evtime
; /* spring the LRTB trap */
Sect
[Ship
.sectx
][Ship
.secty
] = Ship
.ship
;