Path: utzoo!attcan!uunet!husc6!bloom-beacon!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games
From: games@tekred.TEK.COM
Newsgroups: comp.sources.games
Subject: v04i025: spacewar - multiplayer asynchronous space battle game, Part05/06
Message-ID: <2587@tekred.TEK.COM>
Date: 31 May 88 17:19:03 GMT
Sender: billr@tekred.TEK.COM
Lines: 2296
Approved: billr@saab.CNA.TEK.COM
Submitted by: udenva!koala!dir (Dan Rosenblatt)
Comp.sources.games: Volume 4, Issue 25
Archive-name: spacewar/Part05
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh bits.c <<'END_OF_bits.c'
X/*
X * Spacewar - turn bits on, off, and return value
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X
X#define BPB 8 /* bits per byte */
X
XVOID biton(ary,bitno)
Xchar ary[];
Xint bitno;
X{
X ary[bitno/BPB] |= 1<<(bitno%BPB);
X}
X
XVOID bitoff(ary,bitno)
Xchar ary[];
Xint bitno;
X{
X ary[bitno/BPB] &= ~(1<<(bitno%BPB));
X}
X
Xnabit(ary,bitno)
Xchar ary[];
Xint bitno;
X{
X return((ary[bitno/BPB]>>(bitno%BPB))&1);
X}
END_OF_bits.c
if test 448 -ne `wc -c crft.h <<'END_OF_crft.h'
X/*
X * Spacewar - include file that defines a player's craft structure
X * (requires prior inclusion of sys.h, login.h, and universe.h)
X *
X * Copyright 1984 obo Systems, Inc.
X * Copyright 1984 Dan Rosenblatt
X */
X
X#define CRAFT 'C' /* prefix for dbm(3) key */
X
Xstruct crftkey {
X char cr_crftkey; /* prefix for dbm(3) key */
X char cr_plyr[8+1]; /* player(owner) name */
X char cr_name[12+1]; /* craft name */
X};
X
X#define MHOM 6
X
Xstruct crft {
X char cr_htyp; /* craft hull type */
X long cr_flsp; /* craft free floor space */
X long cr_crew; /* craft free crew */
X long cr_pnts; /* craft points */
X time_t cr_time; /* craft playing time */
X short cr_kill; /* craft credited kills */
X idxptr cr_dock; /* craft docked at (object) */
X double cr_pstn[3]; /* craft position */
X double cr_dir[3]; /* craft direction */
X double cr_vel[3]; /* craft velocity */
X double cr_thr[3]; /* craft thrust */
X idxptr cr_hom[MHOM]; /* craft homing channels */
X idxptr cr_auto; /* craft autopilot */
X char cr_ffwd; /* craft facing forward */
X double cr_vang; /* craft viewing angle */
X long cr_vdst; /* craft visual distance */
X char cr_plvl; /* craft privilege level */
X
X/* in-core only */
X struct login *cr_lgn; /* craft login */
X idxptr cr_univ; /* craft universe pointer */
X long cr_hdst[MHOM]; /* craft homing channel distances */
X char cr_sens[2]; /* craft sensors */
X idxptr cr_lhit; /* craft last hit by */
X double cr_lhpstn[3]; /* craft last hit from position */
X char cr_lrpt; /* craft last report line */
X char cr_lcmd; /* craft last command line */
X char cr_chng[10]; /* craft field changed flags */
X char cr_scrn[15][31];/* craft viewscreen */
X double cr_rmat[3][3]; /* craft rotation matrix */
X struct sys cr_sys[MSYS];/* craft systems */
X};
X
X#define MAXCRFT MAXLOGIN
X
Xextern struct crft crftlst[];
X
X#define CRDATSIZ (((char *)(&crftlst[0].cr_lgn))-((char *)(&crftlst[0].cr_htyp)))
END_OF_crft.h
if test 1875 -ne `wc -c crftupdate.c <<'END_OF_crftupdate.c'
X/*
X * Spacewar - update crafts to database
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#ifndef VMS
X#include
X#include
X#else /* BSD SYSIII SYSV */
X#include
X#include "dbm.h"
X#endif /* VMS */
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X#include "sys.h"
X#include "crft.h"
X
XVOID crftupdate(plogin)
Xregister struct login *plogin;
X{
X struct login *plow,*phigh;
X struct crftkey getcrkey;
X struct crft getcrdat;
X struct syskey getskey;
X datum dbmkey,dbmdata;
X register struct sys *psys;
X register int i;
X
X
X /* do a specific one or all */
X if (plogin) {
X#ifdef DEBUG
X DBG("crftupdate(#%d/%s)\n",plogin-loginlst,plogin->ln_name);
X#endif
X plow = phigh = plogin;
X } else {
X#ifdef DEBUG
X DBG("crftupdate(#ALL)\n");
X#endif
X plow = loginlst;
X phigh = loginlst + MAXLOGIN - 1;
X }
X
X /* update associated crafts and subsystems to the database */
X for (plogin=plow;plogin <= phigh;++plogin) {
X
X /* skip if not a player or not playing */
X if (!plogin->ln_tty || !plogin->ln_play.ip_ptr)
X continue;
X
X /* update craft */
X binit((char *)&getcrkey,sizeof(getcrkey));
X getcrkey.cr_crftkey = CRAFT;
X strcpy(getcrkey.cr_plyr,plogin->ln_name);
X strcpy(getcrkey.cr_name,plogin->ln_crft);
X dbmkey.dptr = (char *)&getcrkey;
X dbmkey.dsize = sizeof(getcrkey);
X
X /* normalize idxptr's */
X getcrdat = *plogin->ln_play.ip_ptr->uv_ptr.uv_crft;
X if (getcrdat.cr_dock.ip_ptr)
X getcrdat.cr_dock.ip_ofst = getcrdat.cr_dock.ip_ptr - univlst;
X else
X getcrdat.cr_dock.ip_ofst = 0;
X if (getcrdat.cr_auto.ip_ptr)
X getcrdat.cr_auto.ip_ofst = getcrdat.cr_auto.ip_ptr - univlst;
X else
X getcrdat.cr_auto.ip_ofst = 0;
X for (i=0;i < MHOM;++i)
X if (getcrdat.cr_hom[i].ip_ptr)
X getcrdat.cr_hom[i].ip_ofst = getcrdat.cr_hom[i].ip_ptr -
X univlst;
X else
X getcrdat.cr_hom[i].ip_ofst = 0;
X
X dbmdata.dptr = (char *)&getcrdat;
X dbmdata.dsize = CRDATSIZ;
X if (store(dbmkey,dbmdata))
X perror("crftupdate: can't update crft");
X
X /* update craft subsystems */
X binit((char *)&getskey,sizeof(getskey));
X getskey.s_syskey = SUBSYS;
X strcpy(getskey.s_plyr,plogin->ln_name);
X strcpy(getskey.s_crft,plogin->ln_crft);
X dbmkey.dptr = (char *)&getskey;
X dbmkey.dsize = sizeof(getskey);
X dbmdata.dsize = sizeof(struct sys);
X for (psys=getcrdat.cr_sys,i=0;i < MSYS;++psys,++i) {
X if (!psys->s_cap) continue; /* not in this craft */
X getskey.s_type = i;
X dbmdata.dptr = (char *)psys;
X if (store(dbmkey,dbmdata))
X perror("crftupdate: can't update sys");
X }
X }
X
X#ifdef DEBUG
X VDBG("crftupdate return\n");
X#endif
X}
END_OF_crftupdate.c
if test 2687 -ne `wc -c dbm.c <<'END_OF_dbm.c'
X/*
X * NOTE: VMS only
X */
X
X#include "dbm.h"
X#include
X#include
X
Xstatic struct FAB dbmfab;
Xstatic struct RAB dbmrab;
Xstatic struct XABKEY dbmxab;
Xstatic char *dbmfile;
Xstatic char reckey[24],recdat[512];
X
Xdbminit(file)
Xchar *file;
X{
X int e;
X
X dbmfile = file;
X
X dbmfab=cc$rms_fab;
X dbmrab=cc$rms_rab;
X dbmxab=cc$rms_xabkey;
X
X /* open the file */
X dbmfab.fab$b_fac = FAB$M_PUT + FAB$M_GET + FAB$M_DEL + FAB$M_UPD;
X dbmfab.fab$b_shr = FAB$M_SHRPUT + FAB$M_SHRGET + FAB$M_SHRDEL +
X FAB$M_SHRUPD;
X dbmfab.fab$l_fna = file;
X dbmfab.fab$b_fns = strlen(file);
X dbmfab.fab$l_xab = &dbmxab;
X if ((e=sys$open(&dbmfab)) != RMS$_KFF && e != RMS$_NORMAL) {
X fprintf(stderr,"dbminit 1 rms=%x ",e);
X return(-1);
X }
X
X /* set up for record I/O */
X dbmrab.rab$l_fab = &dbmfab;
X dbmrab.rab$b_krf = 0;
X if ((e=sys$connect(&dbmrab)) != RMS$_NORMAL) {
X fprintf(stderr,"dbminit 2 rms=%x ",e);
X return(-1);
X }
X
X return(0);
X}
X
Xdbmclose()
X{
X int e;
X
X if ((e=sys$close(&dbmfab)) != RMS$_NORMAL) {
X fprintf(stderr,"dbmclose rms=%x ",e);
X return(-1);
X }
X return(0);
X}
X
Xdatum fetch(key)
Xdatum key;
X{
X datum rec;
X int e;
X
X rec.dptr = (char *)0;
X
X dbmrab.rab$b_rac = RAB$C_KEY;
X dbmrab.rab$w_usz = sizeof(recdat);
X dbmrab.rab$l_ubf = recdat;
X dbmrab.rab$l_kbf = key.dptr;
X dbmrab.rab$b_ksz = key.dsize;
X dbmrab.rab$l_rop = RAB$M_NLK;
X if ((e=sys$get(&dbmrab)) != RMS$_NORMAL && e != RMS$_RNF) {
X fprintf(stderr,"fetch rms=%x ",e);
X }
X if (e == RMS$_NORMAL) {
X rec.dptr = dbmrab.rab$l_rbf + sizeof(reckey);
X rec.dsize = dbmrab.rab$w_rsz - sizeof(reckey);
X }
X return(rec);
X}
X
Xdbmdelete(key)
Xdatum key;
X{
X int e;
X
X dbmrab.rab$b_rac = RAB$C_KEY;
X dbmrab.rab$l_kbf = key.dptr;
X dbmrab.rab$b_ksz = key.dsize;
X dbmrab.rab$l_rop = RAB$M_FDL;
X if ((e=sys$find(&dbmrab)) != RMS$_NORMAL && e != RMS$_RNF) {
X fprintf(stderr,"dbmdelete 1 rms=%x ",e);
X }
X if (e == RMS$_NORMAL) {
X if ((e=sys$delete(&dbmrab)) != RMS$_NORMAL) {
X fprintf(stderr,"dbmdelete 2 rms=%x ",e);
X return(-1);
X }
X return(0);
X } else
X return(-1);
X}
X
Xstore(key, dat)
Xdatum key, dat;
X{
X int e;
X
X dbmrab.rab$b_rac = RAB$C_KEY;
X binit(recdat,sizeof(reckey));
X bcopy(recdat,key.dptr,key.dsize);
X bcopy(recdat+sizeof(reckey),dat.dptr,dat.dsize);
X dbmrab.rab$l_kbf = recdat;
X dbmrab.rab$b_ksz = sizeof(reckey);
X dbmrab.rab$l_rbf = recdat;
X dbmrab.rab$w_rsz = sizeof(reckey) + dat.dsize;
X dbmrab.rab$l_rop = RAB$M_LOA + RAB$M_UIF;
X if ((e=sys$put(&dbmrab)) != RMS$_NORMAL) {
X fprintf(stderr,"store rms=%x ",e);
X return(-1);
X }
X return(0);
X}
X
Xdatum firstkey()
X{
X datum key;
X int e;
X
X key.dptr = (char *)0;
X
X dbmrab.rab$b_rac = RAB$C_SEQ;
X if ((e=sys$rewind(&dbmrab)) != RMS$_NORMAL) {
X fprintf(stderr,"firstkey 1 rms=%x ",e);
X }
X if (e == RMS$_NORMAL) {
X dbmrab.rab$l_rop = RAB$M_NLK;
X dbmrab.rab$w_usz = sizeof(recdat);
X dbmrab.rab$l_ubf = recdat;
X if ((e=sys$get(&dbmrab)) != RMS$_NORMAL && e != RMS$_EOF) {
X fprintf(stderr,"firstkey 2 rms=%x ",e);
X }
X if (e == RMS$_NORMAL) {
X key.dptr = dbmrab.rab$l_rbf;
X key.dsize = sizeof(reckey);
X }
X }
X return(key);
X}
X
Xdatum nextkey(xkey)
Xdatum xkey;
X{
X datum key;
X int e;
X
X key.dptr = (char *)0;
X
X dbmrab.rab$b_rac = RAB$C_SEQ;
X dbmrab.rab$l_rop = RAB$M_NLK;
X dbmrab.rab$w_usz = sizeof(recdat);
X dbmrab.rab$l_ubf = recdat;
X if ((e=sys$get(&dbmrab)) != RMS$_NORMAL && e != RMS$_EOF) {
X fprintf(stderr,"nextkey rms=%x ",e);
X }
X if (e == RMS$_NORMAL) {
X key.dptr = dbmrab.rab$l_rbf;
X key.dsize = sizeof(reckey);
X }
X return(key);
X}
END_OF_dbm.c
if test 3438 -ne `wc -c dmpdbm.c <<'END_OF_dmpdbm.c'
X/*
X * Spacewar - dump all dbm(3) records
X *
X * Copyright 1984 obo Systems, Inc.
X * Copyright 1984 Dan Rosenblatt
X */
X
X#ifndef VMS
X#include
X#include
X#else /* BSD SYSIII SYSV */
X#include
X#include "dbm.h"
X#endif /* VMS */
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X#include "sys.h"
X#include "crft.h"
X#include "mlbx.h"
X#include "plyr.h"
X#include "ucmd.h"
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X datum dbmkey,dbmdata;
X struct crftkey crk;
X struct crft crd;
X struct mlbxkey mbk;
X struct plyrkey plk;
X struct plyr pld;
X struct ucmdkey uck;
X struct syskey sk;
X struct sys s;
X int dodtl = (argc > 1);
X char *asctime(),*ctime();
X
X if (dbminit(SWDATABASE)) {
X perror(SWDATABASE);
X exit(1);
X }
X
X for (dbmkey=firstkey();dbmkey.dptr;dbmkey=nextkey(dbmkey))
X switch(dbmkey.dptr[0]) {
X
X case CRAFT:
X bcopy((char *)&crk,dbmkey.dptr,sizeof(crk));
X printf("craft '%s' '%s': ",crk.cr_plyr,crk.cr_name);
X dbmdata = fetch(dbmkey);
X if (!dbmdata.dptr)
X printf("can't fetch\n");
X else {
X bcopy((char *)&crd,dbmdata.dptr,sizeof(crd));
X printf("%d %ld %ld %ld %ld %d %d\n",
X crd.cr_htyp,crd.cr_flsp,crd.cr_crew,crd.cr_pnts,
X crd.cr_time,crd.cr_kill,crd.cr_dock.ip_ofst);
X if (dodtl) {
X printf(
X " (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g)\n",
X crd.cr_pstn[0],crd.cr_pstn[1],crd.cr_pstn[2],
X crd.cr_dir[0],crd.cr_dir[1],crd.cr_dir[2],
X crd.cr_vel[0],crd.cr_vel[1],crd.cr_vel[2],
X crd.cr_thr[0],crd.cr_thr[1],crd.cr_thr[2]);
X printf(" %d %d %d %d %d %d %d %d %g %ld %d\n",
X crd.cr_hom[0].ip_ofst,crd.cr_hom[1].ip_ofst,
X crd.cr_hom[2].ip_ofst,crd.cr_hom[3].ip_ofst,
X crd.cr_hom[4].ip_ofst,crd.cr_hom[5].ip_ofst,
X crd.cr_auto.ip_ofst,crd.cr_ffwd,crd.cr_vang,
X crd.cr_vdst,crd.cr_plvl);
X }
X }
X break;
X
X case MLBX:
X bcopy((char *)&mbk,dbmkey.dptr,sizeof(mbk));
X printf("mlbx '%s' %d: ",mbk.mb_plyr,mbk.mb_mlbx);
X dbmdata = fetch(dbmkey);
X if (!dbmdata.dptr)
X printf("can't fetch\n");
X else
X printf("'%s'\n",dbmdata.dptr);
X break;
X
X case PLYR:
X bcopy((char *)&plk,dbmkey.dptr,sizeof(plk));
X printf("plyr '%s': ",plk.pl_name);
X dbmdata = fetch(dbmkey);
X if (!dbmdata.dptr)
X printf("can't fetch\n");
X else {
X bcopy((char *)&pld,dbmdata.dptr,sizeof(pld));
X printf("'%s' %d {%.24s} %d %d %d %d %ld %ld %ld\n",
X pld.pl_passwd,pld.pl_numlgn,
X#ifdef VMS
X ctime(&pld.pl_lstlgn),
X#else /* BSD SYSIII SYSV */
X asctime(localtime(&pld.pl_lstlgn)),
X#endif /* VMS BSD SYSIII SYSV */
X pld.pl_frstml,pld.pl_seenml,pld.pl_lstml,
X pld.pl_slst,pld.pl_klst,pld.pl_plst,pld.pl_tlst);
X }
X break;
X
X case UCMD:
X bcopy((char *)&uck,dbmkey.dptr,sizeof(uck));
X printf("ucmd '%s' '%s' %d: ",uck.uc_plyr,
X uck.uc_name,uck.uc_ucmd);
X dbmdata = fetch(dbmkey);
X if (!dbmdata.dptr)
X printf("can't fetch\n");
X else
X printf("'%s'\n",dbmdata.dptr);
X break;
X
X case SUBSYS:
X bcopy((char *)&sk,dbmkey.dptr,sizeof(sk));
X printf("sys '%s' '%s' %d: ",sk.s_plyr,sk.s_crft,
X sk.s_type);
X dbmdata = fetch(dbmkey);
X if (!dbmdata.dptr)
X printf("can't fetch\n");
X else {
X bcopy((char *)&s,dbmdata.dptr,sizeof(s));
X printf("%d %d %d %d %d\n",s.s_pct,s.s_edmg,s.s_dmg,
X s.s_lvl,s.s_cap);
X }
X break;
X
X default:
X printf("%c: unknown\n",dbmkey.dptr[0]);
X break;
X }
X}
END_OF_dmpdbm.c
if test 3468 -ne `wc -c flds.h <<'END_OF_flds.h'
X/*
X * Spacewar - definitions for fields
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#ifndef FLDS
Xextern
X#endif
Xstruct flddesc {
X char f_row; /* field row (uppermost is 0) */
X char f_col; /* field column (leftmost is 0) */
X char f_len; /* field length */
X char *f_fmt; /* printf format */
X char f_grpw; /* repeating group width (# of fields) */
X char f_maxg; /* maximum group repetitions */
X} flds[]
X#ifdef FLDS
X = {
X /* upper left of viewscreen */
X {0, 24, 0, "%s"},
X
X /* direction */
X {1, 19, 4, "%-4.4s"},
X {1, 6, 5, "%5.1f"},
X {1, 12, 5, "%5.1f"},
X
X /* position */
X {3, 0, 7, "%7.0f"},
X {3, 8, 7, "%7.0f"},
X {3, 16, 7, "%7.0f"},
X
X /* velocity */
X {5, 0, 7, "%7.1f"},
X {5, 8, 7, "%7.1f"},
X {5, 16, 7, "%7.1f"},
X
X /* viewscreen attributes */
X {8, 0, 5, "%5.1f"}, /* angle */
X {8, 6, 9, "%9ld"}, /* distance */
X
X /* sensors */
X {8, 16, 3, "%3d"}, /* see */
X {8, 20, 3, "%3d"}, /* bad */
X
X /* homing */
X {11, 4, 7, "%7ld"},
X {12, 4, 7, "%7ld"},
X {13, 4, 7, "%7ld"},
X {11, 16, 7, "%7ld"},
X {12, 16, 7, "%7ld"},
X {13, 16, 7, "%7ld"},
X
X /* radio */
X {15, 7, 40, "%-40.40s"},
X
X /* time */
X {15, 48, 7, "%7ld"},
X
X /* subsystems */
X {1, 56, 11, "%2d:%-8.8s", 3, MSYS}, /* name */
X {1, 68, 6, "%6d", 3, MSYS}, /* level */
X {1, 76, 3, "%3d", 3, MSYS}, /* %damage */
X
X /* report */
X {17, 41, 38, "%-38.38s", 1, 6},
X
X /* commands */
X {16, 0, 1, "%1.1s", 2, 7}, /* last indicator */
X {16, 1, 40, "%-40.40s", 2, 7}, /* command */
X
X /* background */
X {0, 0, 0, "%s"}
X}
X#endif
X;
X
X#define FLD_VIEWSCREEN 0
X#define FLD_AUTOFFWD 1
X#define FLD_DIR1 2
X#define FLD_DIR2 3
X#define FLD_PN1 4
X#define FLD_PN2 5
X#define FLD_PN3 6
X#define FLD_VEL1 7
X#define FLD_VEL2 8
X#define FLD_VEL3 9
X#define FLD_VANGL 10
X#define FLD_VDIST 11
X#define FLD_SSEE 12
X#define FLD_SBAD 13
X#define FLD_HOMCHAN 14
X#define FLD_RADIO 20
X#define FLD_TIME 21
X#define FLD_SNAME 22
X#define FLD_SLEVEL 23
X#define FLD_SDMG 24
X#define FLD_REPORT 25
X#define FLD_LSTCMD 26
X#define FLD_COMMAND 27
X#define FLD_BACKGROUND 28
X
X#define BIT_AUTOFFWD FLD_AUTOFFWD
X#define BIT_DIR1 FLD_DIR1
X#define BIT_DIR2 FLD_DIR2
X#define BIT_PN1 FLD_PN1
X#define BIT_PN2 FLD_PN2
X#define BIT_PN3 FLD_PN3
X#define BIT_VEL1 FLD_VEL1
X#define BIT_VEL2 FLD_VEL2
X#define BIT_VEL3 FLD_VEL3
X#define BIT_VANGL FLD_VANGL
X#define BIT_VDIST FLD_VDIST
X#define BIT_SSEE FLD_SSEE
X#define BIT_SBAD FLD_SBAD
X#define BIT_HOMCHAN FLD_HOMCHAN
X#define BIT_RADIO FLD_RADIO
X#define BIT_TIME FLD_TIME
X#define BIT_SNAME FLD_SNAME
X#define BIT_SLEVEL FLD_SLEVEL
X#define BIT_SDMG FLD_SDMG
X#define BIT_REPORT FLD_SNAME+(3*MSYS)
END_OF_flds.h
if test 2611 -ne `wc -c logoff.c <<'END_OF_logoff.c'
X/*
X * Spacewar - logoff a player:
X * reset tty modes
X * close the tty I/O channel
X * terminate (signal) the play and read processes
X * clear out the login structure
X *
X * Copyright 1984 obo Systems, Inc.
X * Copyright 1984 Dan Rosenblatt
X */
X
X#include
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X
X#ifdef BSD
X# include
X#else /* VMS SYSIII SYSV */
X#ifdef VMS
X# include
X#else /* SYSIII SYSV */
X# include
X# include
X# include
X#endif /* VMS SYSIII SYSV */
X#endif /* BSD VMS SYSIII SYSV */
X
XVOID logoff(plogin)
Xregister struct login *plogin;
X{
X#ifdef VMS
X int i;
X#endif /* VMS */
X extern int errno;
X
X#ifdef DEBUG
X DBG("logoff(#%d/%s)\n",plogin-loginlst,plogin->ln_name);
X#endif
X
X /* remove from universe if playing */
X if (plogin->ln_play.ip_ptr) unplay(plogin);
X
X /*****************/
X /* set tty modes */
X /*****************/
X#ifdef BSD
X {
X struct sgttyb tmode;
X
X if (gtty(plogin->ln_tty,&tmode)) {
X perror("gtty");
X goto sigh; /* horrendous */
X }
X
X /* reset echo and no cbreak mode */
X /* (too bad the previous states weren't saved) */
X tmode.sg_flags &= ~CBREAK;
X tmode.sg_flags |= ECHO;
X
X if (stty(plogin->ln_tty,&tmode)) {
X perror("stty");
X goto sigh; /* horrendous */
X }
X }
X#else /* VMS SYSIII SYSV */
X#ifndef VMS
X {
X struct termio tmode;
X
X if (ioctl(plogin->ln_tty,TCGETA,&tmode)) {
X perror("ioctl TCGETA");
X goto sigh; /* horrendous */
X }
X
X /* reset echo and erase/kill edit processing */
X /* (too bad the previous states weren't saved) */
X tmode.c_lflag |= ICANON+ECHO+ECHOE+ECHOK+ECHONL;
X tmode.c_cc[VEOF] = CEOF;
X tmode.c_cc[VEOL] = CNUL;
X
X if (ioctl(plogin->ln_tty,TCSETA,&tmode)) {
X perror("ioctl TCSETA");
X goto sigh; /* horrendous */
X }
X }
X#endif /* VMS SYSIII SYSV */
X#endif /* BSD VMS SYSIII SYSV */
X
X /* close the player's terminal and kill the read and play processes */
Xsigh:
X#ifdef VMS
X output(plogin,0,0,0);
X output(plogin,'C',0,"ShUtDoWn");
X output(plogin,0,0,0);
X if ((i=sys$delmbx(plogin->ln_tty)) != SS$_NORMAL) {
X perror("delete mlbx 1");
X#ifdef DEBUG
X VDBG("logoff delmbx()=%d, errno=%d\n",i,errno);
X#endif
X }
X if ((i=sys$dassgn(plogin->ln_tty)) != SS$_NORMAL) {
X perror("dassgn mlbx 1");
X#ifdef DEBUG
X VDBG("logoff dassgn()=%d, errno=%d\n",i,errno);
X#endif
X }
X#else /* BSD SYSIII SYSV */
X if (close(plogin->ln_tty))
X perror("close");
X if (kill(plogin->ln_readpid,SIGTERM))
X perror("kill readsw");
X else
X wait(0);
X if (kill(plogin->ln_playpid,SIGTERM))
X perror("kill playsw");
X#endif /* VMS BSD SYSIII SYSV */
X
X /* reset the login entry */
X binit((char *)plogin,sizeof(*plogin));
X#ifdef DEBUG
X VDBG("logoff return\n");
X#endif
X}
END_OF_logoff.c
if test 2660 -ne `wc -c logon.c <<'END_OF_logon.c'
X/*
X * Spacewar - logon a player
X * clear out most of the login structure
X * set tty modes
X * prompt player for his/her name
X *
X * Copyright 1984 obo Systems, Inc.
X * Copyright 1984 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X
X#ifdef BSD
X# include
X#else /* VMS SYSIII SYSV */
X#ifndef VMS
X# include
X# include
X# include
X#endif /* VMS SYSIII SYSV */
X#endif /* BSD VMS SYSIII SYSV */
X
XVOID logon(plogin)
Xregister struct login *plogin;
X{
X
X#ifdef DEBUG
X DBG("logon(#%d/%s)\n",plogin-loginlst,plogin->ln_name);
X#endif
X
X /* clear out most of login structure */
X plogin->ln_name[0] = NULL;
X if (plogin->ln_term)
X free(plogin->ln_term);
X plogin->ln_term = NULL;
X if (plogin->ln_tcm)
X free(plogin->ln_tcm);
X plogin->ln_tcm = NULL;
X if (plogin->ln_tcl)
X free(plogin->ln_tcl);
X plogin->ln_tcl = NULL;
X if (plogin->ln_tce)
X free(plogin->ln_tce);
X plogin->ln_tce = NULL;
X if (plogin->ln_tso)
X free(plogin->ln_tso);
X plogin->ln_tso = NULL;
X if (plogin->ln_tse)
X free(plogin->ln_tse);
X plogin->ln_tse = NULL;
X plogin->ln_rvslh = 0;
X plogin->ln_iomode = NULL;
X plogin->ln_crft[0] = NULL;
X plogin->ln_play.ip_ptr = NULL;
X plogin->ln_stat = NULL;
X plogin->ln_substat = NULL;
X plogin->ln_input[0] = NULL;
X
X /*****************/
X /* set tty modes */
X /*****************/
X#ifdef BSD
X {
X struct sgttyb tmode;
X
X if (gtty(plogin->ln_tty,&tmode)) {
X perror("gtty");
X logoff(plogin);
X#ifdef DEBUG
X VDBG("logon return\n");
X#endif
X return;
X }
X
X /* insure no echo and cbreak mode */
X /* (too bad the previous states aren't saved) */
X tmode.sg_flags |= CBREAK;
X tmode.sg_flags &= ~(RAW+ECHO);
X
X if (stty(plogin->ln_tty,&tmode)) {
X perror("stty");
X logoff(plogin);
X#ifdef DEBUG
X VDBG("logon return\n");
X#endif
X return;
X }
X }
X#else /* VMS SYSIII SYSV */
X#ifndef VMS
X {
X struct termio tmode;
X
X if (ioctl(plogin->ln_tty,TCGETA,&tmode)) {
X perror("ioctl TCGETA");
X logoff(plogin);
X#ifdef DEBUG
X VDBG("logon return\n");
X#endif
X return;
X }
X
X /* insure no echo and no erase/kill edit processing */
X /* (too bad the previous states aren't saved) */
X tmode.c_lflag &= ~(ICANON+ECHO+ECHOE+ECHOK+ECHONL);
X tmode.c_cc[VMIN] = 1;
X tmode.c_cc[VTIME] = 0;
X
X if (ioctl(plogin->ln_tty,TCSETA,&tmode)) {
X perror("ioctl TCSETA");
X logoff(plogin);
X#ifdef DEBUG
X VDBG("logon return\n");
X#endif
X return;
X }
X }
X#endif /* VMS */
X#endif /* VMS BSD SYSIII SYSV */
X
X
X /* prompt player for name */
X output(plogin,'C',0,"\nWhat is your name?");
X output(plogin,0,0,0);
X#ifdef DEBUG
X VDBG("logon return\n");
X#endif
X}
END_OF_logon.c
if test 2581 -ne `wc -c objinit.c <<'END_OF_objinit.c'
X/*
X * Spacewar - read in objects and set them up for the universe
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include
X#include "spacewar.h"
X#include "universe.h"
X#include "obj.h"
X
XVOID objinit()
X{
X FILE *fobj;
X struct obj *p=objlst;
X struct universe *puniv;
X
X#ifdef DEBUG
X DBG("objinit()\n");
X#endif
X
X if (!(fobj = fopen(SWOBJ,"r"))) {
X perror(SWOBJ);
X exit(1);
X }
X
X /* try to read the exact number of objects that there should be */
X for (p=objlst;p < objlst+MAXOBJ;++p)
X if (fscanf(fobj,"%ld\t%hd\t%c\t%d\t%hd\t%ld\t%lf\t%lf\t%lf\t%lf\n",
X &p->oj_mass,&p->oj_rad,&p->oj_rep,&p->oj_octr.ip_ofst,&p->oj_oprd,
X &p->oj_orad,&p->oj_ocrpt,&p->oj_optx,&p->oj_opty,&p->oj_optz) != 10) {
X perror("bad object");
X exit(1);
X }
X
X if (!feof(fobj) || ferror(fobj) || fclose(fobj)) {
X perror(SWOBJ);
X exit(1);
X }
X
X /* fix up orbital center and rotation matrix */
X for (p=objlst+MAXOBJ;p-- > objlst;) {
X
X /* validate */
X if (p->oj_octr.ip_ofst < 0 ||
X p->oj_octr.ip_ofst >= p-objlst) {
X if (p != objlst) { /* first object is center of universe */
X perror("bad oj_octr");
X exit(1);
X }
X }
X switch(p->oj_rep) {
X case '.':
X p->oj_rep = ' ';
X case '*': case 'O': case 'o': case '#':
X break;
X default:
X perror("bad oj_rep");
X exit(1);
X }
X
X /* rotation matrix */
X unity(p->oj_rmat);
X xrot(p->oj_rmat,NEG(MUL(p->oj_optx,DEGTORAD)));
X yrot(p->oj_rmat,NEG(MUL(p->oj_opty,DEGTORAD)));
X zrot(p->oj_rmat,NEG(MUL(p->oj_optz,DEGTORAD)));
X
X /* place into universe */
X p->oj_octr.ip_ptr = univlst + p->oj_octr.ip_ofst;
X puniv = univlst + (p - objlst);
X puniv->uv_type = 'O';
X puniv->uv_pctr = p->oj_rep;
X puniv->uv_pstn = p->oj_pstn;
X puniv->uv_mass = p->oj_mass;
X puniv->uv_rad = p->oj_rad;
X puniv->uv_ptr.uv_obj = p;
X p->oj_univ.ip_ptr = puniv;
X }
X
X /* update objects so that universe position is current */
X /* (necessary because of first-time players that crank */
X /* up a new instance of the game and how they are put */
X /* into the universe the very first time) */
X updobjs();
X
X#ifdef DEBUG
X VDBG("objinit return\n");
X#endif
X}
END_OF_objinit.c
if test 2205 -ne `wc -c objupdate.c <<'END_OF_objupdate.c'
X/*
X * Spacewar - update universe orbiting objects to external file
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include
X#include "spacewar.h"
X#include "universe.h"
X#include "obj.h"
X
XVOID objupdate()
X{
X char buf[128];
X FILE *fobj;
X register struct obj *p=objlst;
X
X#ifdef DEBUG
X DBG("objupdate()\n");
X#endif
X
X /* write to secondary file to be renamed */
X strcpy(buf,SWOBJ);
X#ifndef VMS
X strcat(buf,"x");
X#endif
X if (!(fobj = fopen(buf,"w"))) {
X perror(buf);
X#ifdef DEBUG
X VDBG("objupdate return\n");
X#endif
X return;
X }
X
X /* write the exact number of objects */
X for (p=objlst;p < objlst+MAXOBJ;++p)
X fprintf(fobj,"%ld\t%d\t%c\t%d\t%d\t%ld\t%.5f\t%.1f\t%.1f\t%.1f\n",
X p->oj_mass,p->oj_rad,(p->oj_rep == ' ') ? '.' : p->oj_rep,
X p->oj_octr.ip_ptr-univlst,p->oj_oprd,p->oj_orad,p->oj_ocrpt,
X p->oj_optx,p->oj_opty,p->oj_optz);
X
X if (ferror(fobj) || fclose(fobj)) {
X perror(buf);
X#ifdef DEBUG
X VDBG("objupdate return\n");
X#endif
X return;
X }
X
X#ifndef VMS
X /* rename secondary file to be primary */
X if (unlink(SWOBJ) || link(buf,SWOBJ) || unlink(buf)) {
X perror(buf);
X }
X#endif
X
X#ifdef DEBUG
X VDBG("objupdate return\n");
X#endif
X}
END_OF_objupdate.c
if test 1211 -ne `wc -c output.c <<'END_OF_output.c'
X/*
X * Spacewar - do output to a terminal
X * output is built with control/leadin characters
X * as needed for terminal type and is buffered
X * modes are: Delete Erase Converse High Low Beep and (null)
X *
X * Copyright 1984 obo Systems, Inc.
X * Copyright 1984 Dan Rosenblatt
X */
X
X#include
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X#include "sys.h"
X#define FLDS
X#include "flds.h"
X#ifdef VMS
X# include
X# include
X#endif /* VMS */
X
Xstatic char outbuf[80*24*2]="";
Xstatic VOID doout(),dowrite();
Xextern int errno;
X
X/*VARARGS1*/
XVOID output(plogin,mode,fld,str,val2,val3,val4)
Xregister struct login *plogin;
Xchar mode;
Xint fld;
Xchar *str;
Xint val2,val3,val4;
X{
X char *s,buf[256],fmt[16],*so="",*se="",*tgoto();
X int grp;
X#ifdef VMS
X int i;
X#endif /* VMS */
X
X switch(mode) {
X case 'B':
X doout(plogin->ln_tty,"\007");
X break;
X case 'C':
X doout(plogin->ln_tty,str);
X break;
X case 'D':
X s = tgoto(plogin->ln_tcm,0,23);
X doout(plogin->ln_tty,s);
X doout(plogin->ln_tty,plogin->ln_tce);
X break;
X case 'E':
X if (s=plogin->ln_tcl)
X doout(plogin->ln_tty,s);
X break;
X case 'H':
X case 'L':
X if ((plogin->ln_rvslh && mode == 'L') ||
X (!plogin->ln_rvslh && mode == 'H')) {
X so = plogin->ln_tso;
X se = plogin->ln_tse;
X }
X grp = (fld>>8)&0xff;
X fld &= 0xff;
X sprintf(fmt,"%%s%%s%s",flds[fld].f_fmt); /* no overflow check */
X sprintf(buf,fmt,
X tgoto(plogin->ln_tcm,flds[fld].f_col,flds[fld].f_row+grp),
X so,str,val2,val3,val4);
X strcat(buf,se);
X doout(plogin->ln_tty,buf);
X break;
X case 0:
X if (plogin->ln_play.ip_ptr) {
X s = tgoto(plogin->ln_tcm,strlen(plogin->ln_input),23);
X doout(plogin->ln_tty,s);
X }
X if (outbuf[0]) {
X#ifdef VMS
X if ((i=sys$qiow(0,plogin->ln_tty,IO$_WRITEVBLK+IO$M_NOW,
X 0,0,0,outbuf,strlen(outbuf)+1,0,0,0,0)) != SS$_NORMAL) {
X perror("output qiow 1");
X#ifdef DEBUG
X VDBG("output qiow(WRITEVBLK)=%d, errno=%d\n",i,errno);
X#endif
X }
X#else /* BSD SYSIII SYSV */
X dowrite(plogin->ln_tty,outbuf,strlen(outbuf));
X#endif /* VMS BSD SYSIII SYSV */
X outbuf[0] = NULL;
X }
X break;
X default:
X write(2,"output: unknown mode\n",21);
X break;
X }
X}
X
Xstatic VOID doout(fd,s)
Xshort fd;
Xchar *s;
X{
X#ifdef VMS
X int i;
X#endif /* VMS */
X
X#if 1 /* with buffering */
X if (strlen(outbuf)+strlen(s)+1 >= sizeof(outbuf)) {
X#ifdef VMS
X if ((i=sys$qiow(0,fd,IO$_WRITEVBLK+IO$M_NOW,0,0,0,
X outbuf,strlen(outbuf)+1,0,0,0,0)) != SS$_NORMAL) {
X perror("output qiow 2");
X#ifdef DEBUG
X VDBG("output qiow(WRITEVBLK)=%d, errno=%d\n",i,errno);
X#endif
X }
X#else /* BSD SYSIII SYSV */
X dowrite(fd,outbuf,strlen(outbuf));
X#endif /* VMS BSD SYSIII SYSV */
X outbuf[0] = NULL;
X }
X strcat(outbuf,s);
X
X#else /* without buffering */
X#ifdef VMS
X if ((i=sys$qiow(0,fd,IO$_WRITEVBLK+IO$M_NOW,0,0,0,
X s,strlen(s)+1,0,0,0,0)) != SS$_NORMAL) {
X perror("output qiow 3");
X#ifdef DEBUG
X VDBG("output qiow(WRITEVBLK)=%d, errno=%d\n",i,errno);
X#endif
X }
X#else /* BSD SYSIII SYSV */
X dowrite(fd,s,strlen(s));
X#endif /* VMS BSD SYSIII SYSV */
X#endif /* with/without buffering */
X}
X
X#ifndef VMS
X#include
Xstatic VOID dowrite(fd,s,ls)
Xint fd,ls;
Xchar *s;
X{
X int oldmask;
X#ifdef BSD
X oldmask = sigblock(1<<(SIGALRM-1));
X#endif
X while (write(fd,s,ls) == -1 && errno == EINTR);
X#ifdef BSD
X sigsetmask(oldmask);
X#endif
X}
X#endif
END_OF_output.c
if test 3377 -ne `wc -c remove.c <<'END_OF_remove.c'
X/*
X * Spacewar - remove (nicely) an object from the universe (crft, torp, aln)
X * fixes (*)lhit,atck,dock,hom,auto
X * aliens are relocated (as if removed and replaced) when removed
X * torps are NOT removed if firing crft/aln removed
X * torps report a miss if fired at crft/torp/aln removed
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X#ifndef VMS
X#include
X#else /* BSD SYSIII SYSV */
X#include
X#endif /* VMS */
X#include "universe.h"
X#include "sys.h"
X#include "login.h"
X#include "crft.h"
X#include "obj.h"
X#include "torp.h"
X#include "flds.h"
X#include "aln.h"
X
XVOID remove(prmv)
Xidxptr prmv;
X{
X struct universe *puniv=univlst+MAXUNIVERSE;
X struct aln *paln;
X struct crft *pcrft;
X int i;
X struct torp *ptorp;
X
X#ifdef DEBUG
X DBG("remove(#%d/'%c/%c')\n",prmv.ip_ptr-univlst,prmv.ip_ptr->uv_type,
X prmv.ip_ptr->uv_pctr);
X#endif
X
X while (--puniv >= univlst) {
X if (!puniv->uv_type) continue;
X /*if (puniv == prmv.ip_ptr) continue;???*/
X
X switch(puniv->uv_type) {
X
X case 'A':
X paln = puniv->uv_ptr.uv_aln;
X if (paln->al_lhit.ip_ptr == prmv.ip_ptr) {
X paln->al_lhit.ip_ptr = NULL;
X paln->al_aeval = 0;
X }
X if (paln->al_atck.ip_ptr == prmv.ip_ptr) {
X paln->al_atck.ip_ptr = NULL;
X paln->al_dly = 0;
X }
X break;
X
X case 'P':
X pcrft = puniv->uv_ptr.uv_crft;
X if (pcrft->cr_dock.ip_ptr == prmv.ip_ptr) {
X pcrft->cr_dock.ip_ptr = NULL;
X pcrft->cr_scrn[7][15] = '?';
X }
X for (i=0;i < MHOM;++i)
X if (pcrft->cr_hom[i].ip_ptr == prmv.ip_ptr) {
X pcrft->cr_hom[i].ip_ptr = NULL;
X biton(pcrft->cr_chng,BIT_HOMCHAN+i);
X }
X if (pcrft->cr_auto.ip_ptr == prmv.ip_ptr) {
X pcrft->cr_auto.ip_ptr = NULL;
X biton(pcrft->cr_chng,BIT_AUTOFFWD);
X }
X if (pcrft->cr_lhit.ip_ptr == prmv.ip_ptr)
X pcrft->cr_lhit.ip_ptr = NULL;
X break;
X
X case 'T':
X ptorp = puniv->uv_ptr.uv_torp;
X if (ptorp->tp_lhit.ip_ptr == prmv.ip_ptr)
X ptorp->tp_lhit.ip_ptr = NULL;
X if (ptorp->tp_fby.ip_ptr == prmv.ip_ptr) {
X /**** don't remove (hee hee hee)****/
X /****idxptr xrmv; ****/
X /****xrmv.ip_ptr = puniv; ****/
X /****remove(xrmv); ****/
X /****continue; ****/
X ptorp->tp_fby.ip_ptr = NULL;
X }
X if (ptorp->tp_aim.ip_ptr == prmv.ip_ptr) {
X if (ptorp->tp_fby.ip_ptr &&
X ptorp->tp_fby.ip_ptr->uv_type == 'P') {
X pcrft = ptorp->tp_fby.ip_ptr->uv_ptr.uv_crft;
X output(pcrft->cr_lgn,'B',0,0);
X setrpt(pcrft);
X rpt(pcrft,"Torpedo missed - target went away");
X fnshrpt(pcrft,1);
X }
X remove(ptorp->tp_univ);
X continue;
X }
X break;
X }
X }
X
X /* relocate rather than remove aliens */
X if (prmv.ip_ptr->uv_type == 'A') {
X paln = prmv.ip_ptr->uv_ptr.uv_aln;
X
X /* zero out velocity, thrust, attack variables, subsystem damage */
X vinit(paln->al_vel);
X vinit(paln->al_thr);
X paln->al_dly = 0;
X paln->al_lhit.ip_ptr = NULL;
X paln->al_atck.ip_ptr = NULL;
X paln->al_aeval = 0;
X for (i=0;ial_sys[i].s_dmg = 0;
X prmv.ip_ptr->uv_mass = 0;
X
X /* relocate */
X for (i=0;i<3;++i)
X paln->al_pstn[i] = MUL(paln->al_pstn[i],-2.);
X vchngd(paln->al_univ.ip_ptr);
X
X /* actually remove the object */
X } else {
X if (prmv.ip_ptr->uv_type == 'T')
X binit((char *)prmv.ip_ptr->uv_ptr.uv_torp,sizeof(struct torp));
X else if (prmv.ip_ptr->uv_type == 'P')
X binit((char *)prmv.ip_ptr->uv_ptr.uv_crft,sizeof(struct crft));
X vrmv(prmv.ip_ptr);
X binit((char *)prmv.ip_ptr,sizeof(*prmv.ip_ptr));
X }
X
X
X#ifdef DEBUG
X VDBG("remove return\n");
X#endif
X}
END_OF_remove.c
if test 3648 -ne `wc -c shutdown.c <<'END_OF_shutdown.c'
X/*
X * Spacewar - shutdown (gracefully) the spacewar game
X *
X * Copyright 1984 obo Systems, Inc.
X * Copyright 1984 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X
X#ifdef VMS
X# include
X extern short inmlbx;
X#endif /* VMS */
X
XVOID shutdown(e)
Xint e;
X{
X register struct login *plogin;
X int i;
X extern int errno;
X
X#ifdef DEBUG
X DBG("shutdown(%d)\n",e);
X#endif
X
X /* don't update the universe any more */
X alarm(0);
X
X /* update objects, crafts */
X objupdate();
X crftupdate((struct login *)0);
X
X /* notify and log all players off */
X for (plogin=loginlst,i=MAXLOGIN;i-- > 0;++plogin)
X if (plogin->ln_tty) {
X if (plogin->ln_play.ip_ptr) {
X plogin->ln_play.ip_ptr = NULL;
X output(plogin,'E',0,0);
X }
X output(plogin,'B',0,0);
X output(plogin,'C',0,"\n\nSpacewar has been shut down\n");
X output(plogin,0,0,0);
X logoff(plogin);
X }
X
X /* remove communication files */
X#ifdef BSD
X if (unlink(SWLGNFILE)) perror(SWLGNFILE);
X if (unlink(SWPIDFILE)) perror(SWPIDFILE);
X#else /* VMS SYSIII SYSV */
X#ifdef VMS
X if ((i=sys$delmbx(inmlbx)) != SS$_NORMAL) {
X perror("delete mlbx 2");
X#ifdef DEBUG
X VDBG("shutdown delmbx()=%d, errno=%d\n",i,errno);
X#endif
X }
X if ((i=sys$dassgn(inmlbx)) != SS$_NORMAL) {
X perror("dassgn mlbx 2");
X#ifdef DEBUG
X VDBG("shutdown dassgn()=%d, errno=%d\n",i,errno);
X#endif
X }
X#else /* SYSIII SYSV */
X if (unlink(SWCOMFILE)) perror(SWCOMFILE);
X#endif /* VMS SYSIII SYSV */
X#endif /* VMS BSD SYSIII SYSV */
X
X#ifdef DEBUG
X VDBG("shutdown exiting\n");
X#endif
X exit(e);
X}
END_OF_shutdown.c
if test 1539 -ne `wc -c spacewar.h <<'END_OF_spacewar.h'
X/*
X * Spacewar - include file for general stuff
X *
X * Copyright 1984 obo Systems, Inc.
X * Copyright 1984 Dan Rosenblatt
X */
X
X#ifdef VMS
X#define VOID
X#define delete dbmdelete
X#endif /* VMS */
X
X#ifdef BSD
X# define SWPIDFILE "/usr/dir/sw/swpid"
X# define SWLGNFILE "/usr/dir/sw/swlgn"
X#else /* VMS SYSIII SYSV */
X#ifdef VMS
X# define SWCOMFILE "swmlbx"
X#else /* SYSIII SYSV */
X# define SWCOMFILE "/usr/dir/sw/swcomm"
X#endif /* VMS SYSIII SYSV */
X#endif /* BSD VMS SYSIII SYSV */
X
X#ifdef VMS
X# define SWDATABASE "$DISK2:[TSDIR.SW]swdb."
X# define SWGAME "$DISK2:[TSDIR.SW]sw"
X# define SWREAD "$DISK2:[TSDIR.SW]vmsrsw"
X# define SWNEWS "$DISK2:[TSDIR.SW]swnews"
X# define SWERR "$DISK2:[TSDIR.SW]swerr"
X# define SWOBJ "$DISK2:[TSDIR.SW]swobj"
X#else /* BSD SYSIII SYSV */
X# define SWDATABASE "/usr/dir/sw/swdb"
X# define SWGAME "/usr/dir/sw/sw"
X# define SWREAD "/usr/dir/sw/rsw"
X# define SWNEWS "/usr/dir/sw/swnews"
X# define SWERR "/usr/dir/sw/swerr"
X# define SWOBJ "/usr/dir/sw/swobj" /* see objupdate.c */
X#endif /* VMS BSD SYSIII SYSV */
X
X#define SWMASTER "Dan R"
X
X#define PI (3.1415926536)
X#define TWOPI (6.2831853072)
X#define DEGTORAD DIV(TWOPI,360.)
X#define PROMPT "\nPlay/See/Info/Complain/Mail/reBuild/Usercmd/Logoff/Who>"
X#ifdef NULL
X#undef NULL
X#endif
X#define NULL (0)
X
X/* uninteresting fudge factors */
X#define VANGVDST (3084.2514) /* makes 45deg match 5000 */
X
X/*
X * all floating-point operations through these macros
X * allowing co-processor routines to be substituted for in-line code
X */
X#define ADD(x,y) ((x)+(y))
X#define SUB(x,y) ((x)-(y))
X#define MUL(x,y) ((x)*(y))
X#define DIV(x,y) ((x)/(y))
X#define SQUARE(x) ((x)*(x))
X#define CUBE(x) ((x)*(x)*(x))
X
Xextern double sqrt();
Xextern int rand();
X#define SQRT(x) (sqrt(x))
X#define RANDOM(x) (rand()%(x))
X
Xextern double atan2(),sin(),cos();
X#define ATAN2(x,y) (atan2((x),(y)))
X#define SIN(x) (sin(x))
X#define COS(x) (cos(x))
X
Xextern double fmod();
X#define FMOD(x,y) (fmod((x),(y)))
X#define NEG(x) (-(x))
X#define INT(x) ((long)(x))
X#define FLOAT(i) ((double)(i))
X#define MAX(x,y) (((x) > (y)) ? (x) : (y))
X#define MIN(x,y) (((x) < (y)) ? (x) : (y))
X
X#ifdef DEBUG
Xextern VOID DBG(),VDBG();
X#endif
X
Xtypedef struct {
X double vec[3];
X double dst;
X char valid;
X} dsplcmnt;
X#define VECVALID 1
X#define DSTVALID 2
X
Xdsplcmnt vdisp();
END_OF_spacewar.h
if test 2296 -ne `wc -c swobj.init <<'END_OF_swobj.init'
X1000000 1 . 0 0 0 0 0 0 0
X22500 20 * 0 0 75000 0 0 0 0
X62500 50 * 0 0 -125000 0 0 0 0
X100 2 O 1 1000 2500 0 5 0 0
X800 6 O 1 1780 4000 0 0 6 0
X450 4 O 1 2125 7000 0 0 0 0
X500 4 O 1 3000 10000 0 0 0 0
X550 5 O 1 3250 16000 0 3.5 0 0
X1000 6 O 1 4200 19500 0 0 0 0
X700 5 O 1 5000 30000 0 3 0 0
X900 4 O 1 5600 32000 0 0 1 0
X375 2 O 1 6000 35000 0 1 0 0
X620 3 O 1 7500 40000 0 1.5 1.5 0
X275 2 O 1 8500 41000 0 -.5 -.5 0
X180 1 O 1 12500 48000 0 1 -1 0
X140 3 O 2 800 1500 0 0 0 0
X500 5 O 2 2000 3200 0 10 10 0
X900 6 O 2 4500 4500 0 -5 0 0
X300 7 O 2 5000 10000 0 0 -5 0
X650 9 O 2 7000 13000 0 2 3 0
X800 10 O 2 10100 14000 0 1 4 0
X400 3 O 2 9500 24000 0 -2 -2 0
X175 2 O 2 9000 30000 0 3 -1 0
X50 1 O 2 10500 33000 0 2 0 0
X75 1 O 2 12000 38000 0 0 2 0
X20 1 o 0 10000 175000 0 15 15 0
X25 1 o 1 500 125000 0 0 0 0
X40 1 o 1 1000 50000 0 -15 0 0
X15 1 o 2 3500 75000 0 0 -15 0
X5 1 o 2 4000 7000 0 5 10 0
X15 2 o 3 500 100 0 90 0 0
X18 1 o 8 750 75 0 0 90 0
X25 3 o 8 1500 150 0 -90 0 0
X5 1 o 8 200 40 0 0 -90 0
X8 1 o 10 300 50 0 45 45 0
X7 1 o 16 175 80 0 -45 45 0
X4 1 o 20 250 20 0 45 -45 0
X1 1 o 22 700 25 0 22 22 0
X2 1 o 23 650 75 0 -22 -22 0
X19 3 o 24 475 45 0 0 0 0
X1 10 # 17 0 150 0 0 90 0
X1 10 # 4 0 150 0 0 90 0
END_OF_swobj.init
if test 1198 -ne `wc -c upddsh.c <<'END_OF_upddsh.c'
X/*
X * Spacewar - update craft direction, sensors, and homing channels
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X#ifndef VMS
X#include
X#else /* BSD SYSIII SYSV */
X#include
X#endif /* VMS */
X#include "universe.h"
X#include "login.h"
X#include "sys.h"
X#include "aln.h"
X#include "crft.h"
X#include "flds.h"
X#include "obj.h"
X#include "torp.h"
X
Xextern double vlen(),vdist();
X
XVOID upddsh()
X{
X register struct crft *pcrft;
X register struct universe *puniv;
X double tmpvec[3];
X int i,sens0,sens1;
X long l;
X dsplcmnt tmpdspl;
X
X#ifdef DEBUG
X DBG("upddsh()\n");
X#endif
X
X for (pcrft=crftlst+MAXCRFT;pcrft-- > crftlst;) {
X if (!pcrft->cr_htyp) continue;
X
X /********************************************/
X /* direction based on autopilot/faceforward */
X /********************************************/
X if (pcrft->cr_ffwd)
X if (vlen(pcrft->cr_vel) == 0.) {
X pcrft->cr_ffwd = NULL;
X biton(pcrft->cr_chng,BIT_AUTOFFWD);
X } else
X rttosp(pcrft->cr_vel,tmpvec);
X else if (pcrft->cr_auto.ip_ptr) {
X /*vdiff(pcrft->cr_auto.ip_ptr->uv_pstn,pcrft->cr_pstn,tmpvec);*/
X tmpdspl = vdisp(pcrft->cr_auto.ip_ptr,pcrft->cr_univ.ip_ptr,'v');
X rttosp(/*tmpvec*/tmpdspl.vec,tmpvec);
X }
X
X /* update screen by checking rounded value */
X if (pcrft->cr_ffwd || pcrft->cr_auto.ip_ptr) {
X if (INT(DIV(MUL(pcrft->cr_dir[1],10.),DEGTORAD)) !=
X INT(DIV(MUL(tmpvec[1],10.),DEGTORAD)))
X biton(pcrft->cr_chng,BIT_DIR1);
X pcrft->cr_dir[1] = tmpvec[1];
X if (INT(DIV(MUL(pcrft->cr_dir[2],10.),DEGTORAD)) !=
X INT(DIV(MUL(tmpvec[2],10.),DEGTORAD)))
X biton(pcrft->cr_chng,BIT_DIR2);
X pcrft->cr_dir[2] = tmpvec[2];
X fixdir(pcrft);
X }
X
X /***********/
X /* sensors */
X /***********/
X sens0 = sens1 = 0;
X for (puniv=univlst+MAXUNIVERSE;puniv-- > univlst;) {
X if (!puniv->uv_type) continue;
X if (puniv == pcrft->cr_univ.ip_ptr) continue;
X tmpdspl = vdisp(puniv,pcrft->cr_univ.ip_ptr,'d');
X l = INT(/*vdist(puniv->uv_pstn,pcrft->cr_pstn)*/tmpdspl.dst);
X if (l <= pcrft->cr_vdst)
X sens0 += 1;
X if (l <= 5000L && puniv->uv_type != 'O')
X sens1 += 1;
X }
X if (sens0 != pcrft->cr_sens[0]) {
X pcrft->cr_sens[0] = sens0;
X biton(pcrft->cr_chng,BIT_SSEE);
X }
X if (sens1 != pcrft->cr_sens[1]) {
X pcrft->cr_sens[1] = sens1;
X biton(pcrft->cr_chng,BIT_SBAD);
X }
X
X /*******************/
X /* homing channels */
X /*******************/
X for (i=0;icr_hom[i].ip_ptr) continue;
X tmpdspl = vdisp(pcrft->cr_hom[i].ip_ptr,pcrft->cr_univ.ip_ptr,'d');
X l = INT(/*vdist(pcrft->cr_hom[i].ip_ptr->uv_pstn,pcrft->cr_pstn)*/tmpdspl.dst);
X if (l != pcrft->cr_hdst[i]) {
X pcrft->cr_hdst[i] = l;
X biton(pcrft->cr_chng,BIT_HOMCHAN+i);
X }
X }
X }
X
X#ifdef DEBUG
X VDBG("upddsh return\n");
X#endif
X}
END_OF_upddsh.c
if test 2872 -ne `wc -c updobjs.c <<'END_OF_updobjs.c'
X/*
X * Spacewar - update movement of objects
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X#include "universe.h"
X#include "obj.h"
X
XVOID updobjs()
X{
X register struct obj *pobj;
X double tmpvec[3];
X int i;
X
X#ifdef DEBUG
X DBG("updobjs()\n");
X#endif
X
X for (pobj=objlst;pobj < objlst+MAXOBJ;++pobj) {
X
X /* new orbital center relative plane theta */
X if (pobj->oj_oprd) {
X pobj->oj_ocrpt = ADD(pobj->oj_ocrpt,
X DIV(TWOPI,FLOAT(pobj->oj_oprd)));
X pobj->oj_ocrpt = FMOD(pobj->oj_ocrpt,TWOPI);
X }
X
X /* new position by converting from spherical to rectangular, */
X /* rotating from orbital plane, and translating from orbital */
X /* center; figure velocity from old and new position */
X vcopy(tmpvec,pobj->oj_pstn);
X pobj->oj_pstn[0] = FLOAT(pobj->oj_orad);
X pobj->oj_pstn[1] = pobj->oj_ocrpt;
X pobj->oj_pstn[2] = DIV(PI,2.);
X sptort(pobj->oj_pstn,pobj->oj_pstn);
X vecmul(pobj->oj_pstn,pobj->oj_rmat,pobj->oj_pstn);
X for (i=0;i < 3;++i)
X pobj->oj_pstn[i] = ADD(pobj->oj_pstn[i],
X pobj->oj_octr.ip_ptr->uv_pstn[i]);
X vchngd(pobj->oj_univ.ip_ptr);
X vdiff(pobj->oj_pstn,tmpvec,pobj->oj_vel);
X }
X
X#ifdef DEBUG
X VDBG("updobjs return\n");
X#endif
X}
END_OF_updobjs.c
if test 1249 -ne `wc -c updtorp.c <<'END_OF_updtorp.c'
X/*
X * Spacewar - torpedo intelligence
X * thrust torward target
X * miss/blow up logic
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X#ifndef VMS
X#include
X#else /* BSD SYSIII SYSV */
X#include
X#endif /* VMS */
X#include "universe.h"
X#include "sys.h"
X#include "login.h"
X#include "crft.h"
X#include "aln.h"
X#include "torp.h"
X#include "obj.h"
X
XVOID updtorp()
X{
X register struct torp *ptorp;
X double tmpvec[3],*pvel,vlen();
X long l,m;
X int i;
X dsplcmnt tmpdspl;
X
X#ifdef DEBUG
X DBG("updtorp()\n");
X#endif
X
X for (ptorp=torplst+MAXTORP;ptorp-- > torplst;) {
X if (!ptorp->tp_aim.ip_ptr) continue;
X
X /* vector and distance to target */
X /*vdiff(ptorp->tp_aim.ip_ptr->uv_pstn,ptorp->tp_pstn,tmpvec);*/
X /*l = INT(vlen(tmpvec));*/
X tmpdspl = vdisp(ptorp->tp_aim.ip_ptr,ptorp->tp_univ.ip_ptr,'b');
X l = INT(tmpdspl.dst);
X
X /* target is getting further away or is real close */
X if (l > ptorp->tp_dist || l < 50L) {
X
X /* too far away */
X if (ptorp->tp_dist < 5000L && l > 5000L) {
X /*idxptr prmv;*/
X if (ptorp->tp_fby.ip_ptr &&
X ptorp->tp_fby.ip_ptr->uv_type == 'P') {
X struct crft *pcrft=
X ptorp->tp_fby.ip_ptr->uv_ptr.uv_crft;
X output(pcrft->cr_lgn,'B',0,0);
X setrpt(pcrft);
X rpt(pcrft,"Your torpedo missed");
X fnshrpt(pcrft,1);
X }
X remove(ptorp->tp_univ);
X /*for (prmv.ip_ptr=univlst+MAXUNIVERSE;prmv.ip_ptr-- > univlst;)
X if (prmv.ip_ptr->uv_type == 'T' &&
X prmv.ip_ptr->uv_ptr.uv_torp == ptorp) {
X remove(prmv);
X break;
X }*/
X continue;
X
X /* real close */
X } else if (l < 50L) {
X /*idxptr prmv;*/
X if (ptorp->tp_fby.ip_ptr &&
X ptorp->tp_fby.ip_ptr->uv_type == 'P') {
X struct crft *pcrft=
X ptorp->tp_fby.ip_ptr->uv_ptr.uv_crft;
X output(pcrft->cr_lgn,'B',0,0);
X setrpt(pcrft);
X rpt(pcrft,"Your torpedo detonated");
X fnshrpt(pcrft,1);
X }
X damage(ptorp->tp_univ.ip_ptr,ptorp->tp_univ.ip_ptr,
X 100.,200.,"Torpedo attack");
X remove(ptorp->tp_univ);
X /*for (prmv.ip_ptr=univlst+MAXUNIVERSE;prmv.ip_ptr-- > univlst;)
X if (prmv.ip_ptr->uv_type == 'T' &&
X prmv.ip_ptr->uv_ptr.uv_torp == ptorp) {
X damage(prmv.ip_ptr,ptorp->tp_pstn,100.,200.,
X "Torpedo attack");
X remove(prmv);
X break;
X }*/
X continue;
X }
X }
X ptorp->tp_dist = l;
X
X /****************************/
X /* compute thrust to target */
X /****************************/
X switch(ptorp->tp_aim.ip_ptr->uv_type) {
X case 'P':
X pvel = ptorp->tp_aim.ip_ptr->uv_ptr.uv_crft->cr_vel;
X break;
X case 'T':
X pvel = ptorp->tp_aim.ip_ptr->uv_ptr.uv_torp->tp_vel;
X break;
X case 'A':
X pvel = ptorp->tp_aim.ip_ptr->uv_ptr.uv_aln->al_vel;
X break;
X }
X rttosp(/*tmpvec*/tmpdspl.vec,tmpvec);
X for (m=0;l > 0L && l > m;) {
X l -= m + MAXTTHR/2;
X m += MAXTTHR;
X }
X if (m < MAXTTHR/2) m = MAXTTHR/2;
X tmpvec[0] = FLOAT(m);
X sptort(tmpvec,tmpvec);
X for (i=0;i<3;++i)
X ptorp->tp_thr[i] = ADD(SUB(tmpvec[i],ptorp->tp_vel[i]),pvel[i]);
X }
X
X#ifdef DEBUG
X VDBG("updtorp return\n");
X#endif
X}
END_OF_updtorp.c
if test 3160 -ne `wc -c vdisp.c <<'END_OF_vdisp.c'
X/*
X * Spacewar - return vector displacement
X * (buffered to reduce recomputation)
X *
X * Copyright 1986 obo Systems, Inc.
X * Copyright 1986 Dan Rosenblatt
X */
X
X#ifndef VMS
X#include
X#else /* BSD SYSIII SYSV */
X#include
X#endif /* VMS */
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X#include "sys.h"
X#include "aln.h"
X#include "crft.h"
X#include "obj.h"
X#include "torp.h"
X
X
Xdsplcmnt vdisp(p1,p2,which)
Xregister struct universe *p1,*p2;
Xchar which;
X{
X dsplcmnt d;
X register dsplcmnt *pd;
X double vlen();
X int i,p1off;
X int negate=0;
X char *malloc();
X
X
X /* use higher of two pointers to cut storage in half ==> negate xyz */
X if (p2 > p1) {
X struct universe *ptmp;
X negate = 1;
X ptmp = p1;
X p1 = p2;
X p2 = ptmp;
X }
X
X p1off = p1 - univlst;
X
X /* allocate storage if not there already */
X if (!p1->uv_dspl) {
X if (!(pd = p1->uv_dspl = (dsplcmnt *)
X malloc(sizeof(dsplcmnt) * (p1off+1)))) {
X perror("vdisp malloc");
X if (negate)
X vdiff(p2->uv_pstn,p1->uv_pstn,d.vec);
X else
X vdiff(p1->uv_pstn,p2->uv_pstn,d.vec);
X d.dst = vlen(d.vec);
X return(d);
X }
X for (i=p1off;i-- > 0;)
X pd++->valid = 0; /* init to not valid */
X }
X
X /* point to displacement info and recompute if not valid */
X pd = p1->uv_dspl + (p2 - univlst);
X vdiff(p1->uv_pstn,p2->uv_pstn,pd->vec);
X pd->valid |= VECVALID;
X if ((which == 'd' || which == 'b') && !(pd->valid&DSTVALID)) {
X pd->dst = vlen(pd->vec);
X pd->valid |= DSTVALID;
X }
X
X if (negate) {
X d.valid = 0;
X if (which == 'v' || which == 'b') {
X d.vec[0] = -pd->vec[0];
X d.vec[1] = -pd->vec[1];
X d.vec[2] = -pd->vec[2];
X d.valid |= VECVALID;
X }
X if (which == 'd' || which == 'b') {
X d.dst = pd->dst;
X d.valid |= DSTVALID;
X }
X return(d);
X } else {
X return(*pd);
X }
X}
X
X/* mark all displacements w.r.t. puniv as invalid */
XVOID vchngd(puniv)
Xstruct universe *puniv;
X{
X register dsplcmnt *pd;
X int poff = (puniv - univlst);
X register int i;
X
X /* up to diagonal */
X if (pd = puniv->uv_dspl) {
X for (i=poff;i-- > 0;)
X pd++->valid = 0;
X }
X
X /* 90 degrees after reaching diagonal */
X while (++puniv < univlst+MAXUNIVERSE)
X if (pd = puniv->uv_dspl)
X pd[poff].valid = 0;
X
X}
X
XVOID vrmv(puniv)
Xstruct universe *puniv;
X{
X if (puniv->uv_dspl)
X free(puniv->uv_dspl);
X puniv->uv_dspl = 0;
X vchngd(puniv);
X}
END_OF_vdisp.c
if test 2354 -ne `wc -c vmsrsw.c <<'END_OF_vmsrsw.c'
X/*
X * Spacewar - program that reads a user's terminal and passes
X * it back to the spacewar game through a mailbox in
X * order to present spacewar with only one I/O channel to
X * read for user input eliminating polling
X *
X * Copyright 1985 obo Systems, Inc.
X * Copyright 1985 Dan Rosenblatt
X */
X
X#include "spacewar.h"
X#include "universe.h"
X#include "login.h"
X#include "uio.h"
X
X#include
X#include
X#include
X#include
X#include
Xstatic $DESCRIPTOR(swmlbx,SWCOMFILE);
Xstatic $DESCRIPTOR(tty,"TT");
Xstatic struct dsc$descriptor_s pmlbx;
Xstatic char buf[32];
Xstatic short swchan,tchan,pchan;
Xstatic struct uio ttyuio;
Xextern int errno;
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X struct login *plogin;
X int i,cleanup();
X
X /* get and save player's login pointer */
X if (argc != 3) exit(1);
X plogin = (struct login *) atoi(argv[1]);
X
X if ((i=sys$assign(&swmlbx,&swchan,PSL$C_USER,0)) != SS$_NORMAL) {
X sprintf(buf,"vmsrsw assign(swmlbx)=%d, errno=%d\n",i,errno);
X write(2,buf,strlen(buf));
X cleanup();
X }
X if ((i=sys$assign(&tty,&tchan,PSL$C_USER,0)) != SS$_NORMAL) {
X sprintf(buf,"vmsrsw assign(tty)=%d, errno=%d\n",i,errno);
X write(2,buf,strlen(buf));
X cleanup();
X }
X
X pmlbx.dsc$w_length = strlen(argv[2]);
X pmlbx.dsc$b_dtype = DSC$K_DTYPE_T;
X pmlbx.dsc$b_class = DSC$K_CLASS_S;
X pmlbx.dsc$a_pointer = argv[2];
X if ((i=sys$assign(&pmlbx,&pchan,PSL$C_USER,0)) != SS$_NORMAL) {
X sprintf(buf,"vmsrsw assign(pmlbx)=%d, errno=%d\n",i,errno);
X write(2,buf,strlen(buf));
X cleanup();
X }
X
X /* read tty and forward it on */
X signal(SIGALRM,cleanup);
X signal(SIGHUP,cleanup);
X for(;;) {
X if ((i=sys$qiow(0,tchan,IO$_READVBLK,0,0,0,ttyuio.uio_chrs,1,
X 0,0,0,0)) == SS$_NORMAL) {
X switch(ttyuio.uio_chrs[0]) {
X case '\031': /* ^Y */
X case '\032': /* ^Z */
X ttyuio.uio_lgn = (struct login *) SIGINT;
X strcpy(ttyuio.uio_chrs,argv[2]);
X break;
X case '\003': /* ^C */
X ttyuio.uio_lgn = (struct login *) SIGQUIT;
X strcpy(ttyuio.uio_chrs,argv[2]);
X break;
X default:
X ttyuio.uio_lgn = plogin;
X ttyuio.uio_chrs[1] = '\0';
X break;
X }
X alarm(10);
X if ((i=sys$qiow(0,swchan,IO$_WRITEVBLK,0,0,0,&ttyuio,
X sizeof(ttyuio),0,0,0,0)) != SS$_NORMAL) {
X sprintf(buf,"vmsrsw qiow(WRITE)=%d, errno=%d\n",
X i,errno);
X write(2,buf,strlen(buf));
X cleanup();
X }
X alarm(0);
X }
X }
X}
X
Xcleanup()
X{
X ttyuio.uio_lgn = (struct login *)SIGHUP;
X strcpy(ttyuio.uio_chrs,pmlbx.dsc$a_pointer);
X sys$qiow(0,swchan,IO$_WRITEVBLK+IO$M_NOW,0,0,0,&ttyuio,sizeof(ttyuio),
X 0,0,0,0);
X sys$qiow(0,pchan,IO$_WRITEVBLK+IO$M_NOW,0,0,0,"ShUtDoWn",9,0,0,0,0);
X exit(SS$_ABORT);
X}
END_OF_vmsrsw.c
if test 2666 -ne `wc -c