+/* $NetBSD: warp.c,v 1.11 2009/05/24 22:55:03 dholland Exp $ */
+
/*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* SUCH DAMAGE.
*/
+#include <sys/cdefs.h>
#ifndef lint
-/*static char sccsid[] = "from: @(#)warp.c 5.4 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: warp.c,v 1.2 1993/08/01 18:49:52 mycroft Exp $";
+#if 0
+static char sccsid[] = "@(#)warp.c 8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: warp.c,v 1.11 2009/05/24 22:55:03 dholland Exp $");
+#endif
#endif /* not lint */
-# include "trek.h"
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <unistd.h>
+#include "trek.h"
+#include "getpar.h"
/*
** MOVE UNDER WARP POWER
** case, there is code to handle time warps, etc.
*/
-warp(fl, c, d)
-int fl, c;
-double d;
+void
+dowarp(int fl)
+{
+ int c;
+ double d;
+
+ if (getcodi(&c, &d))
+ return;
+ warp(fl, c, d);
+}
+
+void
+warp(int fl, int c, double d)
{
- int course;
- double power;
- double dist;
- double time;
- double speed;
- double frac;
- register int percent;
- register int i;
- extern double move();
-
- if (Ship.cond == DOCKED)
- return (printf("%s is docked\n", Ship.shipname));
- if (damaged(WARP))
- {
- return (out(WARP));
+ char *p;
+ int course;
+ double power;
+ double dist;
+ double time;
+ double speed;
+ double frac;
+ int percent;
+ int i;
+ double repairs;
+
+ if (Ship.cond == DOCKED) {
+ printf("%s is docked\n", Ship.shipname);
+ return;
}
- if (fl < 0)
- {
- course = c;
- dist = d;
+ if (damaged(WARP)) {
+ out(WARP);
+ return;
}
- else
- if (getcodi(&course, &dist))
- return;
+
+ course = c;
+ dist = d;
/* check to see that we are not using an absurd amount of power */
power = (dist + 0.05) * Ship.warp3;
percent = 100 * power / Ship.energy + 0.5;
- if (percent >= 85)
- {
- printf("Scotty: That would consume %d%% of our remaining energy.\n",
+ if (percent >= 85) {
+ printf("Scotty: That would consume %d%% of our remaining "
+ "energy.\n",
percent);
if (!getynpar("Are you sure that is wise"))
return;
/* check to see that that value is not ridiculous */
percent = 100 * time / Now.time + 0.5;
- if (percent >= 85)
- {
+ if (percent >= 85) {
printf("Spock: That would take %d%% of our remaining time.\n",
percent);
if (!getynpar("Are you sure that is wise"))
}
/* compute how far we will go if we get damages */
- if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0))
- {
+ if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0)) {
frac = franf();
dist *= frac;
time *= frac;
- damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
+ repairs = (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20;
+ damage(WARP, repairs);
}
/* do the move */
sleep(2);
printf("Crew experiencing extreme sensory distortion\n");
sleep(4);
- if (ranf(100) >= 100 * dist)
- {
- return (printf("Equilibrium restored -- all systems normal\n"));
+ if (ranf(100) >= 100 * dist) {
+ printf("Equilibrium restored -- all systems normal\n");
+ return;
}
/* select a bizzare thing to happen to us */
percent = ranf(100);
- if (percent < 70)
- {
+ if (percent < 70) {
/* time warp */
- if (percent < 35 || !Game.snap)
- {
+ if (percent < 35 || !Game.snap) {
/* positive time warp */
time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
Now.date += time;
- printf("Positive time portal entered -- it is now Stardate %.2f\n",
+ printf("Positive time portal entered -- "
+ "it is now Stardate %.2f\n",
Now.date);
- for (i = 0; i < MAXEVENTS; i++)
- {
+ for (i = 0; i < MAXEVENTS; i++) {
percent = Event[i].evcode;
if (percent == E_FIXDV || percent == E_LRTB)
Event[i].date += time;
/* s/he got lucky: a negative time portal */
time = Now.date;
- i = (int) Etc.snapshot;
- bmove(i, Quad, sizeof Quad);
- bmove(i += sizeof Quad, Event, sizeof Event);
- bmove(i += sizeof Event, &Now, sizeof Now);
- printf("Negative time portal entered -- it is now Stardate %.2f\n",
+ p = (char *) Etc.snapshot;
+ memcpy(p, Quad, sizeof Quad);
+ p += sizeof Quad;
+ memcpy(p, Event, sizeof Event);
+ p += sizeof Event;
+ memcpy(p, &Now, sizeof Now);
+ printf("Negative time portal entered -- "
+ "it is now Stardate %.2f\n",
Now.date);
for (i = 0; i < MAXEVENTS; i++)
if (Event[i].evcode == E_FIXDV)
/* test for just a lot of damage */
if (percent < 80)
lose(L_TOOFAST);
- printf("Equilibrium restored -- extreme damage occured to ship systems\n");
+ printf("Equilibrium restored -- "
+ "extreme damage occurred to ship systems\n");
for (i = 0; i < NDEV; i++)
damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
Ship.shldup = 0;