├── .gitignore ├── USD.doc ├── paper.pdf └── spell.ok ├── .travis.yml ├── DOC ├── things └── read_me.nr ├── README.md ├── Makefile ├── cgetc.c ├── ranf.c ├── out.c ├── getpar.h ├── damaged.c ├── systemname.c ├── getcodi.c ├── setwarp.c ├── check_out.c ├── dumpssradio.c ├── utility.c ├── lose.c ├── impulse.c ├── rest.c ├── dumpme.c ├── externs.c ├── autover.c ├── win.c ├── damage.c ├── visual.c ├── dcrept.c ├── ram.c ├── compkl.c ├── lrscan.c ├── score.c ├── checkcond.c ├── play.c ├── trek.6 ├── capture.c ├── destruct.c ├── nova.c ├── shield.c ├── initquad.c ├── dock.c ├── schedule.c ├── dumpgame.c ├── snova.c ├── help.c ├── abandon.c ├── srscan.c ├── klmove.c ├── kill.c ├── attack.c ├── warp.c ├── getpar.c ├── torped.c ├── move.c ├── main.c └── setup.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | trek 3 | -------------------------------------------------------------------------------- /USD.doc/paper.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jj1bdx/bsdtrek/HEAD/USD.doc/paper.pdf -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | notifications: 3 | email: false 4 | before_install: sudo apt-get install pmake 5 | script: pmake CFLAGS="-g -O2 -pipe" 6 | install: true 7 | compiler: 8 | - clang 9 | - gcc 10 | -------------------------------------------------------------------------------- /DOC/things: -------------------------------------------------------------------------------- 1 | * tractor beams 2 | * power distribution 3 | * Romulans: 4 | - plasma bolts 5 | - neutral zone 6 | - cloaking device 7 | * the thing 8 | * ion storms 9 | * torpedoes with time delays 10 | * Put removal from event list into killk 11 | -------------------------------------------------------------------------------- /USD.doc/spell.ok: -------------------------------------------------------------------------------- 1 | Allman 2 | Faire 3 | Klingon 4 | Klingons 5 | L.R 6 | Onboard 7 | Queene 8 | S.R 9 | Spock 10 | Starbase 11 | Starbases 12 | Stardate 13 | Starsystem 14 | TO:02:06:12 15 | Torpedoes 16 | Trek''USD:34 17 | U.S.S 18 | USD:34 19 | XII 20 | amt1 21 | anual 22 | arp 23 | atus 24 | ca 25 | ck 26 | cl 27 | course1 28 | da 29 | dist 30 | distresslist 31 | ds 32 | es 33 | est 34 | filename 35 | fo 36 | ft 37 | hasers 38 | ields 39 | impcost 40 | isual 41 | lrscan 42 | mages 43 | mo 44 | mov 45 | mpulse 46 | na 47 | ndock 48 | omputer 49 | onboard 50 | orpedo 51 | ove 52 | partway 53 | pheff 54 | pture 55 | rscan 56 | shuttlecraft 57 | spread1 58 | srscan 59 | st 60 | starbase 61 | starbases 62 | stardate 63 | stardates 64 | starsystem 65 | starsystems 66 | ta 67 | torpedoes 68 | trek.me 69 | utomatic 70 | warpcost 71 | woops 72 | x,y 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bsdtrek 2 | ======== 3 | 4 | This Star Trak game is originally from FreeBSD, with minimal change to build on Linux with pmake too. 5 | 6 | ## Travis CI build status for the master branch 7 | 8 | [![Build Status](https://travis-ci.org/jj1bdx/bsdtrek.svg?branch=master)](https://travis-ci.org/jj1bdx/bsdtrek) 9 | 10 | ## FreeBSD `trek` source code 11 | 12 | * Based on the ports [SVN revision r362720](http://svnweb.freebsd.org/ports/head/games/bsdgames/Makefile?revision=362720&view=markup) (tagged bsdtrek\_dragonflybsd\_3.8.1) 13 | * See also 14 | 15 | ## On OS X 16 | 17 | * Use `bsdmake` from MacPorts or Homebrew 18 | * setrlimit error message patch required 19 | * Tested on OS X 10.10.1 Yosemite 20 | 21 | ## On Ubuntu (and Travis CI) 22 | 23 | * Require `sudo apt-get install pmake` and use `pmake` instead of `make` 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # @(#)Makefile 8.1 (Berkeley) 5/31/93 2 | # $FreeBSD: src/games/trek/Makefile,v 1.1.1.1.14.1 2001/04/25 09:29:03 ru Exp $ 3 | # $DragonFly: src/games/trek/Makefile,v 1.4 2006/10/08 16:22:36 pavalos Exp $ 4 | 5 | PROG= trek 6 | SRCS= abandon.c attack.c autover.c capture.c check_out.c checkcond.c \ 7 | compkl.c computer.c damage.c damaged.c dcrept.c destruct.c \ 8 | dock.c dumpgame.c dumpme.c dumpssradio.c events.c externs.c \ 9 | getcodi.c getpar.c help.c impulse.c initquad.c kill.c klmove.c \ 10 | lose.c lrscan.c main.c move.c nova.c out.c phaser.c play.c ram.c \ 11 | ranf.c rest.c schedule.c score.c setup.c setwarp.c \ 12 | shield.c snova.c srscan.c systemname.c torped.c utility.c \ 13 | visual.c warp.c win.c cgetc.c 14 | MAN= trek.6 15 | DPADD= ${LIBM} 16 | LDADD= -lm 17 | HIDEGAME=hidegame 18 | 19 | CFLAGS= -g -O2 -pipe -std=c99 -D_XOPEN_SOURCE=600 -pedantic -Wall -Wno-error=unused-result 20 | 21 | .include 22 | -------------------------------------------------------------------------------- /cgetc.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)cgetc.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/cgetc.c,v 1.2 1999/11/30 03:49:44 billf Exp $ 31 | * $DragonFly: src/games/trek/cgetc.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | int 37 | cgetc(int i __unused) 38 | { 39 | return (getchar()); 40 | } 41 | -------------------------------------------------------------------------------- /ranf.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)ranf.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/ranf.c,v 1.3 1999/11/30 03:49:53 billf Exp $ 31 | * $DragonFly: src/games/trek/ranf.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | int 37 | ranf(int max) 38 | { 39 | if (max <= 0) 40 | return (0); 41 | return (random() % max); 42 | } 43 | 44 | double 45 | franf(void) 46 | { 47 | double t; 48 | t = random() & 077777; 49 | return (t / 32767.0); 50 | } 51 | -------------------------------------------------------------------------------- /out.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)out.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/out.c,v 1.4 1999/11/30 03:49:52 billf Exp $ 31 | * $DragonFly: src/games/trek/out.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Announce Device Out 38 | */ 39 | 40 | void 41 | out(int dev) 42 | { 43 | struct device *d; 44 | 45 | d = &Device[dev]; 46 | printf("%s reports %s ", d->person, d->name); 47 | if (d->name[strlen(d->name) - 1] == 's') 48 | printf("are"); 49 | else 50 | printf("is"); 51 | printf(" damaged\n"); 52 | } 53 | -------------------------------------------------------------------------------- /getpar.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)getpar.h 8.1 (Berkeley) 5/31/93 30 | * $DragonFly: src/games/trek/getpar.h,v 1.2 2006/09/07 21:19:44 pavalos Exp $ 31 | */ 32 | 33 | #include 34 | 35 | typedef void (*cmdfun)(int); 36 | 37 | /* used for getcodpar() parameter list */ 38 | struct cvntab { 39 | const char *abrev; 40 | const char *full; 41 | cmdfun value; 42 | int value2; 43 | }; 44 | 45 | extern struct cvntab Skitab[]; 46 | extern struct cvntab Lentab[]; 47 | 48 | int getintpar(const char *); 49 | double getfltpar(const char *); 50 | long getynpar(const char *); 51 | struct cvntab *getcodpar(const char *, struct cvntab[]); 52 | void getstrpar(const char *, char *, int, const char *); 53 | bool testnl(void); 54 | void skiptonl(char); 55 | bool readdelim(char); 56 | -------------------------------------------------------------------------------- /damaged.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)damaged.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/damaged.c,v 1.4 1999/11/30 03:49:45 billf Exp $ 31 | * $DragonFly: src/games/trek/damaged.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* DAMAGED -- check for device damaged 37 | ** 38 | ** This is a boolean function which returns non-zero if the 39 | ** specified device is broken. It does this by checking the 40 | ** event list for a "device fix" action on that device. 41 | */ 42 | 43 | bool 44 | damaged(int dev) 45 | { 46 | int d; 47 | struct event *e; 48 | int i; 49 | 50 | d = dev; 51 | 52 | for (i = 0; i < MAXEVENTS; i++) { 53 | e = &Event[i]; 54 | if (e->evcode != E_FIXDV) 55 | continue; 56 | if (e->systemname == d) 57 | return (1); 58 | } 59 | 60 | /* device fix not in event list -- device must not be broken */ 61 | return (0); 62 | } 63 | -------------------------------------------------------------------------------- /systemname.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)systemname.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/systemname.c,v 1.4 1999/11/30 03:49:55 billf Exp $ 31 | * $DragonFly: src/games/trek/systemname.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** RETRIEVE THE STARSYSTEM NAME 38 | ** 39 | ** Very straightforward, this routine just gets the starsystem 40 | ** name. It returns zero if none in the specified quadrant 41 | ** (which, by the way, is passed it). 42 | ** 43 | ** This routine knows all about such things as distressed 44 | ** starsystems, etc. 45 | */ 46 | 47 | const char * 48 | systemname(struct quad *q1) 49 | { 50 | struct quad *q; 51 | int i; 52 | 53 | q = q1; 54 | 55 | i = q->qsystemname; 56 | if (i & Q_DISTRESSED) 57 | i = Event[i & Q_SYSTEM].systemname; 58 | 59 | i &= Q_SYSTEM; 60 | if (i == 0) 61 | return (NULL); 62 | return (Systemname[i]); 63 | } 64 | -------------------------------------------------------------------------------- /getcodi.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)getcodi.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/getcodi.c,v 1.2 1999/11/30 03:49:48 billf Exp $ 31 | * $DragonFly: src/games/trek/getcodi.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "getpar.h" 35 | #include "trek.h" 36 | 37 | /* 38 | ** get course and distance 39 | ** 40 | ** The user is asked for a course and distance. This is used by 41 | ** move, impulse, and some of the computer functions. 42 | ** 43 | ** The return value is zero for success, one for an invalid input 44 | ** (meaning to drop the request). 45 | */ 46 | 47 | bool 48 | getcodi(int *co, double *di) 49 | { 50 | 51 | *co = getintpar("Course"); 52 | 53 | /* course must be in the interval [0, 360] */ 54 | if (*co < 0 || *co > 360) 55 | return (1); 56 | *di = getfltpar("Distance"); 57 | 58 | /* distance must be in the interval [0, 15] */ 59 | if (*di <= 0.0 || *di > 15.0) 60 | return (1); 61 | 62 | /* good return */ 63 | return (0); 64 | } 65 | -------------------------------------------------------------------------------- /setwarp.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)setwarp.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/setwarp.c,v 1.2 1999/11/30 03:49:54 billf Exp $ 31 | * $DragonFly: src/games/trek/setwarp.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** SET WARP FACTOR 39 | ** 40 | ** The warp factor is set for future move commands. It is 41 | ** checked for consistancy. 42 | */ 43 | 44 | void 45 | setwarp(int v __unused) 46 | { 47 | double warpfac; 48 | 49 | warpfac = getfltpar("Warp factor"); 50 | if (warpfac < 0.0) 51 | return; 52 | if (warpfac < 1.0) { 53 | printf("Minimum warp speed is 1.0\n"); 54 | return; 55 | } 56 | if (warpfac > 10.0) { 57 | printf("Maximum speed is warp 10.0\n"); 58 | return; 59 | } 60 | if (warpfac > 6.0) 61 | printf("Damage to warp engines may occur above warp 6.0\n"); 62 | Ship.warp = warpfac; 63 | Ship.warp2 = Ship.warp * warpfac; 64 | Ship.warp3 = Ship.warp2 * warpfac; 65 | } 66 | -------------------------------------------------------------------------------- /check_out.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)check_out.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/check_out.c,v 1.4 1999/11/30 03:49:44 billf Exp $ 31 | * $DragonFly: src/games/trek/check_out.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** CHECK IF A DEVICE IS OUT 38 | ** 39 | ** The indicated device is checked to see if it is disabled. If 40 | ** it is, an attempt is made to use the starbase device. If both 41 | ** of these fails, it returns non-zero (device is REALLY out), 42 | ** otherwise it returns zero (I can get to it somehow). 43 | ** 44 | ** It prints appropriate messages too. 45 | */ 46 | 47 | bool 48 | check_out(int device) 49 | { 50 | int dev; 51 | 52 | dev = device; 53 | 54 | /* check for device ok */ 55 | if (!damaged(dev)) 56 | return (0); 57 | 58 | /* report it as being dead */ 59 | out(dev); 60 | 61 | /* but if we are docked, we can go ahead anyhow */ 62 | if (Ship.cond != DOCKED) 63 | return (1); 64 | printf(" Using starbase %s\n", Device[dev].name); 65 | return (0); 66 | } 67 | -------------------------------------------------------------------------------- /dumpssradio.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)dumpssradio.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/dumpssradio.c,v 1.4 1999/11/30 03:49:47 billf Exp $ 31 | * $DragonFly: src/games/trek/dumpssradio.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /** 37 | ** output hidden distress calls 38 | **/ 39 | 40 | int 41 | dumpssradio(void) 42 | { 43 | struct event *e; 44 | int j; 45 | int chkrest; 46 | 47 | chkrest = 0; 48 | for (j = 0; j < MAXEVENTS; j++) { 49 | e = &Event[j]; 50 | /* if it is not hidden, then just ignore it */ 51 | if ((e->evcode & E_HIDDEN) == 0) 52 | continue; 53 | if (e->evcode & E_GHOST) { 54 | unschedule(e); 55 | printf("Starsystem %s in quadrant %d,%d is no longer distressed\n", 56 | systemname(&Quad[e->x][e->y]), e->x, e->y); 57 | continue; 58 | } 59 | 60 | switch (e->evcode) { 61 | 62 | case E_KDESB: 63 | printf("Starbase in quadrant %d,%d is under attack\n", 64 | e->x, e->y); 65 | chkrest++; 66 | break; 67 | 68 | case E_ENSLV: 69 | case E_REPRO: 70 | printf("Starsystem %s in quadrant %d,%d is distressed\n", 71 | systemname(&Quad[e->x][e->y]), e->x, e->y); 72 | chkrest++; 73 | break; 74 | 75 | } 76 | } 77 | 78 | return (chkrest); 79 | } 80 | -------------------------------------------------------------------------------- /utility.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)utility.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/utility.c,v 1.5 1999/11/30 03:49:55 billf Exp $ 31 | * $DragonFly: src/games/trek/utility.c,v 1.4 2006/09/07 21:19:45 pavalos Exp $ 32 | */ 33 | 34 | #include 35 | #include 36 | #include "trek.h" 37 | 38 | /* 39 | ** ASSORTED UTILITY ROUTINES 40 | */ 41 | 42 | /* 43 | ** BLOCK MOVE 44 | ** 45 | ** Moves a block of storage of length `l' bytes from the data 46 | ** area pointed to by `a' to the area pointed to by `b'. 47 | ** Returns the address of the byte following the `b' field. 48 | ** Overflow of `b' is not tested. 49 | */ 50 | 51 | char * 52 | bmove(const void *a, void *b, size_t l) 53 | { 54 | return((char *)memcpy(b, a, l) + l); 55 | } 56 | 57 | 58 | /* 59 | ** STRING EQUALITY TEST 60 | ** null-terminated strings `a' and `b' are tested for 61 | ** absolute equality. 62 | ** returns one if equal, zero otherwise. 63 | */ 64 | 65 | bool 66 | sequal(const char *a, const char *b) 67 | { 68 | return(!strcmp(a, b)); 69 | } 70 | 71 | 72 | /* 73 | ** SYSTEM ERROR 74 | */ 75 | 76 | void 77 | syserr(const char *fmt, ...) 78 | { 79 | va_list ap; 80 | 81 | va_start(ap, fmt); 82 | printf("\n\07TREK SYSERR: "); 83 | vprintf(fmt, ap); 84 | printf("\n"); 85 | if (errno) 86 | printf("\tsystem error %d\n", errno); 87 | va_end(ap); 88 | exit(1); 89 | } 90 | -------------------------------------------------------------------------------- /lose.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)lose.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/lose.c,v 1.2 1999/11/30 03:49:49 billf Exp $ 31 | * $DragonFly: src/games/trek/lose.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** PRINT OUT LOSER MESSAGES 39 | ** 40 | ** The messages are printed out, the score is computed and 41 | ** printed, and the game is restarted. Oh yeh, any special 42 | ** actions which need be taken are taken. 43 | */ 44 | 45 | const char *Losemsg[] = { 46 | "You ran out of time", 47 | "You ran out of energy", 48 | "You have been destroyed", 49 | "You ran into the negative energy barrier", 50 | "You destroyed yourself by nova'ing that star", 51 | "You have been caught in a supernova", 52 | "You just suffocated in outer space", 53 | "You could not be rematerialized", 54 | "\n\032\014 ***\07 Ship's hull has imploded\07 ***", 55 | "You have burned up in a star", 56 | "Well, you destroyed yourself, but it didn't do any good", 57 | "You have been captured by Klingons and mercilessly tortured", 58 | "Your last crew member died", 59 | }; 60 | 61 | void 62 | lose(int why) 63 | { 64 | Game.killed = 1; 65 | sleep(1); 66 | printf("\n%s\n", Losemsg[why - 1]); 67 | switch (why) { 68 | case L_NOTIME: 69 | Game.killed = 0; 70 | break; 71 | } 72 | Move.endgame = -1; 73 | score(); 74 | skiptonl(0); 75 | longjmp(env, 1); 76 | } 77 | -------------------------------------------------------------------------------- /impulse.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)impulse.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/impulse.c,v 1.4 1999/11/30 03:49:48 billf Exp $ 31 | * $DragonFly: src/games/trek/impulse.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "getpar.h" 35 | #include "trek.h" 36 | 37 | /** 38 | ** move under impulse power 39 | **/ 40 | 41 | void 42 | impulse(int v __unused) 43 | { 44 | int course; 45 | int power; 46 | double dist, p_time; 47 | int percent; 48 | 49 | if (Ship.cond == DOCKED) { 50 | printf("Scotty: Sorry captain, but we are still docked.\n"); 51 | return; 52 | } 53 | if (damaged(IMPULSE)) { 54 | out(IMPULSE); 55 | return; 56 | } 57 | if (getcodi(&course, &dist)) 58 | return; 59 | power = 20 + 100 * dist; 60 | percent = 100 * power / Ship.energy + 0.5; 61 | if (percent >= 85) { 62 | printf("Scotty: That would consume %d%% of our remaining energy.\n", 63 | percent); 64 | if (!getynpar("Are you sure that is wise")) 65 | return; 66 | printf("Aye aye, sir\n"); 67 | } 68 | p_time = dist / 0.095; 69 | percent = 100 * p_time / Now.time + 0.5; 70 | if (percent >= 85) { 71 | printf("Spock: That would take %d%% of our remaining time.\n", 72 | percent); 73 | if (!getynpar("Are you sure that is wise")) 74 | return; 75 | printf("(He's finally gone mad)\n"); 76 | } 77 | Move.time = move(0, course, p_time, 0.095); 78 | Ship.energy -= 20 + 100 * Move.time * 0.095; 79 | } 80 | -------------------------------------------------------------------------------- /rest.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)rest.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/rest.c,v 1.4 1999/11/30 03:49:53 billf Exp $ 31 | * $DragonFly: src/games/trek/rest.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** REST FOR REPAIRS 39 | ** 40 | ** You sit around and wait for repairs to happen. Actually, you 41 | ** sit around and wait for anything to happen. I do want to point 42 | ** out however, that Klingons are not as patient as you are, and 43 | ** they tend to attack you while you are resting. 44 | ** 45 | ** You can never rest through a long range tractor beam. 46 | ** 47 | ** In events() you will be given an opportunity to cancel the 48 | ** rest period if anything momentous happens. 49 | */ 50 | 51 | void 52 | rest(int v __unused) 53 | { 54 | double t; 55 | int percent; 56 | 57 | /* get the time to rest */ 58 | t = getfltpar("How long"); 59 | if (t <= 0.0) 60 | return; 61 | percent = 100 * t / Now.time + 0.5; 62 | if (percent >= 70) { 63 | printf("Spock: That would take %d%% of our remaining time.\n", 64 | percent); 65 | if (!getynpar("Are you really certain that is wise")) 66 | return; 67 | } 68 | Move.time = t; 69 | 70 | /* boundary condition is the LRTB */ 71 | t = Now.eventptr[E_LRTB]->date - Now.date; 72 | if (Ship.cond != DOCKED && Move.time > t) 73 | Move.time = t + 0.0001; 74 | Move.free = 0; 75 | Move.resting = 1; 76 | } 77 | -------------------------------------------------------------------------------- /dumpme.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)dumpme.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/dumpme.c,v 1.4 1999/11/30 03:49:47 billf Exp $ 31 | * $DragonFly: src/games/trek/dumpme.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Dump the starship somewhere in the galaxy 38 | ** 39 | ** Parameter is zero if bounce off of negative energy barrier, 40 | ** one if through a black hole 41 | ** 42 | ** Note that the quadrant is NOT initialized here. This must 43 | ** be done from the calling routine. 44 | ** 45 | ** Repair of devices must be deferred. 46 | */ 47 | 48 | void 49 | dumpme(int flag) 50 | { 51 | int f; 52 | double x = 0; 53 | struct event *e; 54 | int i; 55 | 56 | f = flag; 57 | Ship.quadx = ranf(NQUADS); 58 | Ship.quady = ranf(NQUADS); 59 | Ship.sectx = ranf(NSECTS); 60 | Ship.secty = ranf(NSECTS); 61 | x += 1.5 * franf(); 62 | Move.time += x; 63 | if (f) { 64 | printf("%s falls into a black hole.\n", Ship.shipname); 65 | } else { 66 | printf("Computer applies full reverse power to avoid hitting the\n"); 67 | printf(" negative energy barrier. A space warp was entered.\n"); 68 | } 69 | /* bump repair dates forward */ 70 | for (i = 0; i < MAXEVENTS; i++) { 71 | e = &Event[i]; 72 | if (e->evcode != E_FIXDV) 73 | continue; 74 | reschedule(e, (e->date - Now.date) + x); 75 | } 76 | events(1); 77 | printf("You are now in quadrant %d,%d. It is stardate %.2f\n", 78 | Ship.quadx, Ship.quady, Now.date); 79 | Move.time = 0; 80 | } 81 | -------------------------------------------------------------------------------- /externs.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)externs.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/externs.c,v 1.2 1999/11/30 03:49:47 billf Exp $ 31 | * $DragonFly: src/games/trek/externs.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** global variable definitions 38 | */ 39 | 40 | struct device Device[NDEV] = { 41 | { "warp drive", "Scotty" }, 42 | { "S.R. scanners", "Scotty" }, 43 | { "L.R. scanners", "Scotty" }, 44 | { "phasers", "Sulu" }, 45 | { "photon tubes", "Sulu" }, 46 | { "impulse engines", "Scotty" }, 47 | { "shield control", "Sulu" }, 48 | { "computer", "Spock" }, 49 | { "subspace radio", "Uhura" }, 50 | { "life support", "Scotty" }, 51 | { "navigation system", "Chekov" }, 52 | { "cloaking device", "Scotty" }, 53 | { "transporter", "Scotty" }, 54 | { "shuttlecraft", "Scotty" }, 55 | { "*ERR 14*", "Nobody" }, 56 | { "*ERR 15*", "Nobody" } 57 | }; 58 | 59 | const char *Systemname[NINHAB] = { 60 | "ERROR", 61 | "Talos IV", 62 | "Rigel III", 63 | "Deneb VII", 64 | "Canopus V", 65 | "Icarus I", 66 | "Prometheus II", 67 | "Omega VII", 68 | "Elysium I", 69 | "Scalos IV", 70 | "Procyon IV", 71 | "Arachnid I", 72 | "Argo VIII", 73 | "Triad III", 74 | "Echo IV", 75 | "Nimrod III", 76 | "Nemisis IV", 77 | "Centarurus I", 78 | "Kronos III", 79 | "Spectros V", 80 | "Beta III", 81 | "Gamma Tranguli VI", 82 | "Pyris III", 83 | "Triachus", 84 | "Marcus XII", 85 | "Kaland", 86 | "Ardana", 87 | "Stratos", 88 | "Eden", 89 | "Arrikis", 90 | "Epsilon Eridani IV", 91 | "Exo III" 92 | }; 93 | -------------------------------------------------------------------------------- /autover.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)autover.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/autover.c,v 1.4 1999/11/30 03:49:43 billf Exp $ 31 | * $DragonFly: src/games/trek/autover.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Automatic Override 38 | ** 39 | ** If we should be so unlucky as to be caught in a quadrant 40 | ** with a supernova in it, this routine is called. It is 41 | ** called from checkcond(). 42 | ** 43 | ** It sets you to a random warp (guaranteed to be over 6.0) 44 | ** and starts sending you off "somewhere" (whereever that is). 45 | ** 46 | ** Please note that it is VERY important that you reset your 47 | ** warp speed after the automatic override is called. The new 48 | ** warp factor does not stay in effect for just this routine. 49 | ** 50 | ** This routine will never try to send you more than sqrt(2) 51 | ** quadrants, since that is all that is needed. 52 | */ 53 | 54 | void 55 | autover(void) 56 | { 57 | double dist; 58 | int course; 59 | 60 | printf("\07RED ALERT: The %s is in a supernova quadrant\n", 61 | Ship.shipname); 62 | printf("*** Emergency override attempts to hurl %s to safety\n", 63 | Ship.shipname); 64 | /* let's get our ass out of here */ 65 | Ship.warp = 6.0 + 2.0 * franf(); 66 | Ship.warp2 = Ship.warp * Ship.warp; 67 | Ship.warp3 = Ship.warp2 * Ship.warp; 68 | dist = 0.75 * Ship.energy / (Ship.warp3 * (Ship.shldup + 1)); 69 | if (dist > 1.4142) 70 | dist = 1.4142; 71 | course = ranf(360); 72 | Etc.nkling = -1; 73 | Ship.cond = RED; 74 | warp(-1, course, dist); 75 | attack(0); 76 | } 77 | -------------------------------------------------------------------------------- /win.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)win.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/win.c,v 1.4 1999/11/30 03:49:56 billf Exp $ 31 | * $DragonFly: src/games/trek/win.c,v 1.3 2006/09/07 21:19:45 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** Signal game won 39 | ** 40 | ** This routine prints out the win message, arranges to print out 41 | ** your score, tells you if you have a promotion coming to you, 42 | ** cleans up the current input line, and arranges to have you 43 | ** asked whether or not you want another game (via the longjmp() 44 | ** call). 45 | ** 46 | ** Pretty straightforward, although the promotion algorithm is 47 | ** pretty off the wall. 48 | */ 49 | 50 | void 51 | win(void) 52 | { 53 | long s; 54 | struct cvntab *p; 55 | 56 | sleep(1); 57 | printf("\nCongratulations, you have saved the Federation\n"); 58 | Move.endgame = 1; 59 | 60 | /* print and return the score */ 61 | s = score(); 62 | 63 | /* decide if she gets a promotion */ 64 | if (Game.helps == 0 && Game.killb == 0 && Game.killinhab == 0 && 65 | 5 * Game.kills + Game.deaths < 100 && 66 | s >= 1000 && Ship.ship == ENTERPRISE) { 67 | printf("In fact, you are promoted one step in rank,\n"); 68 | if (Game.skill >= 6) { 69 | printf("to the exalted rank of Commodore Emeritus\n"); 70 | } else { 71 | p = &Skitab[Game.skill - 1]; 72 | printf("from %s%s ", p->abrev, p->full); 73 | p++; 74 | printf("to %s%s\n", p->abrev, p->full); 75 | } 76 | } 77 | 78 | /* clean out input, and request new game */ 79 | skiptonl(0); 80 | longjmp(env, 1); 81 | } 82 | -------------------------------------------------------------------------------- /damage.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)damage.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/damage.c,v 1.4 1999/11/30 03:49:45 billf Exp $ 31 | * $DragonFly: src/games/trek/damage.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Schedule Ship.damages to a Device 38 | ** 39 | ** Device `dev1' is damaged in an amount `dam'. Dam is measured 40 | ** in stardates, and is an additional amount of damage. It should 41 | ** be the amount to occur in non-docked mode. The adjustment 42 | ** to docked mode occurs automatically if we are docked. 43 | ** 44 | ** Note that the repair of the device occurs on a DATE, meaning 45 | ** that the dock() and undock() have to reschedule the event. 46 | */ 47 | 48 | void 49 | damage(int dev1, double dam) 50 | { 51 | int i; 52 | struct event *e; 53 | int f; 54 | int dev; 55 | 56 | /* ignore zero damages */ 57 | if (dam <= 0.0) 58 | return; 59 | dev = dev1; 60 | 61 | printf("\t%s damaged\n", Device[dev].name); 62 | 63 | /* find actual length till it will be fixed */ 64 | if (Ship.cond == DOCKED) 65 | dam *= Param.dockfac; 66 | /* set the damage flag */ 67 | f = damaged(dev); 68 | if (!f) { 69 | /* new damages -- schedule a fix */ 70 | schedule(E_FIXDV, dam, 0, 0, dev); 71 | return; 72 | } 73 | /* device already damaged -- add to existing damages */ 74 | /* scan for old damages */ 75 | for (i = 0; i < MAXEVENTS; i++) { 76 | e = &Event[i]; 77 | if (e->evcode != E_FIXDV || e->systemname != dev) 78 | continue; 79 | /* got the right one; add on the new damages */ 80 | reschedule(e, e->date - Now.date + dam); 81 | return; 82 | } 83 | syserr("Cannot find old damages %d\n", dev); 84 | } 85 | -------------------------------------------------------------------------------- /visual.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)visual.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/visual.c,v 1.4 1999/11/30 03:49:56 billf Exp $ 31 | * $DragonFly: src/games/trek/visual.c,v 1.3 2006/09/07 21:19:45 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** VISUAL SCAN 39 | ** 40 | ** A visual scan is made in a particular direction of three sectors 41 | ** in the general direction specified. This takes time, and 42 | ** Klingons can attack you, so it should be done only when sensors 43 | ** are out. 44 | */ 45 | 46 | /* This struct[] has the delta x, delta y for particular directions */ 47 | struct xy Visdelta[11] = { 48 | { -1, -1 }, 49 | { -1, 0 }, 50 | { -1, 1 }, 51 | { 0, 1 }, 52 | { 1, 1 }, 53 | { 1, 0 }, 54 | { 1, -1 }, 55 | { 0, -1 }, 56 | { -1, -1 }, 57 | { -1, 0 }, 58 | { -1, 1 } 59 | }; 60 | 61 | void 62 | visual(int z __unused) 63 | { 64 | int ix, iy; 65 | int co; 66 | struct xy *v; 67 | 68 | co = getintpar("direction"); 69 | if (co < 0 || co > 360) 70 | return; 71 | co = (co + 22) / 45; 72 | v = &Visdelta[co]; 73 | ix = Ship.sectx + v->x; 74 | iy = Ship.secty + v->y; 75 | if (ix < 0 || ix >= NSECTS || iy < 0 || iy >= NSECTS) 76 | co = '?'; 77 | else 78 | co = Sect[ix][iy]; 79 | printf("%d,%d %c ", ix, iy, co); 80 | v++; 81 | ix = Ship.sectx + v->x; 82 | iy = Ship.secty + v->y; 83 | if (ix < 0 || ix >= NSECTS || iy < 0 || iy >= NSECTS) 84 | co = '?'; 85 | else 86 | co = Sect[ix][iy]; 87 | printf("%c ", co); 88 | v++; 89 | ix = Ship.sectx + v->x; 90 | iy = Ship.secty + v->y; 91 | if (ix < 0 || ix >= NSECTS || iy < 0 || iy >= NSECTS) 92 | co = '?'; 93 | else 94 | co = Sect[ix][iy]; 95 | printf("%c %d,%d\n", co, ix, iy); 96 | Move.time = 0.05; 97 | Move.free = 0; 98 | } 99 | -------------------------------------------------------------------------------- /dcrept.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)dcrept.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/dcrept.c,v 1.4 1999/11/30 03:49:46 billf Exp $ 31 | * $DragonFly: src/games/trek/dcrept.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** damage control report 38 | ** 39 | ** Print damages and time to fix. This is taken from the event 40 | ** list. A couple of factors are set up, based on whether or not 41 | ** we are docked. (One of these factors will always be 1.0.) 42 | ** The event list is then scanned for damage fix events, the 43 | ** time until they occur is determined, and printed out. The 44 | ** magic number DAMFAC is used to tell how much faster you can 45 | ** fix things if you are docked. 46 | */ 47 | 48 | void 49 | dcrept(int v __unused) 50 | { 51 | int i, f; 52 | double x; 53 | double m1, m2; 54 | struct event *e; 55 | 56 | /* set up the magic factors to output the time till fixed */ 57 | if (Ship.cond == DOCKED) { 58 | m1 = 1.0 / Param.dockfac; 59 | m2 = 1.0; 60 | } else { 61 | m1 = 1.0; 62 | m2 = Param.dockfac; 63 | } 64 | printf("Damage control report:\n"); 65 | f = 1; 66 | 67 | /* scan for damages */ 68 | for (i = 0; i < MAXEVENTS; i++) { 69 | e = &Event[i]; 70 | if (e->evcode != E_FIXDV) 71 | continue; 72 | 73 | /* output the title first time */ 74 | if (f) { 75 | printf("\t\t\t repair times\n"); 76 | printf("device\t\t\tin flight docked\n"); 77 | f = 0; 78 | } 79 | 80 | /* compute time till fixed, then adjust by the magic factors */ 81 | x = e->date - Now.date; 82 | printf("%-24s%7.2f %7.2f\n", 83 | Device[e->systemname].name, x * m1 + 0.005, x * m2 + 0.005); 84 | 85 | /* do a little consistancy checking */ 86 | } 87 | 88 | /* if everything was ok, reassure the nervous captain */ 89 | if (f) 90 | printf("All devices functional\n"); 91 | } 92 | -------------------------------------------------------------------------------- /ram.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)ram.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/ram.c,v 1.4 1999/11/30 03:49:53 billf Exp $ 31 | * $DragonFly: src/games/trek/ram.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** RAM SOME OBJECT 38 | ** 39 | ** You have run into some sort of object. It may be a Klingon, 40 | ** a star, or a starbase. If you run into a star, you are really 41 | ** stupid, because there is no hope for you. 42 | ** 43 | ** If you run into something else, you destroy that object. You 44 | ** also rack up incredible damages. 45 | */ 46 | 47 | void 48 | ram(int ix, int iy) 49 | { 50 | int i; 51 | char c; 52 | 53 | printf("\07RED ALERT\07: collision imminent\n"); 54 | c = Sect[ix][iy]; 55 | switch (c) { 56 | 57 | case KLINGON: 58 | printf("%s rams Klingon at %d,%d\n", Ship.shipname, ix, iy); 59 | killk(ix, iy); 60 | break; 61 | 62 | case STAR: 63 | case INHABIT: 64 | printf("Yeoman Rand: Captain, isn't it getting hot in here?\n"); 65 | sleep(2); 66 | printf("Spock: Hull temperature approaching 550 Degrees Kelvin.\n"); 67 | lose(L_STAR); 68 | 69 | case BASE: 70 | printf("You ran into the starbase at %d,%d\n", ix, iy); 71 | killb(Ship.quadx, Ship.quady); 72 | /* don't penalize the captain if it wasn't his fault */ 73 | if (!damaged(SINS)) 74 | Game.killb += 1; 75 | break; 76 | } 77 | sleep(2); 78 | printf("%s heavily damaged\n", Ship.shipname); 79 | 80 | /* select the number of deaths to occur */ 81 | i = 10 + ranf(20 * Game.skill); 82 | Game.deaths += i; 83 | Ship.crew -= i; 84 | printf("McCoy: Take it easy Jim; we had %d casualties.\n", i); 85 | 86 | /* damage devices with an 80% probability */ 87 | for (i = 0; i < NDEV; i++) { 88 | if (ranf(100) < 20) 89 | continue; 90 | damage(i, (2.5 * (franf() + franf()) + 1.0) * Param.damfac[i]); 91 | } 92 | 93 | /* no chance that your shields remained up in all that */ 94 | Ship.shldup = 0; 95 | } 96 | -------------------------------------------------------------------------------- /compkl.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)compkl.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/compkl.c,v 1.4 1999/11/30 03:49:44 billf Exp $ 31 | * $DragonFly: src/games/trek/compkl.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | static void sortkl(void); 37 | 38 | /* 39 | ** compute klingon distances 40 | ** 41 | ** The klingon list has the distances for all klingons recomputed 42 | ** and sorted. The parameter is a Boolean flag which is set if 43 | ** we have just entered a new quadrant. 44 | ** 45 | ** This routine is used every time the Enterprise or the Klingons 46 | ** move. 47 | */ 48 | 49 | void 50 | compkldist(bool f) 51 | { 52 | int i, dx, dy; 53 | double d; 54 | double temp; 55 | 56 | if (Etc.nkling == 0) 57 | return; 58 | for (i = 0; i < Etc.nkling; i++) { 59 | /* compute distance to the Klingon */ 60 | dx = Ship.sectx - Etc.klingon[i].x; 61 | dy = Ship.secty - Etc.klingon[i].y; 62 | d = dx * dx + dy * dy; 63 | d = sqrt(d); 64 | 65 | /* compute average of new and old distances to Klingon */ 66 | if (!f) { 67 | temp = Etc.klingon[i].dist; 68 | Etc.klingon[i].avgdist = 0.5 * (temp + d); 69 | } else { 70 | /* new quadrant: average is current */ 71 | Etc.klingon[i].avgdist = d; 72 | } 73 | Etc.klingon[i].dist = d; 74 | } 75 | 76 | /* leave them sorted */ 77 | sortkl(); 78 | } 79 | 80 | 81 | /* 82 | ** sort klingons 83 | ** 84 | ** bubble sort on ascending distance 85 | */ 86 | 87 | static void 88 | sortkl(void) 89 | { 90 | struct kling t; 91 | int f, i, m; 92 | 93 | m = Etc.nkling - 1; 94 | f = 1; 95 | while (f) { 96 | f = 0; 97 | for (i = 0; i < m; i++) { 98 | if (Etc.klingon[i].dist > Etc.klingon[i+1].dist) { 99 | bmove(&Etc.klingon[i], &t, sizeof t); 100 | bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof t); 101 | bmove(&t, &Etc.klingon[i+1], sizeof t); 102 | f = 1; 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /lrscan.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)lrscan.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/lrscan.c,v 1.4 1999/11/30 03:49:50 billf Exp $ 31 | * $DragonFly: src/games/trek/lrscan.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** LONG RANGE OF SCANNERS 38 | ** 39 | ** A summary of the quadrants that surround you is printed. The 40 | ** hundreds digit is the number of Klingons in the quadrant, 41 | ** the tens digit is the number of starbases, and the units digit 42 | ** is the number of stars. If the printout is "///" it means 43 | ** that that quadrant is rendered uninhabitable by a supernova. 44 | ** It also updates the "scanned" field of the quadrants it scans, 45 | ** for future use by the "chart" option of the computer. 46 | */ 47 | 48 | void 49 | lrscan(int v __unused) 50 | { 51 | int i, j; 52 | struct quad *q; 53 | 54 | if (check_out(LRSCAN)) { 55 | return; 56 | } 57 | printf("Long range scan for quadrant %d,%d\n\n", Ship.quadx, Ship.quady); 58 | 59 | /* print the header on top */ 60 | for (j = Ship.quady - 1; j <= Ship.quady + 1; j++) { 61 | if (j < 0 || j >= NQUADS) 62 | printf(" "); 63 | else 64 | printf(" %1d", j); 65 | } 66 | 67 | /* scan the quadrants */ 68 | for (i = Ship.quadx - 1; i <= Ship.quadx + 1; i++) { 69 | printf("\n -------------------\n"); 70 | if (i < 0 || i >= NQUADS) { 71 | /* negative energy barrier */ 72 | printf(" ! * ! * ! * !"); 73 | continue; 74 | } 75 | 76 | /* print the left hand margin */ 77 | printf("%1d !", i); 78 | for (j = Ship.quady - 1; j <= Ship.quady + 1; j++) { 79 | if (j < 0 || j >= NQUADS) { 80 | /* negative energy barrier again */ 81 | printf(" * !"); 82 | continue; 83 | } 84 | q = &Quad[i][j]; 85 | if (q->stars < 0) { 86 | /* supernova */ 87 | printf(" /// !"); 88 | q->scanned = 1000; 89 | continue; 90 | } 91 | q->scanned = q->klings * 100 + q->bases * 10 + q->stars; 92 | printf(" %3d !", q->scanned); 93 | } 94 | } 95 | printf("\n -------------------\n"); 96 | return; 97 | } 98 | -------------------------------------------------------------------------------- /score.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)score.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/score.c,v 1.4 1999/11/30 03:49:53 billf Exp $ 31 | * $DragonFly: src/games/trek/score.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** PRINT OUT THE CURRENT SCORE 39 | */ 40 | 41 | long 42 | score(void) 43 | { 44 | int u; 45 | int t; 46 | long s; 47 | double r; 48 | 49 | printf("\n*** Your score:\n"); 50 | s = t = Param.klingpwr / 4 * (u = Game.killk); 51 | if (t != 0) 52 | printf("%d Klingons killed\t\t\t%6d\n", u, t); 53 | r = Now.date - Param.date; 54 | if (r < 1.0) 55 | r = 1.0; 56 | r = Game.killk / r; 57 | s += (t = 400 * r); 58 | if (t != 0) 59 | printf("Kill rate %.2f Klingons/stardate \t%6d\n", r, t); 60 | r = Now.klings; 61 | r /= Game.killk + 1; 62 | s += (t = -400 * r); 63 | if (t != 0) 64 | printf("Penalty for %d klingons remaining\t%6d\n", Now.klings, t); 65 | if (Move.endgame > 0) { 66 | s += (t = 100 * (u = Game.skill)); 67 | printf("Bonus for winning a %s%s game\t\t%6d\n", Skitab[u - 1].abrev, Skitab[u - 1].full, t); 68 | } 69 | if (Game.killed) { 70 | s -= 500; 71 | printf("Penalty for getting killed\t\t -500\n"); 72 | } 73 | s += (t = -100 * (u = Game.killb)); 74 | if (t != 0) 75 | printf("%d starbases killed\t\t\t%6d\n", u, t); 76 | s += (t = -100 * (u = Game.helps)); 77 | if (t != 0) 78 | printf("%d calls for help\t\t\t%6d\n", u, t); 79 | s += (t = -5 * (u = Game.kills)); 80 | if (t != 0) 81 | printf("%d stars destroyed\t\t\t%6d\n", u, t); 82 | s += (t = -150 * (u = Game.killinhab)); 83 | if (t != 0) 84 | printf("%d inhabited starsystems destroyed\t%6d\n", u, t); 85 | if (Ship.ship != ENTERPRISE) { 86 | s -= 200; 87 | printf("penalty for abandoning ship\t\t -200\n"); 88 | } 89 | s += (t = 3 * (u = Game.captives)); 90 | if (t != 0) 91 | printf("%d Klingons captured\t\t\t%6d\n", u, t); 92 | s += (t = -(u = Game.deaths)); 93 | if (t != 0) 94 | printf("%d casualties\t\t\t\t%6d\n", u, t); 95 | printf("\n*** TOTAL\t\t\t%14ld\n", s); 96 | return (s); 97 | } 98 | -------------------------------------------------------------------------------- /checkcond.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)checkcond.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/checkcond.c,v 1.4 1999/11/30 03:49:44 billf Exp $ 31 | * $DragonFly: src/games/trek/checkcond.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Check for Condition After a Move 38 | ** 39 | ** Various ship conditions are checked. First we check 40 | ** to see if we have already lost the game, due to running 41 | ** out of life support reserves, running out of energy, 42 | ** or running out of crew members. The check for running 43 | ** out of time is in events(). 44 | ** 45 | ** If we are in automatic override mode (Etc.nkling < 0), we 46 | ** don't want to do anything else, lest we call autover 47 | ** recursively. 48 | ** 49 | ** In the normal case, if there is a supernova, we call 50 | ** autover() to help us escape. If after calling autover() 51 | ** we are still in the grips of a supernova, we get burnt 52 | ** up. 53 | ** 54 | ** If there are no Klingons in this quadrant, we nullify any 55 | ** distress calls which might exist. 56 | ** 57 | ** We then set the condition code, based on the energy level 58 | ** and battle conditions. 59 | */ 60 | 61 | void 62 | checkcond(void) 63 | { 64 | /* see if we are still alive and well */ 65 | if (Ship.reserves < 0.0) 66 | lose(L_NOLIFE); 67 | if (Ship.energy <= 0) 68 | lose(L_NOENGY); 69 | if (Ship.crew <= 0) 70 | lose(L_NOCREW); 71 | /* if in auto override mode, ignore the rest */ 72 | if (Etc.nkling < 0) 73 | return; 74 | /* call in automatic override if appropriate */ 75 | if (Quad[Ship.quadx][Ship.quady].stars < 0) 76 | autover(); 77 | if (Quad[Ship.quadx][Ship.quady].stars < 0) 78 | lose(L_SNOVA); 79 | /* nullify distress call if appropriate */ 80 | if (Etc.nkling <= 0) 81 | killd(Ship.quadx, Ship.quady, 1); 82 | 83 | /* set condition code */ 84 | if (Ship.cond == DOCKED) 85 | return; 86 | 87 | if (Etc.nkling > 0) { 88 | Ship.cond = RED; 89 | return; 90 | } 91 | if (Ship.energy < Param.energylow) { 92 | Ship.cond = YELLOW; 93 | return; 94 | } 95 | Ship.cond = GREEN; 96 | return; 97 | } 98 | -------------------------------------------------------------------------------- /play.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)play.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/play.c,v 1.2 1999/11/30 03:49:52 billf Exp $ 31 | * $DragonFly: src/games/trek/play.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | static void myreset(int); 38 | /* 39 | ** INSTRUCTION READ AND MAIN PLAY LOOP 40 | ** 41 | ** Well folks, this is it. Here we have the guts of the game. 42 | ** This routine executes moves. It sets up per-move variables, 43 | ** gets the command, and executes the command. After the command, 44 | ** it calls events() to use up time, attack() to have Klingons 45 | ** attack if the move was not free, and checkcond() to check up 46 | ** on how we are doing after the move. 47 | */ 48 | 49 | struct cvntab Comtab[] = { 50 | { "abandon", "", abandon, 0 }, 51 | { "ca", "pture", capture, 0 }, 52 | { "cl", "oak", shield, -1 }, 53 | { "c", "omputer", computer, 0 }, 54 | { "da", "mages", dcrept, 0 }, 55 | { "destruct", "", destruct, 0 }, 56 | { "do", "ck", dock, 0 }, 57 | { "help", "", help, 0 }, 58 | { "i", "mpulse", impulse, 0 }, 59 | { "l", "rscan", lrscan, 0 }, 60 | { "m", "ove", dowarp, 0 }, 61 | { "p", "hasers", phaser, 0 }, 62 | { "ram", "", dowarp, 1 }, 63 | { "dump", "", dumpgame, 0 }, 64 | { "r", "est", rest, 0 }, 65 | { "sh", "ield", shield, 0 }, 66 | { "s", "rscan", srscan, 0 }, 67 | { "st", "atus", srscan, -1 }, 68 | { "terminate", "", myreset, 0 }, 69 | { "t", "orpedo", torped, 0 }, 70 | { "u", "ndock", undock, 0 }, 71 | { "v", "isual", visual, 0 }, 72 | { "w", "arp", setwarp, 0 }, 73 | { NULL, NULL, NULL, 0 } 74 | }; 75 | 76 | static void 77 | myreset(int v __unused) 78 | { 79 | longjmp(env, 1); 80 | } 81 | 82 | void 83 | play(void) 84 | { 85 | struct cvntab *r; 86 | 87 | while (1) { 88 | Move.free = 1; 89 | Move.time = 0.0; 90 | Move.shldchg = 0; 91 | Move.newquad = 0; 92 | Move.resting = 0; 93 | skiptonl(0); 94 | r = getcodpar("\nCommand", Comtab); 95 | (*r->value)(r->value2); 96 | events(0); 97 | attack(0); 98 | checkcond(); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /trek.6: -------------------------------------------------------------------------------- 1 | .\" Copyright (c) 1980, 1993 2 | .\" The Regents of the University of California. All rights reserved. 3 | .\" 4 | .\" Redistribution and use in source and binary forms, with or without 5 | .\" modification, are permitted provided that the following conditions 6 | .\" are met: 7 | .\" 1. Redistributions of source code must retain the above copyright 8 | .\" notice, this list of conditions and the following disclaimer. 9 | .\" 2. Redistributions in binary form must reproduce the above copyright 10 | .\" notice, this list of conditions and the following disclaimer in the 11 | .\" documentation and/or other materials provided with the distribution. 12 | .\" 3. Neither the name of the University nor the names of its contributors 13 | .\" may be used to endorse or promote products derived from this software 14 | .\" without specific prior written permission. 15 | .\" 16 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | .\" SUCH DAMAGE. 27 | .\" 28 | .\" @(#)trek.6 8.2 (Berkeley) 12/30/93 29 | .\" $FreeBSD: src/games/trek/trek.6,v 1.4 1999/08/27 23:29:19 peter Exp $ 30 | .\" 31 | .Dd July 12, 2012 32 | .Dt TREK 6 33 | .Os 34 | .Sh NAME 35 | .Nm trek 36 | .Nd trekkie game 37 | .Sh SYNOPSIS 38 | .Nm 39 | .Sh DESCRIPTION 40 | .Nm Trek 41 | is a game of space glory and war. 42 | Below is a summary of commands. 43 | For complete documentation, see 44 | .Em Trek 45 | by Eric Allman. 46 | .Pp 47 | The game will ask you what length game you would like. 48 | Valid responses are 49 | .Dq short , 50 | .Dq medium , 51 | and 52 | .Dq long . 53 | You may also type 54 | .Dq restart , 55 | which restarts a previously saved game. 56 | You will then be prompted for the skill, to which you must respond 57 | .Dq novice , 58 | .Dq fair , 59 | .Dq good , 60 | .Dq expert , 61 | .Dq commodore , 62 | or 63 | .Dq impossible . 64 | You should normally start out with a novice and work up. 65 | .Pp 66 | In general, throughout the game, if you forget what is appropriate 67 | the game will tell you what it expects if you just type in a question mark. 68 | .Sh SEE ALSO 69 | .Rs 70 | .%A "Eric Allman" 71 | .%B "4.4BSD Users's Supplementary Documents (USD)" 72 | .%T "Star Trek" 73 | .Re 74 | .\" .Pa /usr/share/doc/usd/31.trek 75 | .Sh AUTHORS 76 | .An Eric Allman 77 | .Sh COMMAND SUMMARY 78 | .Bl -item -compact 79 | .It 80 | .Ic abandon 81 | .It 82 | .Ic ca Ns pture 83 | .It 84 | .Ic cl Ns oak 85 | .Ic u Ns p/ Ns Ic d Ns own 86 | .It 87 | .Ic c Ns omputer request; ... 88 | .It 89 | .Ic da Ns mages 90 | .It 91 | .Ic destruct 92 | .It 93 | .Ic do Ns ck 94 | .It 95 | .Ic help 96 | .It 97 | .Ic i Ns mpulse course distance 98 | .It 99 | .Ic l Ns rscan 100 | .It 101 | .Ic m Ns ove course distance 102 | .It 103 | .Ic p Ns hasers Ic a Ns utomatic 104 | amount 105 | .It 106 | .Ic p Ns hasers Ic m Ns anual 107 | amt1 course1 spread1 ... 108 | .It 109 | .Ic t Ns orpedo course 110 | .Op Ic y Ns es 111 | .No angle/ Ns Ic n Ns o 112 | .It 113 | .Ic ram No course distance 114 | .It 115 | .Ic r Ns est time 116 | .It 117 | .Ic shell 118 | .It 119 | .Ic sh Ns ields 120 | .Ic u Ns p/ Ns Ic d Ns own 121 | .It 122 | .Ic s Ns rscan 123 | .Op Ic y Ns es/ Ns Ic n Ns o 124 | .It 125 | .Ic st Ns atus 126 | .It 127 | .Ic terminate y Ns es/ Ns Ic n Ns o 128 | .It 129 | .Ic u Ns ndock 130 | .It 131 | .Ic v Ns isual course 132 | .It 133 | .Ic w Ns arp warp_factor 134 | .El 135 | -------------------------------------------------------------------------------- /capture.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)capture.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/capture.c,v 1.4 1999/11/30 03:49:43 billf Exp $ 31 | * $DragonFly: src/games/trek/capture.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | static struct kling *selectklingon(void); 37 | 38 | /* 39 | ** Ask a Klingon To Surrender 40 | ** 41 | ** (Fat chance) 42 | ** 43 | ** The Subspace Radio is needed to ask a Klingon if he will kindly 44 | ** surrender. A random Klingon from the ones in the quadrant is 45 | ** chosen. 46 | ** 47 | ** The Klingon is requested to surrender. The probability of this 48 | ** is a function of that Klingon's remaining power, our power, 49 | ** etc. 50 | */ 51 | 52 | void 53 | capture(int v __unused) 54 | { 55 | int i; 56 | struct kling *k; 57 | double x; 58 | 59 | /* check for not cloaked */ 60 | if (Ship.cloaked) { 61 | printf("Ship-ship communications out when cloaked\n"); 62 | return; 63 | } 64 | if (damaged(SSRADIO)) { 65 | out(SSRADIO); 66 | return; 67 | } 68 | /* find out if there are any at all */ 69 | if (Etc.nkling <= 0) { 70 | printf("Uhura: Getting no response, sir\n"); 71 | return; 72 | } 73 | 74 | /* if there is more than one Klingon, find out which one */ 75 | k = selectklingon(); 76 | Move.free = 0; 77 | Move.time = 0.05; 78 | 79 | /* check out that Klingon */ 80 | k->srndreq++; 81 | x = Param.klingpwr; 82 | x *= Ship.energy; 83 | x /= k->power * Etc.nkling; 84 | x *= Param.srndrprob; 85 | i = x; 86 | #ifdef xTRACE 87 | if (Trace) 88 | printf("Prob = %d (%.4f)\n", i, x); 89 | #endif 90 | if (i > ranf(100)) { 91 | /* guess what, he surrendered!!! */ 92 | printf("Klingon at %d,%d surrenders\n", k->x, k->y); 93 | i = ranf(Param.klingcrew); 94 | if ( i > 0 ) 95 | printf("%d klingons commit suicide rather than be taken captive\n", Param.klingcrew - i); 96 | if (i > Ship.brigfree) 97 | i = Ship.brigfree; 98 | Ship.brigfree -= i; 99 | printf("%d captives taken\n", i); 100 | killk(k->x, k->y); 101 | return; 102 | } 103 | 104 | /* big surprise, he refuses to surrender */ 105 | printf("Fat chance, captain\n"); 106 | return; 107 | } 108 | 109 | 110 | /* 111 | ** SELECT A KLINGON 112 | ** 113 | ** Cruddy, just takes one at random. Should ask the captain. 114 | */ 115 | 116 | static struct kling * 117 | selectklingon(void) 118 | { 119 | int i; 120 | 121 | if (Etc.nkling < 2) 122 | i = 0; 123 | else 124 | i = ranf(Etc.nkling); 125 | return (&Etc.klingon[i]); 126 | } 127 | -------------------------------------------------------------------------------- /destruct.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)destruct.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/destruct.c,v 1.4 1999/11/30 03:49:46 billf Exp $ 31 | * $DragonFly: src/games/trek/destruct.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "getpar.h" 35 | #include "trek.h" 36 | 37 | /* 38 | ** Self Destruct Sequence 39 | ** 40 | ** The computer starts up the self destruct sequence. Obviously, 41 | ** if the computer is out nothing can happen. You get a countdown 42 | ** and a request for password. This must match the password that 43 | ** you entered at the start of the game. 44 | ** 45 | ** You get to destroy things when you blow up; hence, it is 46 | ** possible to win the game by destructing if you take the last 47 | ** Klingon with you. 48 | ** 49 | ** By the way, the \032 in the message is a ^Z, which is because 50 | ** the terminal in my office is an ADM-3, which uses that char- 51 | ** acter to clear the screen. I also stick in a \014 (form feed) 52 | ** because that clears some other screens. 53 | ** 54 | ** Uses trace flag 41 55 | */ 56 | 57 | void 58 | destruct(int v __unused) 59 | { 60 | char checkpass[15]; 61 | int i, j; 62 | double zap; 63 | 64 | if (damaged(COMPUTER)) { 65 | out(COMPUTER); 66 | return; 67 | } 68 | printf("\n\07 --- WORKING ---\07\n"); 69 | sleep(3); 70 | /* output the count 10 9 8 7 6 */ 71 | for (i = 10; i > 5; i--) { 72 | for (j = 10; j > i; j--) 73 | printf(" "); 74 | printf("%d\n", i); 75 | sleep(1); 76 | } 77 | /* check for password on new line only */ 78 | skiptonl(0); 79 | getstrpar("Enter password verification", checkpass, 14, 0); 80 | sleep(2); 81 | if (!sequal(checkpass, Game.passwd)) { 82 | printf("Self destruct sequence aborted\n"); 83 | return; 84 | } 85 | printf("Password verified; self destruct sequence continues:\n"); 86 | sleep(2); 87 | /* output count 5 4 3 2 1 0 */ 88 | for (i = 5; i >= 0; i--) { 89 | sleep(1); 90 | for (j = 5; j > i; j--) 91 | printf(" "); 92 | printf("%d\n", i); 93 | } 94 | sleep(2); 95 | printf("\032\014***** %s destroyed *****\n", Ship.shipname); 96 | Game.killed = 1; 97 | /* let's see what we can blow up!!!! */ 98 | zap = 20.0 * Ship.energy; 99 | Game.deaths += Ship.crew; 100 | for (i = 0; i < Etc.nkling; ) { 101 | if (Etc.klingon[i].power * Etc.klingon[i].dist <= zap) 102 | killk(Etc.klingon[i].x, Etc.klingon[i].y); 103 | else 104 | i++; 105 | } 106 | /* if we didn't kill the last Klingon (detected by killk), */ 107 | /* then we lose.... */ 108 | lose(L_DSTRCT); 109 | } 110 | -------------------------------------------------------------------------------- /nova.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)nova.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/nova.c,v 1.4 1999/11/30 03:49:52 billf Exp $ 31 | * $DragonFly: src/games/trek/nova.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** CAUSE A NOVA TO OCCUR 38 | ** 39 | ** A nova occurs. It is the result of having a star hit with 40 | ** a photon torpedo. There are several things which may happen. 41 | ** The star may not be affected. It may go nova. It may turn 42 | ** into a black hole. Any (yummy) it may go supernova. 43 | ** 44 | ** Stars that go nova cause stars which surround them to undergo 45 | ** the same probabilistic process. Klingons next to them are 46 | ** destroyed. And if the starship is next to it, it gets zapped. 47 | ** If the zap is too much, it gets destroyed. 48 | */ 49 | 50 | void 51 | nova(int x, int y) 52 | { 53 | int i, j; 54 | int se; 55 | 56 | if (Sect[x][y] != STAR || Quad[Ship.quadx][Ship.quady].stars < 0) 57 | return; 58 | if (ranf(100) < 15) { 59 | printf("Spock: Star at %d,%d failed to nova.\n", x, y); 60 | return; 61 | } 62 | if (ranf(100) < 5) { 63 | snova(x, y); 64 | return; 65 | } 66 | printf("Spock: Star at %d,%d gone nova\n", x, y); 67 | 68 | if (ranf(4) != 0) 69 | Sect[x][y] = EMPTY; 70 | else { 71 | Sect[x][y] = HOLE; 72 | Quad[Ship.quadx][Ship.quady].holes += 1; 73 | } 74 | Quad[Ship.quadx][Ship.quady].stars -= 1; 75 | Game.kills += 1; 76 | for (i = x - 1; i <= x + 1; i++) { 77 | if (i < 0 || i >= NSECTS) 78 | continue; 79 | for (j = y - 1; j <= y + 1; j++) { 80 | if (j < 0 || j >= NSECTS) 81 | continue; 82 | se = Sect[i][j]; 83 | switch (se) { 84 | case EMPTY: 85 | case HOLE: 86 | break; 87 | 88 | case KLINGON: 89 | killk(i, j); 90 | break; 91 | 92 | case STAR: 93 | nova(i, j); 94 | break; 95 | 96 | case INHABIT: 97 | kills(i, j, -1); 98 | break; 99 | 100 | case BASE: 101 | killb(i, j); 102 | Game.killb += 1; 103 | break; 104 | 105 | case ENTERPRISE: 106 | case QUEENE: 107 | se = 2000; 108 | if (Ship.shldup) { 109 | if (Ship.shield >= se) { 110 | Ship.shield -= se; 111 | se = 0; 112 | } else { 113 | se -= Ship.shield; 114 | Ship.shield = 0; 115 | } 116 | } 117 | Ship.energy -= se; 118 | if (Ship.energy <= 0) 119 | lose(L_SUICID); 120 | break; 121 | 122 | default: 123 | printf("Unknown object %c at %d,%d destroyed\n", 124 | se, i, j); 125 | Sect[i][j] = EMPTY; 126 | break; 127 | } 128 | } 129 | } 130 | return; 131 | } 132 | -------------------------------------------------------------------------------- /shield.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)shield.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/shield.c,v 1.5 1999/11/30 03:49:54 billf Exp $ 31 | * $DragonFly: src/games/trek/shield.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** SHIELD AND CLOAKING DEVICE CONTROL 39 | ** 40 | ** 'f' is one for auto shield up (in case of Condition RED), 41 | ** zero for shield control, and negative one for cloaking 42 | ** device control. 43 | ** 44 | ** Called with an 'up' or 'down' on the same line, it puts 45 | ** the shields/cloak into the specified mode. Otherwise it 46 | ** reports to the user the current mode, and asks if she wishes 47 | ** to change. 48 | ** 49 | ** This is not a free move. Hits that occur as a result of 50 | ** this move appear as though the shields are half up/down, 51 | ** so you get partial hits. 52 | */ 53 | 54 | struct cvntab Udtab[] = { 55 | { "u", "p", (cmdfun)1, 0 }, 56 | { "d", "own", (cmdfun)0, 0 }, 57 | { NULL, NULL, NULL, 0 } 58 | }; 59 | 60 | void 61 | shield(int f) 62 | { 63 | int i; 64 | struct cvntab *r; 65 | char s[100]; 66 | const char *device, *dev2, *dev3; 67 | int ind; 68 | char *stat; 69 | 70 | if (f > 0 && (Ship.shldup || damaged(SRSCAN))) 71 | return; 72 | if (f < 0) { 73 | /* cloaking device */ 74 | if (Ship.ship == QUEENE) { 75 | printf("Ye Faire Queene does not have the cloaking device.\n"); 76 | return; 77 | } 78 | device = "Cloaking device"; 79 | dev2 = "is"; 80 | ind = CLOAK; 81 | dev3 = "it"; 82 | stat = &Ship.cloaked; 83 | } else { 84 | /* shields */ 85 | device = "Shields"; 86 | dev2 = "are"; 87 | dev3 = "them"; 88 | ind = SHIELD; 89 | stat = &Ship.shldup; 90 | } 91 | if (damaged(ind)) { 92 | if (f <= 0) 93 | out(ind); 94 | return; 95 | } 96 | if (Ship.cond == DOCKED) { 97 | printf("%s %s down while docked\n", device, dev2); 98 | return; 99 | } 100 | if (f <= 0 && !testnl()) { 101 | r = getcodpar("Up or down", Udtab); 102 | i = (long) r->value; 103 | } else { 104 | if (*stat) 105 | sprintf(s, "%s %s up. Do you want %s down", device, dev2, dev3); 106 | else 107 | sprintf(s, "%s %s down. Do you want %s up", device, dev2, dev3); 108 | if (!getynpar(s)) 109 | return; 110 | i = !*stat; 111 | } 112 | if (*stat == i) { 113 | printf("%s already ", device); 114 | if (i) 115 | printf("up\n"); 116 | else 117 | printf("down\n"); 118 | return; 119 | } 120 | if (i) { 121 | if (f >= 0) 122 | Ship.energy -= Param.shupengy; 123 | else 124 | Ship.cloakgood = 0; 125 | } 126 | Move.free = 0; 127 | if (f >= 0) 128 | Move.shldchg = 1; 129 | *stat = i; 130 | return; 131 | } 132 | -------------------------------------------------------------------------------- /initquad.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)initquad.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/initquad.c,v 1.4 1999/11/30 03:49:49 billf Exp $ 31 | * $DragonFly: src/games/trek/initquad.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Paramize Quadrant Upon Entering 38 | ** 39 | ** A quadrant is initialized from the information held in the 40 | ** Quad matrix. Basically, everything is just initialized 41 | ** randomly, except for the starship, which goes into a fixed 42 | ** sector. 43 | ** 44 | ** If there are Klingons in the quadrant, the captain is informed 45 | ** that the condition is RED, and he is given a chance to put 46 | ** his shields up if the computer is working. 47 | ** 48 | ** The flag `f' is set to disable the check for condition red. 49 | ** This mode is used in situations where you know you are going 50 | ** to be docked, i.e., abandon() and help(). 51 | */ 52 | 53 | void 54 | initquad(int f) 55 | { 56 | int i, j; 57 | int rx, ry; 58 | int nbases, nstars; 59 | struct quad *q; 60 | int nholes; 61 | 62 | q = &Quad[Ship.quadx][Ship.quady]; 63 | 64 | /* ignored supernova'ed quadrants (this is checked again later anyway */ 65 | if (q->stars < 0) 66 | return; 67 | Etc.nkling = q->klings; 68 | nbases = q->bases; 69 | nstars = q->stars; 70 | nholes = q->holes; 71 | 72 | /* have we blundered into a battle zone w/ shields down? */ 73 | if (Etc.nkling > 0 && !f) { 74 | printf("Condition RED\n"); 75 | Ship.cond = RED; 76 | if (!damaged(COMPUTER)) 77 | shield(1); 78 | } 79 | 80 | /* clear out the quadrant */ 81 | for (i = 0; i < NSECTS; i++) 82 | for (j = 0; j < NSECTS; j++) 83 | Sect[i][j] = EMPTY; 84 | 85 | /* initialize Enterprise */ 86 | Sect[Ship.sectx][Ship.secty] = Ship.ship; 87 | 88 | /* initialize Klingons */ 89 | for (i = 0; i < Etc.nkling; i++) { 90 | sector(&rx, &ry); 91 | Sect[rx][ry] = KLINGON; 92 | Etc.klingon[i].x = rx; 93 | Etc.klingon[i].y = ry; 94 | Etc.klingon[i].power = Param.klingpwr; 95 | Etc.klingon[i].srndreq = 0; 96 | } 97 | compkldist(1); 98 | 99 | /* initialize star base */ 100 | if (nbases > 0) { 101 | sector(&rx, &ry); 102 | Sect[rx][ry] = BASE; 103 | Etc.starbase.x = rx; 104 | Etc.starbase.y = ry; 105 | } 106 | 107 | /* initialize inhabited starsystem */ 108 | if (q->qsystemname != 0) { 109 | sector(&rx, &ry); 110 | Sect[rx][ry] = INHABIT; 111 | nstars -= 1; 112 | } 113 | 114 | /* initialize black holes */ 115 | for (i = 0; i < nholes; i++) { 116 | sector(&rx, &ry); 117 | Sect[rx][ry] = HOLE; 118 | } 119 | 120 | /* initialize stars */ 121 | for (i = 0; i < nstars; i++) { 122 | sector(&rx, &ry); 123 | Sect[rx][ry] = STAR; 124 | } 125 | Move.newquad = 1; 126 | } 127 | 128 | void 129 | sector(int *x, int *y) 130 | { 131 | int i, j; 132 | 133 | do { 134 | i = ranf(NSECTS); 135 | j = ranf(NSECTS); 136 | } while (Sect[i][j] != EMPTY); 137 | *x = i; 138 | *y = j; 139 | return; 140 | } 141 | -------------------------------------------------------------------------------- /dock.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)dock.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/dock.c,v 1.4 1999/11/30 03:49:46 billf Exp $ 31 | * $DragonFly: src/games/trek/dock.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** DOCK TO STARBASE 38 | ** 39 | ** The starship is docked to a starbase. For this to work you 40 | ** must be adjacent to a starbase. 41 | ** 42 | ** You get your supplies replenished and your captives are 43 | ** disembarked. Note that your score is updated now, not when 44 | ** you actually take the captives. 45 | ** 46 | ** Any repairs that need to be done are rescheduled to take 47 | ** place sooner. This provides for the faster repairs when you 48 | ** are docked. 49 | */ 50 | 51 | void 52 | dock(int v __unused) 53 | { 54 | int i, j; 55 | int ok; 56 | struct event *e; 57 | 58 | if (Ship.cond == DOCKED) { 59 | printf("Chekov: But captain, we are already docked\n"); 60 | return; 61 | } 62 | /* check for ok to dock, i.e., adjacent to a starbase */ 63 | ok = 0; 64 | for (i = Ship.sectx - 1; i <= Ship.sectx + 1 && !ok; i++) { 65 | if (i < 0 || i >= NSECTS) 66 | continue; 67 | for (j = Ship.secty - 1; j <= Ship.secty + 1; j++) { 68 | if (j < 0 || j >= NSECTS) 69 | continue; 70 | if (Sect[i][j] == BASE) { 71 | ok++; 72 | break; 73 | } 74 | } 75 | } 76 | if (!ok) { 77 | printf("Chekov: But captain, we are not adjacent to a starbase.\n"); 78 | return; 79 | } 80 | 81 | /* restore resources */ 82 | Ship.energy = Param.energy; 83 | Ship.torped = Param.torped; 84 | Ship.shield = Param.shield; 85 | Ship.crew = Param.crew; 86 | Game.captives += Param.brigfree - Ship.brigfree; 87 | Ship.brigfree = Param.brigfree; 88 | 89 | /* reset ship's defenses */ 90 | Ship.shldup = 0; 91 | Ship.cloaked = 0; 92 | Ship.cond = DOCKED; 93 | Ship.reserves = Param.reserves; 94 | 95 | /* recalibrate space inertial navigation system */ 96 | Ship.sinsbad = 0; 97 | 98 | /* output any saved radio messages */ 99 | dumpssradio(); 100 | 101 | /* reschedule any device repairs */ 102 | for (i = 0; i < MAXEVENTS; i++) { 103 | e = &Event[i]; 104 | if (e->evcode != E_FIXDV) 105 | continue; 106 | reschedule(e, (e->date - Now.date) * Param.dockfac); 107 | } 108 | return; 109 | } 110 | 111 | 112 | /* 113 | ** LEAVE A STARBASE 114 | ** 115 | ** This is the inverse of dock(). The main function it performs 116 | ** is to reschedule any damages so that they will take longer. 117 | */ 118 | 119 | void 120 | undock(int v __unused) 121 | { 122 | struct event *e; 123 | int i; 124 | 125 | if (Ship.cond != DOCKED) { 126 | printf("Sulu: Pardon me captain, but we are not docked.\n"); 127 | return; 128 | } 129 | Ship.cond = GREEN; 130 | Move.free = 0; 131 | 132 | /* reschedule device repair times (again) */ 133 | for (i = 0; i < MAXEVENTS; i++) { 134 | e = &Event[i]; 135 | if (e->evcode != E_FIXDV) 136 | continue; 137 | reschedule(e, (e->date - Now.date) / Param.dockfac); 138 | } 139 | return; 140 | } 141 | -------------------------------------------------------------------------------- /schedule.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)schedule.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/schedule.c,v 1.4 1999/11/30 03:49:53 billf Exp $ 31 | * $DragonFly: src/games/trek/schedule.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** SCHEDULE AN EVENT 38 | ** 39 | ** An event of type 'type' is scheduled for time NOW + 'offset' 40 | ** into the first available slot. 'x', 'y', and 'z' are 41 | ** considered the attributes for this event. 42 | ** 43 | ** The address of the slot is returned. 44 | */ 45 | 46 | struct event * 47 | schedule(int type, double offset, char x, char y, char z) 48 | { 49 | struct event *e; 50 | int i; 51 | double date; 52 | 53 | date = Now.date + offset; 54 | for (i = 0; i < MAXEVENTS; i++) { 55 | e = &Event[i]; 56 | if (e->evcode) 57 | continue; 58 | /* got a slot */ 59 | #ifdef xTRACE 60 | if (Trace) 61 | printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n", 62 | type, date, i, x, y, z); 63 | #endif 64 | e->evcode = type; 65 | e->date = date; 66 | e->x = x; 67 | e->y = y; 68 | e->systemname = z; 69 | Now.eventptr[type] = e; 70 | return (e); 71 | } 72 | syserr("Cannot schedule event %d parm %d %d %d", type, x, y, z); 73 | /* NOTREACHED */ 74 | return(NULL); 75 | } 76 | 77 | 78 | /* 79 | ** RESCHEDULE AN EVENT 80 | ** 81 | ** The event pointed to by 'e' is rescheduled to the current 82 | ** time plus 'offset'. 83 | */ 84 | 85 | void 86 | reschedule(struct event *e1, double offset) 87 | { 88 | double date; 89 | struct event *e; 90 | 91 | e = e1; 92 | 93 | date = Now.date + offset; 94 | e->date = date; 95 | #ifdef xTRACE 96 | if (Trace) 97 | printf("reschedule: type %d parm %d %d %d @ %.2f\n", 98 | e->evcode, e->x, e->y, e->systemname, date); 99 | #endif 100 | return; 101 | } 102 | 103 | 104 | /* 105 | ** UNSCHEDULE AN EVENT 106 | ** 107 | ** The event at slot 'e' is deleted. 108 | */ 109 | 110 | void 111 | unschedule(struct event *e1) 112 | { 113 | struct event *e; 114 | 115 | e = e1; 116 | 117 | #ifdef xTRACE 118 | if (Trace) 119 | printf("unschedule: type %d @ %.2f parm %d %d %d\n", 120 | e->evcode, e->date, e->x, e->y, e->systemname); 121 | #endif 122 | Now.eventptr[e->evcode & E_EVENT] = 0; 123 | e->date = TOOLARGE; 124 | e->evcode = 0; 125 | return; 126 | } 127 | 128 | 129 | /* 130 | ** Abreviated schedule routine 131 | ** 132 | ** Parameters are the event index and a factor for the time 133 | ** figure. 134 | */ 135 | 136 | struct event * 137 | xsched(int ev1, int factor, int x, int y, int z) 138 | { 139 | int ev; 140 | double when; 141 | 142 | ev = ev1; 143 | when = -Param.eventdly[ev] * Param.time * log(franf()) / factor; 144 | return (schedule(ev, when, x, y, z)); 145 | } 146 | 147 | 148 | /* 149 | ** Simplified reschedule routine 150 | ** 151 | ** Parameters are the event index, the initial date, and the 152 | ** division factor. Look at the code to see what really happens. 153 | */ 154 | 155 | void 156 | xresched(struct event *e1, int ev1, int factor) 157 | { 158 | int ev; 159 | struct event *e; 160 | double when; 161 | 162 | ev = ev1; 163 | e = e1; 164 | when = -Param.eventdly[ev] * Param.time * log(franf()) / factor; 165 | reschedule(e, when); 166 | } 167 | -------------------------------------------------------------------------------- /dumpgame.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)dumpgame.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/dumpgame.c,v 1.6 1999/11/30 03:49:46 billf Exp $ 31 | * $DragonFly: src/games/trek/dumpgame.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include 35 | 36 | #include "trek.h" 37 | 38 | /*** THIS CONSTANT MUST CHANGE AS THE DATA SPACES CHANGE ***/ 39 | #define VERSION 2 40 | 41 | struct dump { 42 | char *area; 43 | int count; 44 | }; 45 | 46 | static bool readdump(int); 47 | 48 | struct dump Dump_template[] = { 49 | { (char *)&Ship, sizeof (Ship) }, 50 | { (char *)&Now, sizeof (Now) }, 51 | { (char *)&Param, sizeof (Param) }, 52 | { (char *)&Etc, sizeof (Etc) }, 53 | { (char *)&Game, sizeof (Game) }, 54 | { (char *)Sect, sizeof (Sect) }, 55 | { (char *)Quad, sizeof (Quad) }, 56 | { (char *)&Move, sizeof (Move) }, 57 | { (char *)Event, sizeof (Event) }, 58 | { NULL, 0 } 59 | }; 60 | 61 | /* 62 | ** DUMP GAME 63 | ** 64 | ** This routine dumps the game onto the file "trek.dump". The 65 | ** first two bytes of the file are a version number, which 66 | ** reflects whether this image may be used. Obviously, it must 67 | ** change as the size, content, or order of the data structures 68 | ** output change. 69 | */ 70 | 71 | void 72 | dumpgame(int v __unused) 73 | { 74 | int version; 75 | int fd; 76 | struct dump *d; 77 | int i; 78 | 79 | if ((fd = creat("trek.dump", 0644)) < 0) { 80 | printf("cannot dump\n"); 81 | return; 82 | } 83 | version = VERSION; 84 | write(fd, &version, sizeof version); 85 | 86 | /* output the main data areas */ 87 | for (d = Dump_template; d->area; d++) { 88 | write(fd, &d->area, sizeof d->area); 89 | i = d->count; 90 | write(fd, d->area, i); 91 | } 92 | 93 | close(fd); 94 | } 95 | 96 | 97 | /* 98 | ** RESTORE GAME 99 | ** 100 | ** The game is restored from the file "trek.dump". In order for 101 | ** this to succeed, the file must exist and be readable, must 102 | ** have the correct version number, and must have all the appro- 103 | ** priate data areas. 104 | ** 105 | ** Return value is zero for success, one for failure. 106 | */ 107 | 108 | bool 109 | restartgame(void) 110 | { 111 | int fd; 112 | int version; 113 | 114 | if ((fd = open("trek.dump", O_RDONLY)) < 0 || 115 | read(fd, &version, sizeof version) != sizeof version || 116 | version != VERSION || 117 | readdump(fd)) { 118 | printf("cannot restart\n"); 119 | close(fd); 120 | return (1); 121 | } 122 | 123 | close(fd); 124 | return (0); 125 | } 126 | 127 | 128 | /* 129 | ** READ DUMP 130 | ** 131 | ** This is the business end of restartgame(). It reads in the 132 | ** areas. 133 | ** 134 | ** Returns zero for success, one for failure. 135 | */ 136 | 137 | static bool 138 | readdump(int fd1) 139 | { 140 | int fd; 141 | struct dump *d; 142 | int i; 143 | long junk; 144 | 145 | fd = fd1; 146 | 147 | for (d = Dump_template; d->area; d++) { 148 | if (read(fd, &junk, sizeof junk) != (sizeof junk)) 149 | return (1); 150 | if ((char *)junk != d->area) 151 | return (1); 152 | i = d->count; 153 | if (read(fd, d->area, i) != i) 154 | return (1); 155 | } 156 | 157 | /* make quite certain we are at EOF */ 158 | return (read(fd, &junk, 1)); 159 | } 160 | -------------------------------------------------------------------------------- /snova.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)snova.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/snova.c,v 1.4 1999/11/30 03:49:54 billf Exp $ 31 | * $DragonFly: src/games/trek/snova.c,v 1.4 2007/05/13 22:25:41 swildner Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** CAUSE SUPERNOVA TO OCCUR 38 | ** 39 | ** A supernova occurs. If 'ix' < 0, a random quadrant is chosen; 40 | ** otherwise, the current quadrant is taken, and (ix, iy) give 41 | ** the sector quadrants of the star which is blowing up. 42 | ** 43 | ** If the supernova turns out to be in the quadrant you are in, 44 | ** you go into "emergency override mode", which tries to get you 45 | ** out of the quadrant as fast as possible. However, if you 46 | ** don't have enough fuel, or if you by chance run into something, 47 | ** or some such thing, you blow up anyway. Oh yeh, if you are 48 | ** within two sectors of the star, there is nothing that can 49 | ** be done for you. 50 | ** 51 | ** When a star has gone supernova, the quadrant becomes uninhab- 52 | ** itable for the rest of eternity, i.e., the game. If you ever 53 | ** try stopping in such a quadrant, you will go into emergency 54 | ** override mode. 55 | */ 56 | 57 | void 58 | snova(int x, int y) 59 | { 60 | int qx, qy; 61 | int ix, iy = 0; 62 | int f; 63 | int dx, dy; 64 | int n; 65 | struct quad *q; 66 | 67 | f = 0; 68 | ix = x; 69 | if (ix < 0) { 70 | /* choose a quadrant */ 71 | while (1) { 72 | qx = ranf(NQUADS); 73 | qy = ranf(NQUADS); 74 | q = &Quad[qx][qy]; 75 | if (q->stars > 0) 76 | break; 77 | } 78 | if (Ship.quadx == qx && Ship.quady == qy) { 79 | /* select a particular star */ 80 | n = ranf(q->stars); 81 | for (ix = 0; ix < NSECTS; ix++) { 82 | for (iy = 0; iy < NSECTS; iy++) 83 | if (Sect[ix][iy] == STAR || 84 | Sect[ix][iy] == INHABIT) 85 | if ((n -= 1) <= 0) 86 | break; 87 | if (n <= 0) 88 | break; 89 | } 90 | f = 1; 91 | } 92 | } else { 93 | /* current quadrant */ 94 | iy = y; 95 | qx = Ship.quadx; 96 | qy = Ship.quady; 97 | q = &Quad[qx][qy]; 98 | f = 1; 99 | } 100 | if (f) { 101 | /* supernova is in same quadrant as Enterprise */ 102 | printf("\a\nRED ALERT: supernova occurring at %d,%d\n", ix, iy); 103 | dx = ix - Ship.sectx; 104 | dy = iy - Ship.secty; 105 | if (dx * dx + dy * dy <= 2) { 106 | printf("*** Emergency override attem"); 107 | sleep(1); 108 | printf("\n"); 109 | lose(L_SNOVA); 110 | } 111 | q->scanned = 1000; 112 | } else { 113 | if (!damaged(SSRADIO)) { 114 | q->scanned = 1000; 115 | printf("\nUhura: Captain, Starfleet Command reports a supernova\n"); 116 | printf(" in quadrant %d,%d. Caution is advised\n", qx, qy); 117 | } 118 | } 119 | 120 | /* clear out the supernova'ed quadrant */ 121 | dx = q->klings; 122 | dy = q->stars; 123 | Now.klings -= dx; 124 | if (x >= 0) { 125 | /* Enterprise caused supernova */ 126 | Game.kills += dy; 127 | if (q->bases) 128 | killb(qx, qy); 129 | Game.killk += dx; 130 | } else { 131 | if (q->bases) 132 | killb(qx, qy); 133 | } 134 | killd(qx, qy, (x >= 0)); 135 | q->stars = -1; 136 | q->klings = 0; 137 | if (Now.klings <= 0) { 138 | printf("Lucky devil, that supernova destroyed the last klingon\n"); 139 | win(); 140 | } 141 | return; 142 | } 143 | -------------------------------------------------------------------------------- /help.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)help.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/help.c,v 1.4 1999/11/30 03:49:48 billf Exp $ 31 | * $DragonFly: src/games/trek/help.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** call starbase for help 38 | ** 39 | ** First, the closest starbase is selected. If there is a 40 | ** a starbase in your own quadrant, you are in good shape. 41 | ** This distance takes quadrant distances into account only. 42 | ** 43 | ** A magic number is computed based on the distance which acts 44 | ** as the probability that you will be rematerialized. You 45 | ** get three tries. 46 | ** 47 | ** When it is determined that you should be able to be remater- 48 | ** ialized (i.e., when the probability thing mentioned above 49 | ** comes up positive), you are put into that quadrant (anywhere). 50 | ** Then, we try to see if there is a spot adjacent to the star- 51 | ** base. If not, you can't be rematerialized!!! Otherwise, 52 | ** it drops you there. It only tries five times to find a spot 53 | ** to drop you. After that, it's your problem. 54 | */ 55 | 56 | const char *Cntvect[3] = { 57 | "first", "second", "third" 58 | }; 59 | 60 | void 61 | help(int v __unused) 62 | { 63 | int i; 64 | double dist, x; 65 | int dx, dy; 66 | int j, l = 0; 67 | 68 | /* check to see if calling for help is reasonable ... */ 69 | if (Ship.cond == DOCKED) { 70 | printf("Uhura: But Captain, we're already docked\n"); 71 | return; 72 | } 73 | 74 | /* or possible */ 75 | if (damaged(SSRADIO)) { 76 | out(SSRADIO); 77 | return; 78 | } 79 | if (Now.bases <= 0) { 80 | printf("Uhura: I'm not getting any response from starbase\n"); 81 | return; 82 | } 83 | 84 | /* tut tut, there goes the score */ 85 | Game.helps += 1; 86 | 87 | /* find the closest base */ 88 | dist = TOOLARGE; 89 | if (Quad[Ship.quadx][Ship.quady].bases <= 0) { 90 | /* there isn't one in this quadrant */ 91 | for (i = 0; i < Now.bases; i++) { 92 | /* compute distance */ 93 | dx = Now.base[i].x - Ship.quadx; 94 | dy = Now.base[i].y - Ship.quady; 95 | x = dx * dx + dy * dy; 96 | x = sqrt(x); 97 | 98 | /* see if better than what we already have */ 99 | if (x < dist) { 100 | dist = x; 101 | l = i; 102 | } 103 | } 104 | 105 | /* go to that quadrant */ 106 | Ship.quadx = Now.base[l].x; 107 | Ship.quady = Now.base[l].y; 108 | initquad(1); 109 | } else { 110 | dist = 0.0; 111 | } 112 | 113 | /* dematerialize the Enterprise */ 114 | Sect[Ship.sectx][Ship.secty] = EMPTY; 115 | printf("Starbase in %d,%d responds\n", Ship.quadx, Ship.quady); 116 | 117 | /* this next thing acts as a probability that it will work */ 118 | x = pow(1.0 - pow(0.94, dist), 0.3333333); 119 | 120 | /* attempt to rematerialize */ 121 | for (i = 0; i < 3; i++) { 122 | sleep(2); 123 | printf("%s attempt to rematerialize ", Cntvect[i]); 124 | if (franf() > x) { 125 | /* ok, that's good. let's see if we can set her down */ 126 | for (j = 0; j < 5; j++) { 127 | dx = Etc.starbase.x + ranf(3) - 1; 128 | if (dx < 0 || dx >= NSECTS) 129 | continue; 130 | dy = Etc.starbase.y + ranf(3) - 1; 131 | if (dy < 0 || dy >= NSECTS || Sect[dx][dy] != EMPTY) 132 | continue; 133 | break; 134 | } 135 | if (j < 5) { 136 | /* found an empty spot */ 137 | printf("succeeds\n"); 138 | Ship.sectx = dx; 139 | Ship.secty = dy; 140 | Sect[dx][dy] = Ship.ship; 141 | dock(0); 142 | compkldist(0); 143 | return; 144 | } 145 | /* the starbase must have been surrounded */ 146 | } 147 | printf("fails\n"); 148 | } 149 | 150 | /* one, two, three strikes, you're out */ 151 | lose(L_NOHELP); 152 | } 153 | -------------------------------------------------------------------------------- /abandon.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)abandon.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/abandon.c,v 1.4 1999/11/30 03:49:43 billf Exp $ 31 | * $DragonFly: src/games/trek/abandon.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Abandon Ship 38 | ** 39 | ** The ship is abandoned. If your current ship is the Faire 40 | ** Queene, or if your shuttlecraft is dead, you're out of 41 | ** luck. You need the shuttlecraft in order for the captain 42 | ** (that's you!!) to escape. 43 | ** 44 | ** Your crew can beam to an inhabited starsystem in the 45 | ** quadrant, if there is one and if the transporter is working. 46 | ** If there is no inhabited starsystem, or if the transporter 47 | ** is out, they are left to die in outer space. 48 | ** 49 | ** These currently just count as regular deaths, but they 50 | ** should count very heavily against you. 51 | ** 52 | ** If there are no starbases left, you are captured by the 53 | ** Klingons, who torture you mercilessly. However, if there 54 | ** is at least one starbase, you are returned to the 55 | ** Federation in a prisoner of war exchange. Of course, this 56 | ** can't happen unless you have taken some prisoners. 57 | ** 58 | ** Uses trace flag 40 59 | */ 60 | 61 | void 62 | abandon(int v __unused) 63 | { 64 | struct quad *q; 65 | int i; 66 | int j; 67 | struct event *e; 68 | 69 | if (Ship.ship == QUEENE) { 70 | printf("You may not abandon ye Faire Queene\n"); 71 | return; 72 | } 73 | if (Ship.cond != DOCKED) { 74 | if (damaged(SHUTTLE)) { 75 | out(SHUTTLE); 76 | return; 77 | } 78 | printf("Officers escape in shuttlecraft\n"); 79 | /* decide on fate of crew */ 80 | q = &Quad[Ship.quadx][Ship.quady]; 81 | if (q->qsystemname == 0 || damaged(XPORTER)) { 82 | printf("Entire crew of %d left to die in outer space\n", 83 | Ship.crew); 84 | Game.deaths += Ship.crew; 85 | } else { 86 | printf("Crew beams down to planet %s\n", systemname(q)); 87 | } 88 | } 89 | /* see if you can be exchanged */ 90 | if (Now.bases == 0 || Game.captives < 20 * Game.skill) 91 | lose(L_CAPTURED); 92 | /* re-outfit new ship */ 93 | printf("You are hereby put in charge of an antiquated but still\n"); 94 | printf(" functional ship, the Fairie Queene.\n"); 95 | Ship.ship = QUEENE; 96 | Ship.shipname = "Fairie Queene"; 97 | Param.energy = Ship.energy = 3000; 98 | Param.torped = Ship.torped = 6; 99 | Param.shield = Ship.shield = 1250; 100 | Ship.shldup = 0; 101 | Ship.cloaked = 0; 102 | Ship.warp = 5.0; 103 | Ship.warp2 = 25.0; 104 | Ship.warp3 = 125.0; 105 | Ship.cond = GREEN; 106 | /* clear out damages on old ship */ 107 | for (i = 0; i < MAXEVENTS; i++) { 108 | e = &Event[i]; 109 | if (e->evcode != E_FIXDV) 110 | continue; 111 | unschedule(e); 112 | } 113 | /* get rid of some devices and redistribute probabilities */ 114 | i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK]; 115 | Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0; 116 | while (i > 0) 117 | for (j = 0; j < NDEV; j++) { 118 | if (Param.damprob[j] != 0) { 119 | Param.damprob[j] += 1; 120 | i--; 121 | if (i <= 0) 122 | break; 123 | } 124 | } 125 | /* pick a starbase to restart at */ 126 | i = ranf(Now.bases); 127 | Ship.quadx = Now.base[i].x; 128 | Ship.quady = Now.base[i].y; 129 | /* setup that quadrant */ 130 | while (1) { 131 | initquad(1); 132 | Sect[Ship.sectx][Ship.secty] = EMPTY; 133 | for (i = 0; i < 5; i++) { 134 | Ship.sectx = Etc.starbase.x + ranf(3) - 1; 135 | if (Ship.sectx < 0 || Ship.sectx >= NSECTS) 136 | continue; 137 | Ship.secty = Etc.starbase.y + ranf(3) - 1; 138 | if (Ship.secty < 0 || Ship.secty >= NSECTS) 139 | continue; 140 | if (Sect[Ship.sectx][Ship.secty] == EMPTY) { 141 | Sect[Ship.sectx][Ship.secty] = QUEENE; 142 | dock(0); 143 | compkldist(0); 144 | return; 145 | } 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /srscan.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)srscan.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/srscan.c,v 1.4 1999/11/30 03:49:55 billf Exp $ 31 | * $DragonFly: src/games/trek/srscan.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** SHORT RANGE SENSOR SCAN 39 | ** 40 | ** A short range scan is taken of the current quadrant. If the 41 | ** flag 'f' is one, it is an "auto srscan". It does a status 42 | ** report and a srscan. 43 | ** If 'f' is -1, you get a status report only. If it is zero, 44 | ** you get a srscan and an optional status report. The status 45 | ** report is taken if you enter "srscan yes"; for all srscans 46 | ** thereafter you get a status report with your srscan until 47 | ** you type "srscan no". It defaults to on. 48 | ** 49 | ** The current quadrant is filled in on the computer chart. 50 | */ 51 | 52 | const char *Color[4] = { 53 | "GREEN", 54 | "DOCKED", 55 | "YELLOW", 56 | "RED" 57 | }; 58 | 59 | void 60 | srscan(int f) 61 | { 62 | int i, j; 63 | int statinfo; 64 | const char *s; 65 | int percent; 66 | struct quad *q = NULL; 67 | struct cvntab *p; 68 | 69 | if (f >= 0 && check_out(SRSCAN)) { 70 | return; 71 | } 72 | if (f) { 73 | statinfo = 1; 74 | } else { 75 | if (!testnl()) 76 | Etc.statreport = getynpar("status report"); 77 | statinfo = Etc.statreport; 78 | } 79 | if (f > 0) 80 | Etc.statreport = 1; 81 | if (f >= 0) { 82 | printf("\nShort range sensor scan\n"); 83 | q = &Quad[Ship.quadx][Ship.quady]; 84 | q->scanned = q->klings * 100 + q->bases * 10 + q->stars; 85 | printf(" "); 86 | for (i = 0; i < NSECTS; i++) { 87 | printf("%d ", i); 88 | } 89 | printf("\n"); 90 | } 91 | 92 | for (i = 0; i < NSECTS; i++) { 93 | if (f >= 0) { 94 | printf("%d ", i); 95 | for (j = 0; j < NSECTS; j++) 96 | printf("%c ", Sect[i][j]); 97 | printf("%d", i); 98 | if (statinfo) 99 | printf(" "); 100 | } 101 | if (statinfo) 102 | switch (i) { 103 | case 0: 104 | printf("stardate %.2f", Now.date); 105 | break; 106 | case 1: 107 | printf("condition %s", Color[Ship.cond]); 108 | if (Ship.cloaked) 109 | printf(", CLOAKED"); 110 | break; 111 | case 2: 112 | printf("position %d,%d/%d,%d", Ship.quadx, 113 | Ship.quady, Ship.sectx, Ship.secty); 114 | break; 115 | case 3: 116 | printf("warp factor %.1f", Ship.warp); 117 | break; 118 | case 4: 119 | printf("total energy %d", Ship.energy); 120 | break; 121 | case 5: 122 | printf("torpedoes %d", Ship.torped); 123 | break; 124 | case 6: 125 | s = "down"; 126 | if (Ship.shldup) 127 | s = "up"; 128 | if (damaged(SHIELD)) 129 | s = "damaged"; 130 | percent = 100.0 * Ship.shield / Param.shield; 131 | printf("shields %s, %d%%", s, percent); 132 | break; 133 | case 7: 134 | printf("Klingons left %d", Now.klings); 135 | break; 136 | case 8: 137 | printf("time left %.2f", Now.time); 138 | break; 139 | case 9: 140 | printf("life support "); 141 | if (damaged(LIFESUP)) { 142 | printf("damaged, reserves = %.2f", Ship.reserves); 143 | break; 144 | } 145 | printf("active"); 146 | break; 147 | } 148 | printf("\n"); 149 | } 150 | if (f < 0) { 151 | printf("current crew %d\n", Ship.crew); 152 | printf("brig space %d\n", Ship.brigfree); 153 | printf("Klingon power %d\n", Param.klingpwr); 154 | p = &Lentab[Game.length - 1]; 155 | if (Game.length > 2) 156 | p--; 157 | printf("Length, Skill %s%s, ", p->abrev, p->full); 158 | p = &Skitab[Game.skill - 1]; 159 | printf("%s%s\n", p->abrev, p->full); 160 | return; 161 | } 162 | printf(" "); 163 | for (i = 0; i < NSECTS; i++) 164 | printf("%d ", i); 165 | printf("\n"); 166 | 167 | if (q->qsystemname & Q_DISTRESSED) 168 | printf("Distressed "); 169 | if (q->qsystemname) 170 | printf("Starsystem %s\n", systemname(q)); 171 | } 172 | -------------------------------------------------------------------------------- /klmove.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)klmove.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/klmove.c,v 1.4 1999/11/30 03:49:49 billf Exp $ 31 | */ 32 | 33 | #include "trek.h" 34 | 35 | /* 36 | ** Move Klingons Around 37 | ** 38 | ** This is a largely incomprehensible block of code that moves 39 | ** Klingons around in a quadrant. It was written in a very 40 | ** "program as you go" fashion, and is a prime candidate for 41 | ** rewriting. 42 | ** 43 | ** The flag `fl' is zero before an attack, one after an attack, 44 | ** and two if you are leaving a quadrant. This serves to 45 | ** change the probability and distance that it moves. 46 | ** 47 | ** Basically, what it will try to do is to move a certain number 48 | ** of steps either toward you or away from you. It will avoid 49 | ** stars whenever possible. Nextx and nexty are the next 50 | ** sector to move to on a per-Klingon basis; they are roughly 51 | ** equivalent to Ship.sectx and Ship.secty for the starship. Lookx and 52 | ** looky are the sector that you are going to look at to see 53 | ** if you can move their. Dx and dy are the increment. Fudgex 54 | ** and fudgey are the things you change around to change your 55 | ** course around stars. 56 | */ 57 | 58 | void 59 | klmove(int fl) 60 | { 61 | int n; 62 | struct kling *k; 63 | double dx, dy; 64 | int nextx, nexty; 65 | int lookx, looky; 66 | int motion; 67 | int fudgex, fudgey; 68 | int qx, qy; 69 | double bigger; 70 | int i; 71 | 72 | #ifdef xTRACE 73 | if (Trace) 74 | printf("klmove: fl = %d, Etc.nkling = %d\n", fl, Etc.nkling); 75 | #endif 76 | for (n = 0; n < Etc.nkling; n++) { 77 | k = &Etc.klingon[n]; 78 | i = 100; 79 | if (fl) 80 | i = 100.0 * k->power / Param.klingpwr; 81 | if (ranf(i) >= Param.moveprob[2 * Move.newquad + fl]) 82 | continue; 83 | /* compute distance to move */ 84 | motion = ranf(75) - 25; 85 | motion *= k->avgdist * Param.movefac[2 * Move.newquad + fl]; 86 | /* compute direction */ 87 | dx = Ship.sectx - k->x + ranf(3) - 1; 88 | dy = Ship.secty - k->y + ranf(3) - 1; 89 | bigger = dx; 90 | if (dy > bigger) 91 | bigger = dy; 92 | if (bigger == 0.0) 93 | bigger = 1.0; 94 | dx = dx / bigger + 0.5; 95 | dy = dy / bigger + 0.5; 96 | if (motion < 0) { 97 | motion = -motion; 98 | dx = -dx; 99 | dy = -dy; 100 | } 101 | fudgex = fudgey = 1; 102 | /* try to move the klingon */ 103 | nextx = k->x; 104 | nexty = k->y; 105 | for (; motion > 0; motion--) { 106 | lookx = nextx + dx; 107 | looky = nexty + dy; 108 | if (lookx < 0 || lookx >= NSECTS || 109 | looky < 0 || looky >= NSECTS) { 110 | /* new quadrant */ 111 | qx = Ship.quadx; 112 | qy = Ship.quady; 113 | if (lookx < 0) 114 | qx -= 1; 115 | else 116 | if (lookx >= NSECTS) 117 | qx += 1; 118 | if (looky < 0) 119 | qy -= 1; 120 | else 121 | if (looky >= NSECTS) 122 | qy += 1; 123 | if (qx < 0 || qx >= NQUADS || 124 | qy < 0 || qy >= NQUADS || 125 | Quad[qx][qy].stars < 0 || 126 | Quad[qx][qy].klings > MAXKLQUAD - 1) 127 | break; 128 | if (!damaged(SRSCAN)) { 129 | printf("Klingon at %d,%d escapes to quadrant %d,%d\n", 130 | k->x, k->y, qx, qy); 131 | motion = Quad[qx][qy].scanned; 132 | if (motion >= 0 && motion < 1000) 133 | Quad[qx][qy].scanned += 100; 134 | motion = Quad[Ship.quadx][Ship.quady].scanned; 135 | if (motion >= 0 && motion < 1000) 136 | Quad[Ship.quadx][Ship.quady].scanned -= 100; 137 | } 138 | Sect[k->x][k->y] = EMPTY; 139 | Quad[qx][qy].klings += 1; 140 | Etc.nkling -= 1; 141 | bmove(&Etc.klingon[Etc.nkling], k, sizeof *k); 142 | Quad[Ship.quadx][Ship.quady].klings -= 1; 143 | k = NULL; 144 | break; 145 | } 146 | if (Sect[lookx][looky] != EMPTY) { 147 | lookx = nextx + fudgex; 148 | if (lookx < 0 || lookx >= NSECTS) 149 | lookx = nextx + dx; 150 | if (Sect[lookx][looky] != EMPTY) { 151 | fudgex = -fudgex; 152 | looky = nexty + fudgey; 153 | if (looky < 0 || looky >= NSECTS || 154 | Sect[lookx][looky] != EMPTY) { 155 | fudgey = -fudgey; 156 | break; 157 | } 158 | } 159 | } 160 | nextx = lookx; 161 | nexty = looky; 162 | } 163 | if (k && (k->x != nextx || k->y != nexty)) { 164 | if (!damaged(SRSCAN)) 165 | printf("Klingon at %d,%d moves to %d,%d\n", 166 | k->x, k->y, nextx, nexty); 167 | Sect[k->x][k->y] = EMPTY; 168 | Sect[k->x = nextx][k->y = nexty] = KLINGON; 169 | } 170 | } 171 | compkldist(0); 172 | } 173 | -------------------------------------------------------------------------------- /kill.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)kill.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/kill.c,v 1.4 1999/11/30 03:49:49 billf Exp $ 31 | */ 32 | 33 | #include "trek.h" 34 | 35 | /* 36 | ** KILL KILL KILL !!! 37 | ** 38 | ** This file handles the killing off of almost anything. 39 | */ 40 | 41 | /* 42 | ** Handle a Klingon's death 43 | ** 44 | ** The Klingon at the sector given by the parameters is killed 45 | ** and removed from the Klingon list. Notice that it is not 46 | ** removed from the event list; this is done later, when the 47 | ** the event is to be caught. Also, the time left is recomputed, 48 | ** and the game is won if that was the last klingon. 49 | */ 50 | 51 | void 52 | killk(int ix, int iy) 53 | { 54 | int i; 55 | 56 | printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy); 57 | 58 | /* remove the scoundrel */ 59 | Now.klings -= 1; 60 | Sect[ix][iy] = EMPTY; 61 | Quad[Ship.quadx][Ship.quady].klings -= 1; 62 | /* %%% IS THIS SAFE???? %%% */ 63 | Quad[Ship.quadx][Ship.quady].scanned -= 100; 64 | Game.killk += 1; 65 | 66 | /* find the Klingon in the Klingon list */ 67 | for (i = 0; i < Etc.nkling; i++) 68 | if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y) { 69 | /* purge him from the list */ 70 | Etc.nkling -= 1; 71 | for (; i < Etc.nkling; i++) 72 | bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]); 73 | break; 74 | } 75 | 76 | /* find out if that was the last one */ 77 | if (Now.klings <= 0) 78 | win(); 79 | 80 | /* recompute time left */ 81 | Now.time = Now.resource / Now.klings; 82 | return; 83 | } 84 | 85 | 86 | /* 87 | ** handle a starbase's death 88 | */ 89 | 90 | void 91 | killb(int qx, int qy) 92 | { 93 | struct quad *q; 94 | struct xy *b; 95 | 96 | q = &Quad[qx][qy]; 97 | 98 | if (q->bases <= 0) 99 | return; 100 | if (!damaged(SSRADIO)) { 101 | /* then update starchart */ 102 | if (q->scanned < 1000) 103 | q->scanned -= 10; 104 | else 105 | if (q->scanned > 1000) 106 | q->scanned = -1; 107 | } 108 | q->bases = 0; 109 | Now.bases -= 1; 110 | for (b = Now.base; ; b++) 111 | if (qx == b->x && qy == b->y) 112 | break; 113 | bmove(&Now.base[Now.bases], b, sizeof *b); 114 | if (qx == Ship.quadx && qy == Ship.quady) { 115 | Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY; 116 | if (Ship.cond == DOCKED) 117 | undock(0); 118 | printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y); 119 | } else { 120 | if (!damaged(SSRADIO)) { 121 | printf("Uhura: Starfleet command reports that the starbase in\n"); 122 | printf(" quadrant %d,%d has been destroyed\n", qx, qy); 123 | } 124 | else 125 | schedule(E_KATSB | E_GHOST, TOOLARGE, qx, qy, 0); 126 | } 127 | } 128 | 129 | 130 | /** 131 | ** kill an inhabited starsystem 132 | ** 133 | ** x, y are quad coords if f == 0, else sector coords 134 | ** f != 0 -- this quad; f < 0 -- Enterprise's fault 135 | **/ 136 | 137 | void 138 | kills(int x, int y, int f) 139 | { 140 | struct quad *q; 141 | struct event *e; 142 | const char *name; 143 | 144 | if (f) { 145 | /* current quadrant */ 146 | q = &Quad[Ship.quadx][Ship.quady]; 147 | Sect[x][y] = EMPTY; 148 | name = systemname(q); 149 | if (name == NULL) 150 | return; 151 | printf("Inhabited starsystem %s at %d,%d destroyed\n", 152 | name, x, y); 153 | if (f < 0) 154 | Game.killinhab += 1; 155 | } else { 156 | /* different quadrant */ 157 | q = &Quad[x][y]; 158 | } 159 | if (q->qsystemname & Q_DISTRESSED) { 160 | /* distressed starsystem */ 161 | e = &Event[q->qsystemname & Q_SYSTEM]; 162 | printf("Distress call for %s invalidated\n", 163 | Systemname[e->systemname]); 164 | unschedule(e); 165 | } 166 | q->qsystemname = 0; 167 | q->stars -= 1; 168 | } 169 | 170 | 171 | /** 172 | ** "kill" a distress call 173 | ** 174 | ** x, y are quadrant coordinates 175 | ** f is set if user is to be informed 176 | **/ 177 | 178 | void 179 | killd(int x, int y, int f) 180 | { 181 | struct event *e; 182 | int i; 183 | struct quad *q; 184 | 185 | q = &Quad[x][y]; 186 | for (i = 0; i < MAXEVENTS; i++) { 187 | e = &Event[i]; 188 | if (e->x != x || e->y != y) 189 | continue; 190 | switch (e->evcode) { 191 | case E_KDESB: 192 | if (f) { 193 | printf("Distress call for starbase in %d,%d nullified\n", 194 | x, y); 195 | unschedule(e); 196 | } 197 | break; 198 | 199 | case E_ENSLV: 200 | case E_REPRO: 201 | if (f) { 202 | printf("Distress call for %s in quadrant %d,%d nullified\n", 203 | Systemname[e->systemname], x, y); 204 | q->qsystemname = e->systemname; 205 | unschedule(e); 206 | } else { 207 | e->evcode |= E_GHOST; 208 | } 209 | } 210 | } 211 | } 212 | -------------------------------------------------------------------------------- /attack.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)attack.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/attack.c,v 1.4 1999/11/30 03:49:43 billf Exp $ 31 | * $DragonFly: src/games/trek/attack.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Klingon Attack Routine 38 | ** 39 | ** This routine performs the Klingon attack provided that 40 | ** (1) Something happened this move (i.e., not free), and 41 | ** (2) You are not cloaked. Note that if you issue the 42 | ** cloak command, you are not considered cloaked until you 43 | ** expend some time. 44 | ** 45 | ** Klingons are permitted to move both before and after the 46 | ** attack. They will tend to move toward you before the 47 | ** attack and away from you after the attack. 48 | ** 49 | ** Under certain conditions you can get a critical hit. This 50 | ** sort of hit damages devices. The probability that a given 51 | ** device is damaged depends on the device. Well protected 52 | ** devices (such as the computer, which is in the core of the 53 | ** ship and has considerable redundancy) almost never get 54 | ** damaged, whereas devices which are exposed (such as the 55 | ** warp engines) or which are particularly delicate (such as 56 | ** the transporter) have a much higher probability of being 57 | ** damaged. 58 | ** 59 | ** The actual amount of damage (i.e., how long it takes to fix 60 | ** it) depends on the amount of the hit and the "damfac[]" 61 | ** entry for the particular device. 62 | ** 63 | ** Casualties can also occur. 64 | */ 65 | 66 | /* resting: set if attack while resting */ 67 | void 68 | attack(int resting) 69 | { 70 | int hit, i, l; 71 | int maxhit, tothit, shldabsb; 72 | double chgfac, propor, extradm; 73 | double dustfac, tothe; 74 | int cas; 75 | int hitflag; 76 | 77 | if (Move.free) 78 | return; 79 | if (Etc.nkling <= 0 || Quad[Ship.quadx][Ship.quady].stars < 0) 80 | return; 81 | if (Ship.cloaked && Ship.cloakgood) 82 | return; 83 | /* move before attack */ 84 | klmove(0); 85 | if (Ship.cond == DOCKED) { 86 | if (!resting) 87 | printf("Starbase shields protect the %s\n", Ship.shipname); 88 | return; 89 | } 90 | /* setup shield effectiveness */ 91 | chgfac = 1.0; 92 | if (Move.shldchg) 93 | chgfac = 0.25 + 0.50 * franf(); 94 | maxhit = tothit = 0; 95 | hitflag = 0; 96 | 97 | /* let each Klingon do his damndest */ 98 | for (i = 0; i < Etc.nkling; i++) { 99 | /* if he's low on power he won't attack */ 100 | if (Etc.klingon[i].power < 20) 101 | continue; 102 | if (!hitflag) { 103 | printf("\nStardate %.2f: Klingon attack:\n", 104 | Now.date); 105 | hitflag++; 106 | } 107 | /* complete the hit */ 108 | dustfac = 0.90 + 0.01 * franf(); 109 | tothe = Etc.klingon[i].avgdist; 110 | hit = Etc.klingon[i].power * pow(dustfac, tothe) * Param.hitfac; 111 | /* deplete his energy */ 112 | dustfac = Etc.klingon[i].power; 113 | Etc.klingon[i].power = dustfac * Param.phasfac * (1.0 + (franf() - 0.5) * 0.2); 114 | /* see how much of hit shields will absorb */ 115 | shldabsb = 0; 116 | if (Ship.shldup || Move.shldchg) { 117 | propor = Ship.shield; 118 | propor /= Param.shield; 119 | shldabsb = propor * chgfac * hit; 120 | if (shldabsb > Ship.shield) 121 | shldabsb = Ship.shield; 122 | Ship.shield -= shldabsb; 123 | } 124 | /* actually do the hit */ 125 | printf("\aHIT: %d units", hit); 126 | if (!damaged(SRSCAN)) 127 | printf(" from %d,%d", Etc.klingon[i].x, Etc.klingon[i].y); 128 | cas = (shldabsb * 100) / hit; 129 | hit -= shldabsb; 130 | if (shldabsb > 0) 131 | printf(", shields absorb %d%%, effective hit %d\n", 132 | cas, hit); 133 | else 134 | printf("\n"); 135 | tothit += hit; 136 | if (hit > maxhit) 137 | maxhit = hit; 138 | Ship.energy -= hit; 139 | /* see if damages occurred */ 140 | if (hit >= (15 - Game.skill) * (25 - ranf(12))) { 141 | printf("\aCRITICAL HIT!!!\a\n"); 142 | /* select a device from probability vector */ 143 | cas = ranf(1000); 144 | for (l = 0; cas >= 0; l++) 145 | cas -= Param.damprob[l]; 146 | l -= 1; 147 | /* compute amount of damage */ 148 | extradm = (hit * Param.damfac[l]) / (75 + ranf(25)) + 0.5; 149 | /* damage the device */ 150 | damage(l, extradm); 151 | if (damaged(SHIELD)) { 152 | if (Ship.shldup) 153 | printf("Sulu: Shields knocked down, captain.\n"); 154 | Ship.shldup = 0; 155 | Move.shldchg = 0; 156 | } 157 | } 158 | if (Ship.energy <= 0) 159 | lose(L_DSTRYD); 160 | } 161 | 162 | /* see what our casualities are like */ 163 | if (maxhit >= 200 || tothit >= 500) { 164 | cas = tothit * 0.015 * franf(); 165 | if (cas >= 2) { 166 | printf("McCoy: we suffered %d casualties in that attack.\n", 167 | cas); 168 | Game.deaths += cas; 169 | Ship.crew -= cas; 170 | } 171 | } 172 | 173 | /* allow Klingons to move after attacking */ 174 | klmove(1); 175 | 176 | return; 177 | } 178 | -------------------------------------------------------------------------------- /warp.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)warp.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/warp.c,v 1.4 1999/11/30 03:49:56 billf Exp $ 31 | * $DragonFly: src/games/trek/warp.c,v 1.4 2007/05/13 18:33:55 swildner Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** MOVE UNDER WARP POWER 39 | ** 40 | ** This is both the "move" and the "ram" commands, differing 41 | ** only in the flag 'fl'. It is also used for automatic 42 | ** emergency override mode, when 'fl' is < 0 and 'c' and 'd' 43 | ** are the course and distance to be moved. If 'fl' >= 0, 44 | ** the course and distance are asked of the captain. 45 | ** 46 | ** The guts of this routine are in the routine move(), which 47 | ** is shared with impulse(). Also, the working part of this 48 | ** routine is very small; the rest is to handle the slight chance 49 | ** that you may be moving at some riduculous speed. In that 50 | ** case, there is code to handle time warps, etc. 51 | */ 52 | 53 | /* 54 | * dowarp() is used in a struct cvntab to call warp(). Since it is always ram 55 | * or move, fl is never < 0, so ask the user for course and distance, then pass 56 | * that to warp(). 57 | */ 58 | void 59 | dowarp(int fl) 60 | { 61 | int c; 62 | double d; 63 | 64 | if (getcodi(&c, &d)) 65 | return; 66 | warp(fl, c, d); 67 | } 68 | 69 | void 70 | warp(int fl, int c, double d) 71 | { 72 | int course; 73 | double power; 74 | double dist; 75 | double p_time; 76 | double speed; 77 | double frac; 78 | int percent; 79 | int i; 80 | char *s; 81 | 82 | if (Ship.cond == DOCKED) { 83 | printf("%s is docked\n", Ship.shipname); 84 | return; 85 | } 86 | if (damaged(WARP)) { 87 | out(WARP); 88 | return; 89 | } 90 | course = c; 91 | dist = d; 92 | 93 | /* check to see that we are not using an absurd amount of power */ 94 | power = (dist + 0.05) * Ship.warp3; 95 | percent = 100 * power / Ship.energy + 0.5; 96 | if (percent >= 85) { 97 | printf("Scotty: That would consume %d%% of our remaining energy.\n", 98 | percent); 99 | if (!getynpar("Are you sure that is wise")) 100 | return; 101 | } 102 | 103 | /* compute the speed we will move at, and the time it will take */ 104 | speed = Ship.warp2 / Param.warptime; 105 | p_time = dist / speed; 106 | 107 | /* check to see that that value is not ridiculous */ 108 | percent = 100 * p_time / Now.time + 0.5; 109 | if (percent >= 85) { 110 | printf("Spock: That would take %d%% of our remaining time.\n", 111 | percent); 112 | if (!getynpar("Are you sure that is wise")) 113 | return; 114 | } 115 | 116 | /* compute how far we will go if we get damages */ 117 | if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0)) { 118 | frac = franf(); 119 | dist *= frac; 120 | p_time *= frac; 121 | damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20); 122 | } 123 | 124 | /* do the move */ 125 | Move.time = move(fl, course, p_time, speed); 126 | 127 | /* see how far we actually went, and decrement energy appropriately */ 128 | dist = Move.time * speed; 129 | Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1); 130 | 131 | /* test for bizarre events */ 132 | if (Ship.warp <= 9.0) 133 | return; 134 | printf("\n\n ___ Speed exceeding warp nine ___\n\n"); 135 | sleep(2); 136 | printf("Ship's safety systems malfunction\n"); 137 | sleep(2); 138 | printf("Crew experiencing extreme sensory distortion\n"); 139 | sleep(4); 140 | if (ranf(100) >= 100 * dist) { 141 | printf("Equilibrium restored -- all systems normal\n"); 142 | return; 143 | } 144 | 145 | /* select a bizzare thing to happen to us */ 146 | percent = ranf(100); 147 | if (percent < 70) { 148 | /* time warp */ 149 | if (percent < 35 || !Game.snap) { 150 | /* positive time warp */ 151 | p_time = (Ship.warp - 8.0) * dist * (franf() + 1.0); 152 | Now.date += p_time; 153 | printf("Positive time portal entered -- it is now Stardate %.2f\n", 154 | Now.date); 155 | for (i = 0; i < MAXEVENTS; i++) { 156 | percent = Event[i].evcode; 157 | if (percent == E_FIXDV || percent == E_LRTB) 158 | Event[i].date += p_time; 159 | } 160 | return; 161 | } 162 | 163 | /* s/he got lucky: a negative time portal */ 164 | p_time = Now.date; 165 | s = Etc.snapshot; 166 | bmove(s, Quad, sizeof Quad); 167 | bmove(s += sizeof Quad, Event, sizeof Event); 168 | bmove(s += sizeof Event, &Now, sizeof Now); 169 | printf("Negative time portal entered -- it is now Stardate %.2f\n", 170 | Now.date); 171 | for (i = 0; i < MAXEVENTS; i++) 172 | if (Event[i].evcode == E_FIXDV) 173 | reschedule(&Event[i], Event[i].date - p_time); 174 | return; 175 | } 176 | 177 | /* test for just a lot of damage */ 178 | if (percent < 80) 179 | lose(L_TOOFAST); 180 | printf("Equilibrium restored -- extreme damage occurred to ship systems\n"); 181 | for (i = 0; i < NDEV; i++) 182 | damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]); 183 | Ship.shldup = 0; 184 | } 185 | -------------------------------------------------------------------------------- /getpar.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)getpar.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/getpar.c,v 1.5 1999/11/30 03:49:48 billf Exp $ 31 | */ 32 | 33 | #include "getpar.h" 34 | #include "trek.h" 35 | 36 | static bool testterm(void); 37 | 38 | /** 39 | ** get integer parameter 40 | **/ 41 | 42 | int 43 | getintpar(const char *s) 44 | { 45 | int i; 46 | int n; 47 | 48 | while (1) { 49 | if (testnl() && s) 50 | printf("%s: ", s); 51 | i = scanf("%d", &n); 52 | if (i < 0) 53 | exit(1); 54 | if (i > 0 && testterm()) 55 | return (n); 56 | printf("invalid input; please enter an integer\n"); 57 | skiptonl(0); 58 | } 59 | } 60 | 61 | /** 62 | ** get floating parameter 63 | **/ 64 | 65 | double 66 | getfltpar(const char *s) 67 | { 68 | int i; 69 | double d; 70 | 71 | while (1) { 72 | if (testnl() && s) 73 | printf("%s: ", s); 74 | i = scanf("%lf", &d); 75 | if (i < 0) 76 | exit(1); 77 | if (i > 0 && testterm()) 78 | return (d); 79 | printf("invalid input; please enter a double\n"); 80 | skiptonl(0); 81 | } 82 | } 83 | 84 | /** 85 | ** get yes/no parameter 86 | **/ 87 | 88 | struct cvntab Yntab[] = { 89 | { "y", "es", (cmdfun)1, 0 }, 90 | { "n", "o", (cmdfun)0, 0 }, 91 | { NULL, NULL, NULL, 0 } 92 | }; 93 | 94 | long 95 | getynpar(const char *s) 96 | { 97 | struct cvntab *r; 98 | 99 | r = getcodpar(s, Yntab); 100 | return ((long) r->value); 101 | } 102 | 103 | 104 | /** 105 | ** get coded parameter 106 | **/ 107 | 108 | struct cvntab * 109 | getcodpar(const char *s, struct cvntab tab[]) 110 | { 111 | char input[100]; 112 | struct cvntab *r; 113 | int flag; 114 | char *p; 115 | const char *q; 116 | int c; 117 | int f; 118 | 119 | flag = 0; 120 | while (1) { 121 | flag |= (f = testnl()); 122 | if (flag) 123 | printf("%s: ", s); 124 | if (f) 125 | cgetc(0); /* throw out the newline */ 126 | scanf("%*[ \t;]"); 127 | if ((c = scanf("%[^ \t;\n]", input)) < 0) 128 | exit(1); 129 | if (c == 0) 130 | continue; 131 | flag = 1; 132 | 133 | /* if command list, print four per line */ 134 | if (input[0] == '?' && input[1] == 0) { 135 | c = 4; 136 | for (r = tab; r->abrev; r++) { 137 | strcpy(input, r->abrev); 138 | strcat(input, r->full); 139 | printf("%14.14s", input); 140 | if (--c > 0) 141 | continue; 142 | c = 4; 143 | printf("\n"); 144 | } 145 | if (c != 4) 146 | printf("\n"); 147 | continue; 148 | } 149 | 150 | /* search for in table */ 151 | for (r = tab; r->abrev; r++) { 152 | p = input; 153 | for (q = r->abrev; *q; q++) 154 | if (*p++ != *q) 155 | break; 156 | if (!*q) { 157 | for (q = r->full; *p && *q; q++, p++) 158 | if (*p != *q) 159 | break; 160 | if (!*p || !*q) 161 | break; 162 | } 163 | } 164 | 165 | /* check for not found */ 166 | if (!r->abrev) { 167 | printf("invalid input; ? for valid inputs\n"); 168 | skiptonl(0); 169 | } 170 | else 171 | return (r); 172 | } 173 | } 174 | 175 | 176 | /** 177 | ** get string parameter 178 | **/ 179 | 180 | void 181 | getstrpar(const char *s, char *r, int l, const char *t) 182 | { 183 | int i; 184 | char format[20]; 185 | int f; 186 | 187 | if (t == NULL) 188 | t = " \t\n;"; 189 | sprintf(format, "%%%d[^%s]", l, t); 190 | while (1) { 191 | if ((f = testnl()) && s) 192 | printf("%s: ", s); 193 | if (f) 194 | cgetc(0); 195 | scanf("%*[\t ;]"); 196 | i = scanf(format, r); 197 | if (i < 0) 198 | exit(1); 199 | if (i != 0) 200 | return; 201 | } 202 | } 203 | 204 | 205 | /** 206 | ** test if newline is next valid character 207 | **/ 208 | 209 | bool 210 | testnl(void) 211 | { 212 | char c; 213 | 214 | while ((c = cgetc(0)) != '\n') { 215 | if ((c >= '0' && c <= '9') || c == '.' || c == '!' || 216 | (c >= 'A' && c <= 'Z') || 217 | (c >= 'a' && c <= 'z') || c == '-') { 218 | ungetc(c, stdin); 219 | return(0); 220 | } 221 | } 222 | ungetc(c, stdin); 223 | return (1); 224 | } 225 | 226 | 227 | /** 228 | ** scan for newline 229 | **/ 230 | 231 | void 232 | skiptonl(char c) 233 | { 234 | while (c != '\n') { 235 | if (!(c = cgetc(0))) 236 | return; 237 | } 238 | ungetc('\n', stdin); 239 | return; 240 | } 241 | 242 | 243 | /** 244 | ** test for valid terminator 245 | **/ 246 | 247 | static bool 248 | testterm(void) 249 | { 250 | char c; 251 | 252 | if (!(c = cgetc(0))) 253 | return (1); 254 | if (c == '.') 255 | return (0); 256 | if (c == '\n' || c == ';') 257 | ungetc(c, stdin); 258 | return (1); 259 | } 260 | 261 | 262 | /* 263 | ** TEST FOR SPECIFIED DELIMITER 264 | ** 265 | ** The standard input is scanned for the parameter. If found, 266 | ** it is thrown away and non-zero is returned. If not found, 267 | ** zero is returned. 268 | */ 269 | 270 | bool 271 | readdelim(char d) 272 | { 273 | char c; 274 | 275 | while ((c = cgetc(0))) { 276 | if (c == d) 277 | return (1); 278 | if (c == ' ') 279 | continue; 280 | ungetc(c, stdin); 281 | break; 282 | } 283 | return (0); 284 | } 285 | -------------------------------------------------------------------------------- /torped.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)torped.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/torped.c,v 1.5 1999/11/30 03:49:55 billf Exp $ 31 | * $DragonFly: src/games/trek/torped.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | static int randcourse(int); 38 | 39 | /* 40 | ** PHOTON TORPEDO CONTROL 41 | ** 42 | ** Either one or three photon torpedoes are fired. If three 43 | ** are fired, it is called a "burst" and you also specify 44 | ** a spread angle. 45 | ** 46 | ** Torpedoes are never 100% accurate. There is always a random 47 | ** cludge factor in their course which is increased if you have 48 | ** your shields up. Hence, you will find that they are more 49 | ** accurate at close range. However, they have the advantage that 50 | ** at long range they don't lose any of their power as phasers 51 | ** do, i.e., a hit is a hit is a hit, by any other name. 52 | ** 53 | ** When the course spreads too much, you get a misfire, and the 54 | ** course is randomized even more. You also have the chance that 55 | ** the misfire damages your torpedo tubes. 56 | */ 57 | 58 | void 59 | torped(int v __unused) 60 | { 61 | int ix, iy; 62 | double x, y, dx, dy; 63 | double angle; 64 | int course, course2; 65 | int k; 66 | double bigger; 67 | double sectsize; 68 | int burst; 69 | int n; 70 | 71 | if (Ship.cloaked) { 72 | printf("Federation regulations do not permit attack while cloaked.\n"); 73 | return; 74 | } 75 | if (check_out(TORPED)) 76 | return; 77 | if (Ship.torped <= 0) { 78 | printf("All photon torpedos expended\n"); 79 | return; 80 | } 81 | 82 | /* get the course */ 83 | course = getintpar("Torpedo course"); 84 | if (course < 0 || course > 360) 85 | return; 86 | burst = -1; 87 | 88 | /* need at least three torpedoes for a burst */ 89 | if (Ship.torped < 3) { 90 | printf("No-burst mode selected\n"); 91 | burst = 0; 92 | } else { 93 | /* see if the user wants one */ 94 | if (!testnl()) { 95 | k = ungetc(cgetc(0), stdin); 96 | if (k >= '0' && k <= '9') 97 | burst = 1; 98 | } 99 | } 100 | if (burst < 0) { 101 | burst = getynpar("Do you want a burst"); 102 | } 103 | if (burst) { 104 | burst = getintpar("burst angle"); 105 | if (burst <= 0) 106 | return; 107 | if (burst > 15) { 108 | printf("Maximum burst angle is 15 degrees\n"); 109 | return; 110 | } 111 | } 112 | sectsize = NSECTS; 113 | n = -1; 114 | if (burst) { 115 | n = 1; 116 | course -= burst; 117 | } 118 | for (; n && n <= 3; n++) { 119 | /* select a nice random course */ 120 | course2 = course + randcourse(n); 121 | angle = course2 * 0.0174532925; /* convert to radians */ 122 | dx = -cos(angle); 123 | dy = sin(angle); 124 | bigger = fabs(dx); 125 | x = fabs(dy); 126 | if (x > bigger) 127 | bigger = x; 128 | dx /= bigger; 129 | dy /= bigger; 130 | x = Ship.sectx + 0.5; 131 | y = Ship.secty + 0.5; 132 | if (Ship.cond != DOCKED) 133 | Ship.torped -= 1; 134 | printf("Torpedo track"); 135 | if (n > 0) 136 | printf(", torpedo number %d", n); 137 | printf(":\n%6.1f\t%4.1f\n", x, y); 138 | while (1) { 139 | ix = x += dx; 140 | iy = y += dy; 141 | if (x < 0.0 || x >= sectsize || 142 | y < 0.0 || y >= sectsize) { 143 | printf("Torpedo missed\n"); 144 | break; 145 | } 146 | printf("%6.1f\t%4.1f\n", x, y); 147 | switch (Sect[ix][iy]) { 148 | case EMPTY: 149 | continue; 150 | 151 | case HOLE: 152 | printf("Torpedo disappears into a black hole\n"); 153 | break; 154 | 155 | case KLINGON: 156 | for (k = 0; k < Etc.nkling; k++) { 157 | if (Etc.klingon[k].x != ix || Etc.klingon[k].y != iy) 158 | continue; 159 | Etc.klingon[k].power -= 500 + ranf(501); 160 | if (Etc.klingon[k].power > 0) { 161 | printf("*** Hit on Klingon at %d,%d: extensive damages\n", 162 | ix, iy); 163 | break; 164 | } 165 | killk(ix, iy); 166 | break; 167 | } 168 | break; 169 | 170 | case STAR: 171 | nova(ix, iy); 172 | break; 173 | 174 | case INHABIT: 175 | kills(ix, iy, -1); 176 | break; 177 | 178 | case BASE: 179 | killb(Ship.quadx, Ship.quady); 180 | Game.killb += 1; 181 | break; 182 | default: 183 | printf("Unknown object %c at %d,%d destroyed\n", 184 | Sect[ix][iy], ix, iy); 185 | Sect[ix][iy] = EMPTY; 186 | break; 187 | } 188 | break; 189 | } 190 | if (damaged(TORPED) || Quad[Ship.quadx][Ship.quady].stars < 0) 191 | break; 192 | course += burst; 193 | } 194 | Move.free = 0; 195 | } 196 | 197 | 198 | /* 199 | ** RANDOMIZE COURSE 200 | ** 201 | ** This routine randomizes the course for torpedo number 'n'. 202 | ** Other things handled by this routine are misfires, damages 203 | ** to the tubes, etc. 204 | */ 205 | 206 | static int 207 | randcourse(int n) 208 | { 209 | double r; 210 | int d; 211 | 212 | d = ((franf() + franf()) - 1.0) * 20; 213 | if (abs(d) > 12) { 214 | printf("Photon tubes misfire"); 215 | if (n < 0) 216 | printf("\n"); 217 | else 218 | printf(" on torpedo %d\n", n); 219 | if (ranf(2)) { 220 | damage(TORPED, 0.2 * abs(d) * (franf() + 1.0)); 221 | } 222 | d *= 1.0 + 2.0 * franf(); 223 | } 224 | if (Ship.shldup || Ship.cond == DOCKED) { 225 | r = Ship.shield; 226 | r = 1.0 + r / Param.shield; 227 | if (Ship.cond == DOCKED) 228 | r = 2.0; 229 | d *= r; 230 | } 231 | return (d); 232 | } 233 | -------------------------------------------------------------------------------- /DOC/read_me.nr: -------------------------------------------------------------------------------- 1 | .\" $FreeBSD: src/games/trek/DOC/read_me.nr,v 1.1.1.1.14.1 2001/03/05 12:11:40 kris Exp $ 2 | .\" $DragonFly: src/games/trek/DOC/read_me.nr,v 1.2 2003/06/17 04:25:25 dillon Exp $ 3 | .de @h 4 | 'sp 4 5 | 'tl 'TREK SETUP INSTRUCTIONS''%' 6 | 'sp 2 7 | .ns 8 | .. 9 | .de @f 10 | 'bp 11 | .. 12 | .wh 0 @h 13 | .wh -6 @f 14 | .de pp 15 | .sp 16 | .ne 2 17 | .ti +5 18 | .. 19 | .de s1 20 | .sp 2 21 | .nr S1 +1 22 | .nr S2 0 23 | .ne 5 24 | .in 4 25 | .ti 0 26 | \\n(S1.\ \ \c 27 | .. 28 | .de s2 29 | .sp 1 30 | .nr S2 +1 31 | .ne 3 32 | .in 8 33 | .ti 4 34 | \\n(S2.\ \ \c 35 | .. 36 | .br 37 | .ce 38 | TREK SETUP INSTRUCTIONS 39 | .sp 2 40 | .pp 41 | This document describes all sorts of nifty things 42 | you should know 43 | before you start to muck around 44 | with the trek source code. 45 | Please read them carefully. 46 | .s1 47 | MAINTENANCE 48 | .s2 49 | There are a number of shell files 50 | which you may use to maintain the system. 51 | "Prtrek" produces a copy of the source code. 52 | It pipes its output to lpr 53 | and runs in background. 54 | "Comp" compiles up to nine source modules 55 | and leaves them in .o files. 56 | "Compile" is the same as "comp" 57 | except that it loads after compiling. 58 | If stated without any arguments, 59 | it loads from .o files. 60 | "Compall" compiles all the .c files 61 | into .o files, 62 | but does not load. 63 | It redirects its output to the file "output". 64 | To recompile the entire system, 65 | type 66 | .ti +8 67 | compall 68 | .ti +8 69 | compile 70 | .br 71 | .s2 72 | Main.c contains a variable called "Mother". 73 | This is initialized to the result of the 74 | "getuid()" call for the maintainer of trek 75 | at your installation. 76 | Only Mother is allowed to set trace flags 77 | and run the game at other than the default priority. 78 | .s2 79 | Speaking of priorities, 80 | trek eats up a lot of system resources. 81 | Hence, it normally runs at a very low priority. 82 | This makes it almost impossible to play 83 | if the system is loaded. 84 | However, 85 | the -pN flag sets the priority to N, 86 | which makes it possible to debug 87 | when the system is loaded. 88 | The default priority is set by a #define of 89 | PRIO, 90 | which is set to 10 in the default system. 91 | .s2 92 | Trace information is provided 93 | which may be useful in debugging things in the system. 94 | If you are in a bad way for space, 95 | comment out the #define xTRACE 96 | which appears in trek.h. 97 | This will cause the trace stuff to not occur 98 | in the object. 99 | .s2 100 | The version of trek released to you 101 | is compiled with the -f flag (for no floating point) 102 | and should work without problems on your machine. 103 | You can edit out the -f flag 104 | in "compile" if you have floating point hardware 105 | on your machine 106 | so that it will take less space. 107 | .s1 108 | THE PORTABLE C LIBRARY 109 | .pp 110 | The portable C library was used 111 | to do I/O in trek. 112 | Unfortunately, 113 | the version which we had at Berkeley 114 | had a number of small bugs 115 | which caused trek to do bad things at times. 116 | For some unknown reason 117 | (temporary insanity perhaps) 118 | I rewrote the portable C library. 119 | This version is much smaller than the old version 120 | and has cleaner code. 121 | It also works right 122 | (???). 123 | However, there are a few minor differences 124 | which you should be aware of. 125 | .s2 126 | Scanf no longer ignores the noise characters "\\n", 127 | "\\t", and space in the format string; 128 | i.e., 129 | these characters now require a match 130 | in the input stream. 131 | .s2 132 | A variable 133 | f_log 134 | has been added 135 | which is the file descriptor 136 | of a "log" file. 137 | If f_log is greater than zero 138 | a copy of everything read from 139 | the standard input 140 | and written to 141 | the standard output 142 | is written in the file f_log. 143 | .s1 144 | DISCLAIMERS 145 | .s2 146 | Frankly, 147 | I am getting pretty sick of playing this game. 148 | Hence, 149 | the version which you get may have several bugs 150 | in it; 151 | I freely admit 152 | that it is probably buggier 153 | than some previous versions. 154 | Sorry about that. 155 | .s2 156 | Along with being buggy, 157 | the game never had quite everything implemented 158 | that was originally intended. 159 | If you see things that look weird, 160 | that may be why. 161 | There are even some features which I have taken out 162 | (like ghost starsystems) 163 | upon deciding that I didn't have the energy 164 | to implement them correctly. 165 | .s1 166 | REQUESTS 167 | .pp 168 | There are several things that I would like to ask of anyone 169 | who does work on the source code. 170 | .s2 171 | Please let me know of any bugs which you find 172 | in the code, 173 | and any fixes which you may have. 174 | Other copies will probably be going out to other people later, 175 | and it would be nice if those copies where less buggy. 176 | Also, 177 | I would be interested in hearing about any 178 | enhancements of the game which you might install. 179 | .s2 180 | Please note that I have a distinct coding style. 181 | I feel that it is cleaner 182 | and easier to read than a more 183 | casual style. 184 | If possible, 185 | please stick to it, 186 | especially if you end up sending tapes back to me. 187 | This goes along with my whole belief in clean code: 188 | I ask you to please avoid obscure code 189 | whenever possible. 190 | If you throw some in, 191 | please don't let me see it. 192 | It just depresses me. 193 | .s2 194 | Unfortunately, 195 | the game is huge. 196 | There are many neat things 197 | which could go in, 198 | if there were only enough space. 199 | However, 200 | I have specifically not gone to separated I/D 201 | space. 202 | The main reason is that I would like future versions 203 | of the game 204 | to be 11/40 compatible. 205 | .s1 206 | SUGGESTIONS FOR THE FUTURE 207 | .pp 208 | If you happen to have more energy than I do, 209 | you may want to examine the following areas. 210 | These are things that I may get to, 211 | but don't hold your breath. 212 | .s2 213 | Frankly, 214 | making the portable C library work 215 | (even without bugs) 216 | was a bitch. 217 | I should have done the I/O in a more 218 | ad hoc manner. 219 | It is my intent to rewrite the I/O 220 | routines to bypass the portable C library entirely. 221 | .s2 222 | The routine "capture" is quite unclean. 223 | First, it should have a manner of selecting Klingons 224 | other than random, 225 | either selecting the most likely 226 | or asking the captain (probably best). 227 | It should either be fully implemented, 228 | which includes adding a "board" routine 229 | (half written, 230 | on some tapes as board.x) 231 | which sends a boarding party to forcefully 232 | take over the Klingon, 233 | or it should go out completely, 234 | which is probably what I will end up doing. 235 | When this happens, 236 | the transporter will go completely. 237 | It seems that the space may be better used 238 | for something which more directly enhances the game. 239 | .sp 3 240 | .in 0 241 | Well, that's about it. 242 | To get hold of me, 243 | write to: 244 | .nf 245 | .sp 246 | Eric P Allman 247 | Electronics Research Laboratory 248 | University of California 249 | Berkeley, California 94720 250 | .fi 251 | 252 | Happy trekking!! 253 | .pp 254 | -------------------------------------------------------------------------------- /move.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)move.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/move.c,v 1.6 1999/11/30 03:49:50 billf Exp $ 31 | * $DragonFly: src/games/trek/move.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | 36 | /* 37 | ** Move Under Warp or Impulse Power 38 | ** 39 | ** `Ramflag' is set if we are to be allowed to ram stars, 40 | ** Klingons, etc. This is passed from warp(), which gets it from 41 | ** either play() or ram(). Course is the course (0 -> 360) at 42 | ** which we want to move. `Speed' is the speed we 43 | ** want to go, and `p_time' is the expected time. It 44 | ** can get cut short if a long range tractor beam is to occur. We 45 | ** cut short the move so that the user doesn't get docked time and 46 | ** energy for distance which he didn't travel. 47 | ** 48 | ** We check the course through the current quadrant to see that he 49 | ** doesn't run into anything. After that, though, space sort of 50 | ** bends around him. Note that this puts us in the awkward posi- 51 | ** tion of being able to be dropped into a sector which is com- 52 | ** pletely surrounded by stars. Oh Well. 53 | ** 54 | ** If the SINS (Space Inertial Navigation System) is out, we ran- 55 | ** domize the course accordingly before ever starting to move. 56 | ** We will still move in a straight line. 57 | ** 58 | ** Note that if your computer is out, you ram things anyway. In 59 | ** other words, if your computer and sins are both out, you're in 60 | ** potentially very bad shape. 61 | ** 62 | ** Klingons get a chance to zap you as you leave the quadrant. 63 | ** By the way, they also try to follow you (heh heh). 64 | ** 65 | ** Return value is the actual amount of time used. 66 | ** 67 | ** 68 | ** Uses trace flag 4. 69 | */ 70 | 71 | double 72 | move(int ramflag, int course, double p_time, double speed) 73 | { 74 | double angle; 75 | double x, y, dx, dy; 76 | int ix, iy; 77 | double bigger; 78 | int n; 79 | int i; 80 | double dist; 81 | double sectsize; 82 | double xn; 83 | double evtime; 84 | 85 | ix = iy = 0; 86 | #ifdef xTRACE 87 | if (Trace) 88 | printf("move: ramflag %d course %d time %.2f speed %.2f\n", 89 | ramflag, course, p_time, speed); 90 | #endif 91 | sectsize = NSECTS; 92 | /* initialize delta factors for move */ 93 | angle = course * 0.0174532925; 94 | if (damaged(SINS)) 95 | angle += Param.navigcrud[1] * (franf() - 0.5); 96 | else 97 | if (Ship.sinsbad) 98 | angle += Param.navigcrud[0] * (franf() - 0.5); 99 | dx = -cos(angle); 100 | dy = sin(angle); 101 | bigger = fabs(dx); 102 | dist = fabs(dy); 103 | if (dist > bigger) 104 | bigger = dist; 105 | dx /= bigger; 106 | dy /= bigger; 107 | 108 | /* check for long range tractor beams */ 109 | /**** TEMPORARY CODE == DEBUGGING ****/ 110 | evtime = Now.eventptr[E_LRTB]->date - Now.date; 111 | #ifdef xTRACE 112 | if (Trace) 113 | printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n", 114 | (void *)Now.eventptr[E_LRTB], 115 | Now.eventptr[E_LRTB]->evcode, 116 | Now.eventptr[E_LRTB]->date, evtime); 117 | #endif 118 | if (p_time > evtime && Etc.nkling < 3) { 119 | /* then we got a LRTB */ 120 | evtime += 0.005; 121 | p_time = evtime; 122 | } else 123 | evtime = -1.0e50; 124 | dist = p_time * speed; 125 | 126 | /* move within quadrant */ 127 | Sect[Ship.sectx][Ship.secty] = EMPTY; 128 | x = Ship.sectx + 0.5; 129 | y = Ship.secty + 0.5; 130 | xn = NSECTS * dist * bigger; 131 | n = xn + 0.5; 132 | #ifdef xTRACE 133 | if (Trace) 134 | printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n); 135 | #endif 136 | Move.free = 0; 137 | 138 | for (i = 0; i < n; i++) { 139 | ix = (x += dx); 140 | iy = (y += dy); 141 | #ifdef xTRACE 142 | if (Trace) 143 | printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y); 144 | #endif 145 | if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) { 146 | /* enter new quadrant */ 147 | dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn; 148 | dy = Ship.quady * NSECTS + Ship.secty + dy * xn; 149 | if (dx < 0.0) 150 | ix = -1; 151 | else 152 | ix = dx + 0.5; 153 | if (dy < 0.0) 154 | iy = -1; 155 | else 156 | iy = dy + 0.5; 157 | #ifdef xTRACE 158 | if (Trace) 159 | printf("New quad: ix = %d, iy = %d\n", ix, iy); 160 | #endif 161 | Ship.sectx = x; 162 | Ship.secty = y; 163 | compkldist(0); 164 | Move.newquad = 2; 165 | attack(0); 166 | checkcond(); 167 | Ship.quadx = ix / NSECTS; 168 | Ship.quady = iy / NSECTS; 169 | Ship.sectx = ix % NSECTS; 170 | Ship.secty = iy % NSECTS; 171 | if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 || 172 | Ship.quady >= NQUADS) { 173 | if (!damaged(COMPUTER)) { 174 | dumpme(0); 175 | } else 176 | lose(L_NEGENB); 177 | } 178 | initquad(0); 179 | n = 0; 180 | break; 181 | } 182 | if (Sect[ix][iy] != EMPTY) { 183 | /* we just hit something */ 184 | if (!damaged(COMPUTER) && ramflag <= 0) { 185 | ix = x - dx; 186 | iy = y - dy; 187 | printf("Computer reports navigation error; %s stopped at %d,%d\n", 188 | Ship.shipname, ix, iy); 189 | Ship.energy -= Param.stopengy * speed; 190 | break; 191 | } 192 | /* test for a black hole */ 193 | if (Sect[ix][iy] == HOLE) { 194 | /* get dumped elsewhere in the galaxy */ 195 | dumpme(1); 196 | initquad(0); 197 | n = 0; 198 | break; 199 | } 200 | ram(ix, iy); 201 | break; 202 | } 203 | } 204 | if (n > 0) { 205 | dx = Ship.sectx - ix; 206 | dy = Ship.secty - iy; 207 | dist = sqrt(dx * dx + dy * dy) / NSECTS; 208 | p_time = dist / speed; 209 | if (evtime > p_time) 210 | p_time = evtime; /* spring the LRTB trap */ 211 | Ship.sectx = ix; 212 | Ship.secty = iy; 213 | } 214 | Sect[Ship.sectx][Ship.secty] = Ship.ship; 215 | compkldist(0); 216 | return (p_time); 217 | } 218 | -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved. 30 | * @(#)main.c 8.1 (Berkeley) 5/31/93 31 | * $FreeBSD: src/games/trek/main.c,v 1.7.2.1 2001/03/05 12:11:14 kris Exp $ 32 | */ 33 | 34 | #include 35 | #include "trek.h" 36 | #include "getpar.h" 37 | 38 | unsigned int Mother = 51 + (51 << 8); 39 | 40 | /* 41 | ** #### ##### # #### ##### #### ##### # # 42 | ** # # # # # # # # # # # # 43 | ** ### # ##### #### # #### ### ### 44 | ** # # # # # # # # # # # # 45 | ** #### # # # # # # # # ##### # # 46 | ** 47 | ** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help 48 | ** from Jeff Poskanzer and Pete Rubinstein. 49 | ** 50 | ** I also want to thank everyone here at Berkeley who 51 | ** where crazy enough to play the undebugged game. I want to 52 | ** particularly thank Nick Whyte, who made considerable 53 | ** suggestions regarding the content of the game. Why, I'll 54 | ** never forget the time he suggested the name for the 55 | ** "capture" command. 56 | ** 57 | ** Please send comments, questions, and suggestions about this 58 | ** game to: 59 | ** Eric P. Allman 60 | ** Project INGRES 61 | ** Electronics Research Laboratory 62 | ** Cory Hall 63 | ** University of California 64 | ** Berkeley, California 94720 65 | ** 66 | ** If you make ANY changes in the game, I sure would like to 67 | ** know about them. It is sort of an ongoing project for me, 68 | ** and I very much want to put in any bug fixes and improvements 69 | ** that you might come up with. 70 | ** 71 | ** FORTRASH version by Kay R. Fisher (DEC) "and countless others". 72 | ** That was adapted from the "original BASIC program" (ha!) by 73 | ** Mike Mayfield (Centerline Engineering). 74 | ** 75 | ** Additional inspiration taken from FORTRAN version by 76 | ** David Matuszek and Paul Reynolds which runs on the CDC 77 | ** 7600 at Lawrence Berkeley Lab, maintained there by 78 | ** Andy Davidson. This version is also available at LLL 79 | ** and at LMSC. In all fairness, this version was the 80 | ** major inspiration for this version of the game (trans- 81 | ** lation: I ripped off a whole lot of code). 82 | ** 83 | ** Minor other input from the "Battelle Version 7A" by Joe Miller 84 | ** (Graphics Systems Group, Battelle-Columbus Labs) and 85 | ** Ross Pavlac (Systems Programmer, Battelle Memorial 86 | ** Institute). That version was written in December '74 87 | ** and extensively modified June '75. It was adapted 88 | ** from the FTN version by Ron Williams of CDC Sunnyvale, 89 | ** which was adapted from the Basic version distributed 90 | ** by DEC. It also had "neat stuff swiped" from T. T. 91 | ** Terry and Jim Korp (University of Texas), Hicks (Penn 92 | ** U.), and Rick Maus (Georgia Tech). Unfortunately, it 93 | ** was not as readable as it could have been and so the 94 | ** translation effort was severely hampered. None the 95 | ** less, I got the idea of inhabited starsystems from this 96 | ** version. 97 | ** 98 | ** Permission is given for use, copying, and modification of 99 | ** all or part of this program and related documentation, 100 | ** provided that all reference to the authors are maintained. 101 | ** 102 | ** 103 | ********************************************************************** 104 | ** 105 | ** NOTES TO THE MAINTAINER: 106 | ** 107 | ** There is a compilation option xTRACE which must be set for any 108 | ** trace information to be generated. It is probably defined in 109 | ** the version that you get. It can be removed, however, if you 110 | ** have trouble finding room in core. 111 | ** 112 | ** Many things in trek are not as clear as they might be, but are 113 | ** done to reduce space. I compile with the -f and -O flags. I 114 | ** am constrained to running with non-separated I/D space, since 115 | ** we don't have doubleing point hardware here; even if we did, I 116 | ** would like trek to be available to the large number of people 117 | ** who either have an 11/40 or do not have FP hardware. I also 118 | ** found it desirable to make the code run reentrant, so this 119 | ** added even more space constraints. 120 | ** 121 | ** I use the portable C library to do my I/O. This is done be- 122 | ** cause I wanted the game easily transportable to other C 123 | ** implementations, and because I was too lazy to do the doubleing 124 | ** point input myself. Little did I know. The portable C library 125 | ** released by Bell Labs has more bugs than you would believe, so 126 | ** I ended up rewriting the whole blessed thing. Trek exercises 127 | ** many of the bugs in it, as well as bugs in some of the section 128 | ** III UNIX routines. We have fixed them here. One main problem 129 | ** was a bug in alloc() that caused it to always ask for a large 130 | ** hunk of memory, which worked fine unless you were almost out, 131 | ** which I inevitably was. If you want the code for all of this 132 | ** stuff, it is also available through me. 133 | ** 134 | *********************************************************************** 135 | */ 136 | 137 | jmp_buf env; 138 | 139 | int 140 | main(int argc, char **argv) 141 | { 142 | int ac; 143 | char **av; 144 | 145 | /* Revoke setgid privileges */ 146 | setgid(getgid()); 147 | 148 | av = argv; 149 | ac = argc; 150 | av++; 151 | srandom((unsigned)time(NULL)); /* srandomdev() */ 152 | while (ac > 1 && av[0][0] == '-') { 153 | switch (av[0][1]) { 154 | #ifdef xTRACE 155 | case 't': /* trace */ 156 | if (getuid() != Mother) 157 | goto badflag; 158 | Trace++; 159 | break; 160 | #endif 161 | default: 162 | badflag: 163 | printf("Invalid option: %s\n", av[0]); 164 | 165 | } 166 | ac--; 167 | av++; 168 | } 169 | if (ac > 1) 170 | syserr("arg count"); 171 | 172 | printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n"); 173 | 174 | if (setjmp(env)) { 175 | if ( !getynpar("Another game") ) 176 | exit(0); 177 | } 178 | do { 179 | setup(); 180 | play(); 181 | } while (getynpar("Another game")); 182 | 183 | fflush(stdout); 184 | return (0); 185 | } 186 | -------------------------------------------------------------------------------- /setup.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1980, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 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. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)setup.c 8.1 (Berkeley) 5/31/93 30 | * $FreeBSD: src/games/trek/setup.c,v 1.6 1999/11/30 03:49:54 billf Exp $ 31 | * $DragonFly: src/games/trek/setup.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $ 32 | */ 33 | 34 | #include "trek.h" 35 | #include "getpar.h" 36 | 37 | /* 38 | ** INITIALIZE THE GAME 39 | ** 40 | ** The length, skill, and password are read, and the game 41 | ** is initialized. It is far too difficult to describe all 42 | ** that goes on in here, but it is all straight-line code; 43 | ** give it a look. 44 | ** 45 | ** Game restart and tournament games are handled here. 46 | */ 47 | 48 | struct cvntab Lentab[] = { 49 | { "s", "hort", (cmdfun)1, 0 }, 50 | { "m", "edium", (cmdfun)2, 0 }, 51 | { "l", "ong", (cmdfun)4, 0 }, 52 | { "restart", "", NULL, 0 }, 53 | { NULL, NULL, NULL, 0 } 54 | }; 55 | 56 | struct cvntab Skitab[] = { 57 | { "n", "ovice", (cmdfun)1, 0 }, 58 | { "f", "air", (cmdfun)2, 0 }, 59 | { "g", "ood", (cmdfun)3, 0 }, 60 | { "e", "xpert", (cmdfun)4, 0 }, 61 | { "c", "ommodore", (cmdfun)5, 0 }, 62 | { "i", "mpossible", (cmdfun)6, 0 }, 63 | { NULL, NULL, NULL, 0 } 64 | }; 65 | 66 | void 67 | setup(void) 68 | { 69 | struct cvntab *r; 70 | int i, j; 71 | double f; 72 | int d; 73 | int klump; 74 | int ix, iy; 75 | struct quad *q; 76 | struct event *e; 77 | 78 | while (1) { 79 | r = getcodpar("What length game", Lentab); 80 | Game.length = (long) r->value; 81 | if (Game.length == 0) { 82 | if (restartgame()) 83 | continue; 84 | return; 85 | } 86 | break; 87 | } 88 | r = getcodpar("What skill game", Skitab); 89 | Game.skill = (long) r->value; 90 | Game.tourn = 0; 91 | getstrpar("Enter a password", Game.passwd, 14, 0); 92 | if (sequal(Game.passwd, "tournament")) { 93 | getstrpar("Enter tournament code", Game.passwd, 14, 0); 94 | Game.tourn = 1; 95 | d = 0; 96 | for (i = 0; Game.passwd[i]; i++) 97 | d += Game.passwd[i] << i; 98 | srandom(d); 99 | } 100 | Param.bases = Now.bases = ranf(6 - Game.skill) + 2; 101 | if (Game.skill == 6) 102 | Param.bases = Now.bases = 1; 103 | Param.time = Now.time = 6.0 * Game.length + 2.0; 104 | i = Game.skill; 105 | j = Game.length; 106 | Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75); 107 | if (Param.klings < i * j * 5) 108 | Param.klings = Now.klings = i * j * 5; 109 | if (Param.klings <= i) /* numerical overflow problems */ 110 | Param.klings = Now.klings = 127; 111 | Param.energy = Ship.energy = 5000; 112 | Param.torped = Ship.torped = 10; 113 | Ship.ship = ENTERPRISE; 114 | Ship.shipname = "Enterprise"; 115 | Param.shield = Ship.shield = 1500; 116 | Param.resource = Now.resource = Param.klings * Param.time; 117 | Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0; 118 | Param.crew = Ship.crew = 387; 119 | Param.brigfree = Ship.brigfree = 400; 120 | Ship.shldup = 1; 121 | Ship.cond = GREEN; 122 | Ship.warp = 5.0; 123 | Ship.warp2 = 25.0; 124 | Ship.warp3 = 125.0; 125 | Ship.sinsbad = 0; 126 | Ship.cloaked = 0; 127 | Param.date = Now.date = (ranf(20) + 20) * 100; 128 | f = Game.skill; 129 | f = log(f + 0.5); 130 | for (i = 0; i < NDEV; i++) 131 | if (Device[i].name[0] == '*') 132 | Param.damfac[i] = 0; 133 | else 134 | Param.damfac[i] = f; 135 | /* these probabilities must sum to 1000 */ 136 | Param.damprob[WARP] = 70; /* warp drive 7.0% */ 137 | Param.damprob[SRSCAN] = 110; /* short range scanners 11.0% */ 138 | Param.damprob[LRSCAN] = 110; /* long range scanners 11.0% */ 139 | Param.damprob[PHASER] = 125; /* phasers 12.5% */ 140 | Param.damprob[TORPED] = 125; /* photon torpedoes 12.5% */ 141 | Param.damprob[IMPULSE] = 75; /* impulse engines 7.5% */ 142 | Param.damprob[SHIELD] = 150; /* shield control 15.0% */ 143 | Param.damprob[COMPUTER] = 20; /* computer 2.0% */ 144 | Param.damprob[SSRADIO] = 35; /* subspace radio 3.5% */ 145 | Param.damprob[LIFESUP] = 30; /* life support 3.0% */ 146 | Param.damprob[SINS] = 20; /* navigation system 2.0% */ 147 | Param.damprob[CLOAK] = 50; /* cloaking device 5.0% */ 148 | Param.damprob[XPORTER] = 80; /* transporter 8.0% */ 149 | /* check to see that I didn't blow it */ 150 | for (i = j = 0; i < NDEV; i++) 151 | j += Param.damprob[i]; 152 | if (j != 1000) 153 | syserr("Device probabilities sum to %d", j); 154 | Param.dockfac = 0.5; 155 | Param.regenfac = (5 - Game.skill) * 0.05; 156 | if (Param.regenfac < 0.0) 157 | Param.regenfac = 0.0; 158 | Param.warptime = 10; 159 | Param.stopengy = 50; 160 | Param.shupengy = 40; 161 | i = Game.skill; 162 | Param.klingpwr = 100 + 150 * i; 163 | if (i >= 6) 164 | Param.klingpwr += 150; 165 | Param.phasfac = 0.8; 166 | Param.hitfac = 0.5; 167 | Param.klingcrew = 200; 168 | Param.srndrprob = 0.0035; 169 | Param.moveprob[KM_OB] = 45; 170 | Param.movefac[KM_OB] = .09; 171 | Param.moveprob[KM_OA] = 40; 172 | Param.movefac[KM_OA] = -0.05; 173 | Param.moveprob[KM_EB] = 40; 174 | Param.movefac[KM_EB] = 0.075; 175 | Param.moveprob[KM_EA] = 25 + 5 * Game.skill; 176 | Param.movefac[KM_EA] = -0.06 * Game.skill; 177 | Param.moveprob[KM_LB] = 0; 178 | Param.movefac[KM_LB] = 0.0; 179 | Param.moveprob[KM_LA] = 10 + 10 * Game.skill; 180 | Param.movefac[KM_LA] = 0.25; 181 | Param.eventdly[E_SNOVA] = 0.5; 182 | Param.eventdly[E_LRTB] = 25.0; 183 | Param.eventdly[E_KATSB] = 1.0; 184 | Param.eventdly[E_KDESB] = 3.0; 185 | Param.eventdly[E_ISSUE] = 1.0; 186 | Param.eventdly[E_SNAP] = 0.5; 187 | Param.eventdly[E_ENSLV] = 0.5; 188 | Param.eventdly[E_REPRO] = 2.0; 189 | Param.navigcrud[0] = 1.50; 190 | Param.navigcrud[1] = 0.75; 191 | Param.cloakenergy = 1000; 192 | Param.energylow = 1000; 193 | for (i = 0; i < MAXEVENTS; i++) { 194 | e = &Event[i]; 195 | e->date = TOOLARGE; 196 | e->evcode = 0; 197 | } 198 | xsched(E_SNOVA, 1, 0, 0, 0); 199 | xsched(E_LRTB, Param.klings, 0, 0, 0); 200 | xsched(E_KATSB, 1, 0, 0, 0); 201 | xsched(E_ISSUE, 1, 0, 0, 0); 202 | xsched(E_SNAP, 1, 0, 0, 0); 203 | Ship.sectx = ranf(NSECTS); 204 | Ship.secty = ranf(NSECTS); 205 | Game.killk = Game.kills = Game.killb = 0; 206 | Game.deaths = Game.negenbar = 0; 207 | Game.captives = 0; 208 | Game.killinhab = 0; 209 | Game.helps = 0; 210 | Game.killed = 0; 211 | Game.snap = 0; 212 | Move.endgame = 0; 213 | 214 | /* setup stars */ 215 | for (i = 0; i < NQUADS; i++) { 216 | for (j = 0; j < NQUADS; j++) { 217 | q = &Quad[i][j]; 218 | q->klings = q->bases = 0; 219 | q->scanned = -1; 220 | q->stars = ranf(9) + 1; 221 | q->holes = ranf(3) - q->stars / 5; 222 | q->qsystemname = 0; 223 | } 224 | } 225 | 226 | /* select inhabited starsystems */ 227 | for (d = 1; d < NINHAB; d++) { 228 | do { 229 | i = ranf(NQUADS); 230 | j = ranf(NQUADS); 231 | q = &Quad[i][j]; 232 | } while (q->qsystemname); 233 | q->qsystemname = d; 234 | } 235 | 236 | /* position starbases */ 237 | for (i = 0; i < Param.bases; i++) { 238 | while (1) { 239 | ix = ranf(NQUADS); 240 | iy = ranf(NQUADS); 241 | q = &Quad[ix][iy]; 242 | if (q->bases > 0) 243 | continue; 244 | break; 245 | } 246 | q->bases = 1; 247 | Now.base[i].x = ix; 248 | Now.base[i].y = iy; 249 | q->scanned = 1001; 250 | /* start the Enterprise near starbase */ 251 | if (i == 0) { 252 | Ship.quadx = ix; 253 | Ship.quady = iy; 254 | } 255 | } 256 | 257 | /* position klingons */ 258 | for (i = Param.klings; i > 0; ) { 259 | klump = ranf(4) + 1; 260 | if (klump > i) 261 | klump = i; 262 | while (1) { 263 | ix = ranf(NQUADS); 264 | iy = ranf(NQUADS); 265 | q = &Quad[ix][iy]; 266 | if (q->klings + klump > MAXKLQUAD) 267 | continue; 268 | q->klings += klump; 269 | i -= klump; 270 | break; 271 | } 272 | } 273 | 274 | /* initialize this quadrant */ 275 | printf("%d Klingons\n%d starbase", Param.klings, Param.bases); 276 | if (Param.bases > 1) 277 | printf("s"); 278 | printf(" at %d,%d", Now.base[0].x, Now.base[0].y); 279 | for (i = 1; i < Param.bases; i++) 280 | printf(", %d,%d", Now.base[i].x, Now.base[i].y); 281 | printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr); 282 | Move.free = 0; 283 | initquad(0); 284 | srscan(1); 285 | attack(0); 286 | } 287 | --------------------------------------------------------------------------------