COSMOS Game (XENIX Specific), Part 01/03
Karl Denninger
karl at ddsw1.MCS.COM
Fri Nov 18 15:54:10 AEST 1988
This is the first of three archives containing COSMOS, a multiuser space
game for Xenix machines.
Note that this code is SPECIFIC to Xenix V/386. It MIGHT run on System V
80386 machines, the further you get away from this the less likely you are
to have success. In particular, you absolutely must have:
o SVID-compliant shared memory and semaphores.
o A large segment size (500K or so), or a completely flat address space.
o Paging would be nice :-)
o A working curses.
o A 'nap' call is highly recommended (short sleep).
FORGET EVEN TRYING to run this on a '286 -- it won't work. On Microport,
it won't even compile without severely crippling the size of the grid.
NOTE: This is shareware, but not crippleware. If you don't want it,
then don't keep it. Flames to /dev/null.
#! /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 <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 1 (of 3)."
# Contents: Makefile Manifest README buildbase.c dispstatus.c
# getship.c givedamage.c makechoice.c mines.c modgame.c phasers.c
# players.c rmseg.c scan.c
# Wrapped by karl at ddsw1 on Thu Nov 17 23:53:03 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1538 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# Makefile for Space - a multiuser game
X#
X# Copyright 1988 Macro Computer Solutions, Inc and Karl Denninger.
X#
X# All rights reserved.
X#
X# Unauthorized duplication, distribution, or modification is
X# prohibited by Federal and State law and will be prosecuted under
X# civil and criminal law.
X
CC=cc
X#
X# First CFLAGS line is for terminfo, others for termcap
X#
CFLAGS= -s -DM_TERMINFO -Ox -DVERSION=\"0.9.9B\" -DSYSID=\"386\" -DSYSV
X#CFLAGS= -s -DM_TERMCAP -Ox -Dcbreak=crmode -DVERSION=\"0.9.9B\" -DSYSID=\"386\" -DSYSV
LDFLAGS= -s -o
X#
X# Now we have two library call lines, first for terminfo, then termcap
X#
LIBS= -lcurses -lx -lm
X#LIBS= -ltcap -ltermcap -lx -lm
X#
X# Then the rest of the stuff
X#
INC_DEP=/usr/include/stdio.h\
X /usr/include/sys/types.h\
X /usr/include/fcntl.h\
X /usr/include/signal.h\
X /usr/include/setjmp.h\
X /usr/include/pwd.h\
X /usr/include/termio.h\
X /usr/include/sys/file.h\
X /usr/include/memory.h\
X cosmos.h
XFILES= cosmos.o\
X funcs.o\
X dispstatus.o\
X getship.o\
X buildbase.o\
X phasers.o\
X givedamage.o\
X mines.o\
X scan.o\
X modgame.o\
X torpedoes.o\
X players.o
X
all: cosmos rmseg drone
X
cosmos: $(INC_DEP) $(FILES)
X $(CC) $(LDFLAGS) cosmos $(FILES) $(LIBS)
X
rmseg: $(INC_DEP) rmseg.o
X $(CC) $(LDFLAGS) rmseg rmseg.o
X
drone: $(INC_DEP) drone.o funcs.o givedamage.o getship.o dispstatus.o \
X buildbase.o phasers.o makechoice.o torpedoes.o
X $(CC) $(LDFLAGS) drone drone.o funcs.o givedamage.o getship.o \
X dispstatus.o buildbase.o phasers.o makechoice.o torpedoes.o -lcurses -lx -lm
X
clean:
X rm drone cosmos rmseg *.o
END_OF_FILE
if test 1538 -ne `wc -c <'Makefile'`; then
echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'Manifest' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Manifest'\"
else
echo shar: Extracting \"'Manifest'\" \(734 characters\)
sed "s/^X//" >'Manifest' <<'END_OF_FILE'
X File Name Archive # Description
X-----------------------------------------------------------
X Help 2
X Makefile 1
X Manifest 1 This shipping list
X README 1
X buildbase.c 1
X cosmos.c 3
X cosmos.h 2
X dispstatus.c 1
X drone.c 2
X funcs.c 3
X getship.c 1
X givedamage.c 1
X makechoice.c 1
X mines.c 1
X modgame.c 1
X phasers.c 1
X players.c 1
X rmseg.c 1
X scan.c 1
X torpedoes.c 2
END_OF_FILE
if test 734 -ne `wc -c <'Manifest'`; then
echo shar: \"'Manifest'\" unpacked with wrong size!
fi
# end of 'Manifest'
fi
if test -f 'README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(6745 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
Welcome to COSMOS!
X
This is the first public release of the COSMOS game for Xenix and some Unix
machines. We hope you will find it to be a fun diversion from your normal
routine -- but be careful not to become addicted to it!
X
X
The following is our statement of policy with regards to the COSMOS package
and it's copyright, as well as general information on porting and
compatibility.
X
XFirst, the dry stuff we have to dispense with:
X
COSMOS is Copyright 1988 by MCS, Inc. and Karl Denninger
All component files in this 'shar' archive are considered covered by this
copyright, both individually and as a compilation.
All rights reserved.
X
Limited distribution rights are granted to the public as follows:
X
o Non-profit distribution of this SHAR file, in it's entirety, is permitted
X freely. If modifications are made, the unmodified files MUST be provided in
X any and all derivitive works.
X
o Non-profit and personal use of this software is permitted on an
X unrestricted basis.
X
o No derivitive or direct product of this work, whether composed of this
X package in whole or part, may be sold or used for profit without the express
X written consent of MCS, Inc. and Karl Denninger. "Profit" shall be defined
X as monetary compensation in excess of direct costs for the transfer of code
X or documentation contained in COSMOS, or compensation paid to secure the
X right to execute COSMOS on a host CPU. (If in doubt, ask. In general,
X having COSMOS available on a pay-for system is ok, as long as you don't
X charge specifically for COSMOS' use).
X
o Copyright notices and any other legends or trademarks must not be removed
X from the software and any accompanying documentation.
X
X
COSMOS is SHAREWARE. We request a $25.00 donation for each executing CPU.
In return, you'll be placed on our mailing list and alerted to new versions
of COSMOS, as well as receiving a nicely-printed users manual. It is
expected that after evaluating the game, you will either remove it from use
or register the package.
X
Please send checks to:
X
Macro Computer Solutions, Inc.
X415 S.E. Garfield
Mundelein, IL 60060
Attn: COSMOS Shareware
X
X
X
DISCLAIMER OF WARRANTY AND LIABILITY.
X
MCS and Karl Denninger hereby disclaim any and all warranties and
liabilities with regards to this package. COSMOS is provided "as is", and
the user is warned that there is no guarantee of completeness or
correctness, nor of fitness for any purpose whatsoever. The user is wholly
responsible for the results of compiling and using COSMOS, without
limitation.
X
X
Installation:
X
COSMOS is designed to execute on a SCO Xenix V/386 installation. As such,
it should compile without changes in it's supplied form. Other operating
systems may require SUBSTANTIAL modifications. To be able to support
COSMOS, you require at a minimum:
X
o Shared memory support per SVID (SVR2 or better)
o Semaphore support, per SVID.
o A segment size limitation (if any) in excess of 500K. Linear address
X spaces are highly preferred. This package WILL NOT run on a 80286. Don't
X even bother trying.
X
o A working CURSES implementation.
X
X
Highly recommended:
o A 'nap()' system call (short sleep).
X
X
If you have all the items noted above, you can probably build COSMOS. If
you're on a Xenix V/386 machine, you'll certainly be able to do so (in fact,
it should build without modifications).
X
Do all the usual things, peek in the Makefile and cosmos.h to make sure
things look reasonable to you, and type 'make'.
X
Place the binary files (cosmos and drone) in a publically-locatable directory. The executable 'rmseg' is provided to clean up after the COSMOS game; it
removes the shared segment and semaphore identifiers if needed.
X
X
To install:
X
Make a directory, and place the Help and Hello files in it. Make these
world readable. SGID cosmos, in a binary directory, to your games group
X(which should also own the directory you have the Help in).
X
Create /etc/cosmos, in the form:
X
X/pub/games/lib/cosmos/ 100 101 6 120 120 480
X
XFields:
X
X1. Base directory: where to find the Help and Hello files, as well as the
X place you want COMSOS to keep it's scorefile. Should NOT be publically
X accessible (660 is a good mode).
X
X2. First "god user" UID.
X3. Second "god user" UID.
X
X Both of these users can use the ^X, ^W and ^P functions.
X
X4. The number of drone ships you will allow to be in the game.
X WARNING: If this is too large, you'll have a VERY slow system! :-) 6 is
X reasonable for most 80386 machines.
X
X5. Time limit values for captive users. Currently incomplete, these values
X are used if ACCOUNTING is #defined in cosmos.h You may put any values
X you wish in here at present, but they MUST be present.
X
XExit the editor and make sure this file is readable by the COSMOS group.
X
Once this has been done, you are ready to play. Type 'cosmos' to start.
All documentation is online.
X
X
X
THEORY OF OPERATION
X
COSMOS is a shared-memory real-time space adventure. It is designed around
a single semaphore for locking, and a large shared memory segment for data
storage. All information that is considered globally "accurate" is
contained in this shared segment, which is created by the first player
entering the game.
X
The game system meters out time in discrete "chunks", the size of which are
under the control of the system installer. Drone ships operate using the
same rules and strategy as the human players, but are penalized slightly to
allow the humans some semblance of a chance in combat.
X
COSMOS is designed to decommission drones when there are no human players in
the game. After a few turns, the drones will put themselves to sleep until
one or more players reenter the game.
X
X
RESOURCE CONSUMPTION
X
COSMOS requires about 500K of shared memory in it's default configuration.
When the game is in play, this is mapped into each players virtual process
space, and thus consumes physical memory. During quiescent times of no
playing, the operating system should page this segment out to disk.
X
Drones are likewise stopped, but the process(es) in question continue to
remain alive on the system, albiet in suspended animation.
X
If this is a concen, you may modify the drone code to exit when they detect
a lack of human players. Similarly, it would be simple to add the required
support to delete the shared segment and semaphore when the last process
exits, although this is not currently done (not doing so keeps the game grid
around for the next player).
X
Of course, system reboots and crashes will cause the segment to be removed :-)
X
X
XEnjoy -- and watch that load average!
X
X--
Karl Denninger (karl at ddsw1.MCS.COM, ddsw1!karl)
Data: [+1 312 566-8912], Voice: [+1 312 566-8910]
Macro Computer Solutions, Inc. "Quality solutions at a fair price"
END_OF_FILE
if test 6745 -ne `wc -c <'README'`; then
echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'buildbase.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'buildbase.c'\"
else
echo shar: Extracting \"'buildbase.c'\" \(3900 characters\)
sed "s/^X//" >'buildbase.c' <<'END_OF_FILE'
X/* Base Building routines
X Contains routines for both player and computer people.... */
X
X/* Copyright 1988 Karl Denninger & MCS, Inc.
X All rights reserved */
X
X
X#include "cosmos.h"
X
extern char *buffer;
extern int drone;
extern struct nameblock *ship;
X
cbuildbase(semid, x, y, window)
int semid;
int x, y;
int window;
X
X{
X
X int kb;
X int xx, yy;
X int dist;
X struct grid onegrid;
X struct grid anothergrid;
X char tmp[80];
X
X release(semid);
X xx = x; yy = y;
X kb = findobj(&xx, &yy, &dist, PLANET, PLANET, window);
X acquire(semid);
X xx = 0; yy = 0;
X switch(kb) {
X case '8':
X xx = 0; yy = 1;
X break;
X case '9':
X xx = 1; yy = 1;
X break;
X case '6':
X yy = 0; xx = 1;
X break;
X case '3':
X yy = -1; xx = 1;
X break;
X case '2':
X xx = 0; yy = -1;
X break;
X case '1':
X xx = -1; yy = -1;
X break;
X case '4':
X xx = -1; yy = 0;
X break;
X case '7':
X xx = -1; yy = 1;
X break;
X }
X xx += x;
X yy += y;
X readgrid(xx, yy, &onegrid);
X if (onegrid.type == PLANET) { /* If now a planet */
X onegrid.shield += 10; /* Add one shield level */
X printf("Build %d\n", (onegrid.shield/10));
X fflush(stdout);
X ship->energy -= BUILDCOST; /* It's expensive! */
X ship->points += 50; /* One point for a build */
X readgrid(x, y, &anothergrid);
X anothergrid.energy = ship->energy;
X storegrid(x, y, anothergrid);
X } else { /* Can't build anything else */
X return(0);
X }
X if (onegrid.shield >= 100) { /* If we have a base.. */
X if (roll(200) < 2)
X onegrid.type = NEGBASE; /* Change it to a neg. base */
X else
X onegrid.type = BASE; /* Change it to a base */
X onegrid.align = ship->align; /* It's yours, or neutral */
X sprintf(tmp, "A new base appears at %d %d", xx, yy);
X putmsg(tmp);
X ship->points += 200; /* 200 for a base... */
X }
X storegrid(xx, yy, onegrid);
X release(semid);
X sleep(BUILDTIME); /* Sleep for BUILDTIME secs */
X acquire(semid);
X return(0);
X}
X
X
X
buildbase(semid, x, y)
int semid;
int x, y;
X
X{
X
X int kb;
X int xx, yy;
X struct grid onegrid;
X struct grid anothergrid;
X char tmp[80];
X
X release(semid);
X mvaddstr(22,20,"Build -> ");
X clrtoeol();
X refresh();
X kb = getchx();
X acquire(semid);
X if (ship->wstatus & SHIELD_UP) {
X mvaddstr(23,20,"Captain! We can't deploy troops through the shields!");
X clrtoeol();
X return(0);
X }
X xx = 0; yy = 0;
X switch(kb) {
X case '8':
X xx = 0; yy = 1;
X break;
X case '9':
X xx = 1; yy = 1;
X break;
X case '6':
X yy = 0; xx = 1;
X break;
X case '3':
X yy = -1; xx = 1;
X break;
X case '2':
X xx = 0; yy = -1;
X break;
X case '1':
X xx = -1; yy = -1;
X break;
X case '4':
X xx = -1; yy = 0;
X break;
X case '7':
X xx = -1; yy = 1;
X break;
X }
X xx += x;
X yy += y;
X if ((xx < 0) || (xx >= SIZE) || (yy < 0) || (yy >= SIZE)) {
X mvaddstr(23,20,"Can't build there");
X clrtoeol();
X return(0);
X }
X readgrid(xx, yy, &onegrid);
X if (onegrid.type == PLANET) { /* If now a planet */
X onegrid.shield += 10; /* Add one shield level */
X move(23,20);
X printw("Build %d", (onegrid.shield/10));
X release(semid);
X refresh();
X acquire(semid);
X ship->energy -= BUILDCOST; /* It's expensive! */
X ship->points += 50; /* One point for a build */
X readgrid(x, y, &anothergrid);
X anothergrid.energy = ship->energy;
X storegrid(x, y, anothergrid);
X } else { /* Can't build anything else */
X mvaddstr(23,20,"Nothing there to build!");
X clrtoeol();
X return(0);
X }
X if (onegrid.shield >= 100) { /* If we have a base.. */
X if (roll(200) < 2)
X onegrid.type = NEGBASE; /* Change it to a neg. base */
X else
X onegrid.type = BASE; /* Change it to a base */
X onegrid.align = ship->align; /* It's yours, or neutral */
X sprintf(tmp, "A new base appears at %d %d", xx, yy);
X putmsg(tmp);
X mvaddstr(23,20,"You have built a BASE!");
X ship->points += 200; /* 200 for a base... */
X }
X storegrid(xx, yy, onegrid);
X release(semid);
X sleep(BUILDTIME); /* Sleep for BUILDTIME secs */
X acquire(semid);
X return(0);
X}
X
END_OF_FILE
if test 3900 -ne `wc -c <'buildbase.c'`; then
echo shar: \"'buildbase.c'\" unpacked with wrong size!
fi
# end of 'buildbase.c'
fi
if test -f 'dispstatus.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'dispstatus.c'\"
else
echo shar: Extracting \"'dispstatus.c'\" \(6141 characters\)
sed "s/^X//" >'dispstatus.c' <<'END_OF_FILE'
X/* Dispstatus.c */
X
X#include "cosmos.h"
X
extern char *buffer;
extern int drone;
extern struct nameblock *ship;
X
calcstatus(x, y, window, docked) /* Calc green/red, no display */
int x, y;
int window;
int docked;
X
X{
X int scanx, scany; /* Scanner variables */
X struct grid onegrid; /* One grid entry */
X int scx, scy, tempint, tempx;
X int othership = 0;
X int ally =0;
X int enemy = 0;
X long oldenergy;
X int xx = 0, yx = 0;
X static int retval;
X
X readgrid(x, y, &onegrid); /* Get present situation */
X ship->shield = onegrid.shield; /* Update */
X oldenergy = ship->energy;
X if (onegrid.energy < ship->energy)
X ship->energy = onegrid.energy;
X scanx = x - (window / 2); /* Start here on each axis */
X scany = y - (window / 2);
X scx = 0;
X scy = window;
X othership = 0;
X tempint = scanx;
X while (scany <= (y + (window / 2))) {
X scx = 0;
X scanx = tempint;
X while (scanx <= (x + (window / 2))) {
X if ((scanx < 0) || (scany < 0) || (scanx >= SIZE) || (scany >= SIZE))
X ;
X else {
X readgrid(scanx, scany, &onegrid);
X if (onegrid.hit) {
X if ((scx != x) && (scy != y)) {
X if ((onegrid.type < 'A') || (onegrid.type > 'Z')) {
X onegrid.hit = 0;
X storegrid(scanx, scany, onegrid);
X }
X }
X }
X if ((onegrid.type >= 'A') && (onegrid.type <= 'Z')) {
X if (onegrid.align == ship->align) {
X othership++;
X ally++;
X } else {
X othership++;
X enemy++;
X }
X }
X
X }
X scx++;
X scanx++;
X }
X scany++;
X scy--;
X }
X othership--; /* We'll always be there */
X if (othership == 0) {
X retval = 0;
X } else {
X retval = 1;
X }
X return(retval);
X}
X
dispstatus(x, y, window, docked)
int x, y;
int window;
int docked;
X
X{
X int scanx, scany; /* Scanner variables */
X struct grid onegrid; /* One grid entry */
X int scx, scy, tempint, tempx;
X int othership = 0;
X int ally =0;
X int enemy = 0;
X long oldenergy;
X int xx = 0, yx = 0;
X int lastfound;
X int dx, dy;
X static int retval;
X
X
X for (xx = 0; xx <= (window + 1); xx++) {
X mvaddstr(xx,0,"|");
X mvaddstr(xx,(window * 2)+2,"|");
X }
X readgrid(x, y, &onegrid); /* Get present situation */
X ship->shield = onegrid.shield; /* Update */
X oldenergy = ship->energy;
X if (onegrid.energy < ship->energy)
X ship->energy = onegrid.energy;
X scanx = x - (window / 2); /* Start here on each axis */
X scany = y - (window / 2);
X scx = 0;
X scy = window;
X move(scy + 1, 1);
X for (xx = 0;xx <= (window * 2); xx++)
X addstr("=");
X lastfound = ((window / 2) + 1);
X move(scy + 1, (window - (strlen(">Scanner<") / 2)+1));
X addstr(">Scanner<");
X othership = 0;
X tempint = scanx;
X while (scany <= (y + (window / 2))) {
X scx = 0;
X scanx = tempint;
X while (scanx <= (x + (window / 2))) {
X dx = (scanx - x) * (scanx - x);
X dy = (scany - y) * (scany - y);
X if ((scanx < 0) || (scany < 0) ||
X (scanx >= SIZE) || (scany >= SIZE)
X#ifdef FASTMATH
X || ((int) sqr(dx + dy) >= lastfound)
X#endif
X )
X mvaddch(scy, (scx * 2)+1, 32);
X else {
X readgrid(scanx, scany, &onegrid);
X if (onegrid.hit)
X standout();
X if (docked == -1)
X mvaddch(scy, (scx * 2)+1, onegrid.type);
X else {
X if (onegrid.type == NEGBASE) {
X mvaddch(scy, (scx * 2)+1, BASE);
X } else {
X mvaddch(scy, (scx * 2)+1, onegrid.type);
X }
X }
X if (onegrid.hit) {
X standend();
X if ((scx != x) && (scy != y)) {
X if ((onegrid.type < 'A') || (onegrid.type > 'Z')) {
X onegrid.hit = 0;
X storegrid(scanx, scany, onegrid);
X }
X }
X }
X if ((onegrid.type >= 'A') && (onegrid.type <= 'Z')) {
X if (onegrid.align == ship->align) {
X othership++;
X ally++;
X } else {
X othership++;
X enemy++;
X }
X }
X
X }
X scx++;
X scanx++;
X }
X scany++;
X scy--;
X }
X move(0,44);
X printw(">> The S.S. %s <<", ship->name);
X clrtoeol();
X move(2,59);
X printw("Energy... %ld", ship->energy);
X clrtoeol();
X move(3,59);
X printw("Engines.. %d", ship->engines);
X clrtoeol();
X move(4,59);
X printw("Lasers... %d", ship->lasers);
X clrtoeol();
X move(5,59);
X if ((ship->wstatus & MINE_DEAD) == 0)
X printw("Mine Lch. %d", ship->mines);
X clrtoeol();
X move(6,59);
X if ((ship->wstatus & TORPEDO_DEAD) == 0)
X printw("Torp Lch. %d", ship->torps);
X clrtoeol();
X move(7,59);
X printw("Shield... %d", ship->shield);
X clrtoeol();
X move(8,59);
X printw("Crew Lvl. %d", ship->crew);
X clrtoeol();
X move(9,59);
X printw("Life Supt %d", ship->life);
X clrtoeol();
X move(10,59);
X printw("Hull..... %d", ship->hull);
X clrtoeol();
X move(11,59);
X if (docked)
X addstr("Ship..... DOCKED");
X clrtoeol();
X move(12,59);
X othership--; /* We'll always be there */
X if (othership == 0) {
X printw("Status... GREEN");
X retval = 0;
X } else {
X retval = 1;
X if (ship->wstatus & SHIELD_UP)
X printw("Status... YELLOW");
X else
X printw("Status... RED");
X }
X clrtoeol();
X move(13,59);
X if (ship->wstatus & SHIELD_DEAD)
X addstr("Shield... INOPERABLE");
X else {
X if (ship->wstatus & SHIELD_UP)
X addstr("Shield... UP");
X else
X addstr("Shield... DOWN");
X }
X clrtoeol();
X move(14,59);
X if (ship->wstatus & LASERS_DEAD)
X addstr("Lasers... INOPERABLE");
X else {
X if (ship->wstatus & LASERS_LOCK)
X addstr("Lasers... LOCKED");
X else
X addstr("Lasers... STBY");
X }
X clrtoeol();
X move(15,59);
X if (ship->wstatus & MINE_DEAD)
X clrtoeol();
X else {
X if (ship->wstatus & MINE_LOCK)
X addstr("Mines.... LOCKED");
X else
X addstr("Mines.... STBY");
X printw(" /%d", ship->nummines);
X }
X clrtoeol();
X move(16,59);
X if (ship->wstatus & TORPEDO_DEAD)
X clrtoeol();
X else {
X if (ship->wstatus & TORPEDO_LOCK)
X addstr("Torps.... LOCKED");
X else
X addstr("Torps.... STBY");
X printw(" /%d", ship->numtorps);
X }
X clrtoeol();
X mvaddstr(17,43,"------------------------------------");
X dspmsg(); /* Show any messages */
X mvaddstr(22,0,"Current Position");
X move(23,0);
X printw("X = %3d, Y = %3d", x, y);
X if (oldenergy > ship->energy) {
X mvaddstr(23,20,"You've been HIT!");
X clrtoeol();
X beep();
X }
X if (ship->gods) {
X/* mvaddstr(23,20,"You feel a supernatural force nearby");
X clrtoeol(); */
X ship->gods = 0;
X }
X if (oldenergy < ship->energy) {
X mvaddstr(23,20,"Energy transfer to you in progress");
X clrtoeol();
X }
X return(retval);
X}
X
END_OF_FILE
if test 6141 -ne `wc -c <'dispstatus.c'`; then
echo shar: \"'dispstatus.c'\" unpacked with wrong size!
fi
# end of 'dispstatus.c'
fi
if test -f 'getship.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'getship.c'\"
else
echo shar: Extracting \"'getship.c'\" \(5450 characters\)
sed "s/^X//" >'getship.c' <<'END_OF_FILE'
X/* Getship.c - get a new ship type */
X
X#include "cosmos.h"
X
X#define MAXCPNAMES 21 /* Number of names defined below */
static char *cpname[MAXCPNAMES] = {
X "Andrus", "Nomad", "Colossus", "W.O.P.R.", "Joshua",
X "James", "Zoonix", "Regula", "Andromeda", "Eteries",
X "Freightliner", "Unreliable", "Pegasus", "Sturgeon", "Challenger",
X "Enterprise", "Relient", "Excalibur", "Botany Bay", "Columbia",
X "Yugo" };
X
X
extern char *buffer;
extern char home[128];
extern int drone;
extern struct nameblock *ship;
X
X
X
char *getcship(semid, xx, yy)
int semid;
int *xx, *yy;
X
X{
X
X static struct nameblock shipx;
X
X struct shiprecord record;
X struct passwd *psw;
X struct nameblock entry;
X int uid;
X int fid;
X int index;
X char fname[80], tmp[80];
X int count;
X int quit = 0;
X long temp;
X int key;
X int x;
X
X strcpy(shipx.name, "_Computer");
X shipx.type = roll(11); /* Select a ship type */
X if (shipx.type == 0)
X shipx.type++;
X shipx.name[MAXNAME-1] = 0;
X#ifdef DEBUG
X *xx = 1;
X *yy = 1;
X#else
X *xx = roll(SIZE - 1);
X *yy = roll(SIZE - 1);
X#endif
X shipx.energy = (long) e_require[shipx.type]; /* Get max energy */
X shipx.points = (long) pts[shipx.type - 1]; /* Points to start */
X shipx.shield = 100;
X shipx.crew = 100;
X shipx.life = 100;
X shipx.engines = 100;
X shipx.hull = 100;
X shipx.lasers = 100;
X shipx.torps = 100;
X shipx.mines = 100;
X shipx.numtorps = num_torps[shipx.type]; /* Copy over config values */
X shipx.nummines = num_mines[shipx.type];
X shipx.wstatus = weapons[shipx.type];
X printf("Computer ship is called the %s, a %s with %ld pts.\n", shipx.name, shiptypes[shipx.type], shipx.points);
X fflush(stdout);
X quit = 0;
X key = 'A';
X while (quit == 0) {
X entry.token = key;
X if ((index = locship(&entry, 1)) < 0)
X quit++;
X else
X key++;
X }
X shipx.token = key;
X entry.token = 0;
X x = locship(&entry, 1); /* Find open slot */
X if (x == -1) {
X puts("Too many players!");
X release(semid);
X exit(0);
X }
X sprintf(tmp, "%s %d", cpname[roll(MAXCPNAMES)], (x + 1));
X strcpy(shipx.name, tmp);
X storename(x, shipx);
X return((char *) buffer + sizeof(ccount) + (sizeof(shipx) * x) );
X}
X
X
char *getship(cx, ptr, semid, xx, yy)
int cx;
char *ptr;
int semid;
int *xx, *yy;
X
X{
X
X static struct nameblock shipx;
X
X int cxx;
X struct shiprecord record;
X struct passwd *psw;
X struct nameblock entry;
X int uid;
X int fid;
X int index;
X char fname[80];
X int count;
X int quit = 0;
X long temp;
X int key;
X int x;
X
X cxx = cx;
X mvaddstr(1,20,"Ship Assignment - The Admiral's Quarters");
X mvaddstr(3,0,"Tkn Ship Name Class Points");
X x = 4;
X count = 0;
X while (count < MAXSHIPS) {
X readname(count, &entry);
X if (entry.token) {
X entry.name[MAXNAME-1] = 0; /* Just in case */
X mvaddch(x,0,entry.token);
X mvaddstr(x,5,entry.name);
X move(x,30);
X addstr(shiptypes[entry.type]);
X move(x,47);
X printw("%ld", entry.points); /* User's points */
X x++;
X }
X count++;
X }
X refresh();
X uid = getuid(); /* Who are we (really) */
X sprintf(fname, "%s/space.scorefile", HOMEDIR);
X if ((fid = open(fname, O_RDWR|O_CREAT, 0660)) < 0) {
X perror(fname);
X endwin();
X return((char *) NULL);
X }
X count = 0;
X while (read(fid, &record, sizeof(record)) == sizeof(record)) {
X if (record.uid == uid) {
X count++; /* Found record */
X lseek(fid, 0L - (sizeof(record)), 1);
X break;
X }
X }
X if (count == 0) {
X release(semid);
X mvaddstr(18,0, "Please name your vessel: ");
X refresh();
X get_str(shipx.name);
X acquire(semid);
X strcpy(record.shipname, shipx.name);
X shipx.type = 2;
X shipx.points = pts[(shipx.type - 1)];
X record.uid = getuid();
X record.type = 1;
X record.points = 0L;
X record.energy = e_require[shipx.type];
X write(fid, &record, sizeof(record));
X } else {
X shipx.type = record.type;
X shipx.points = record.points;
X shipx.energy = record.energy;
X strncpy(shipx.name, record.shipname, MAXNAME);
X shipx.name[MAXNAME-1] = 0;
X *xx = record.x;
X *yy = record.y;
X }
X close(fid);
X while (shipx.points > pts[shipx.type]) {
X shipx.type++;
X move(20,0);
X standout();
X shipx.energy = 0; /* Make sure you get full tanks */
X printw("Congratuations! You have been promoted to captain of a %s", shiptypes[shipx.type]);
X standend();
X clrtoeol();
X }
X if (!shipx.energy)
X shipx.energy = (long) e_require[shipx.type];/* Max energy */
X shipx.shield = 100;
X shipx.crew = 100;
X shipx.life = 100;
X shipx.engines = 100;
X shipx.hull = 100;
X shipx.lasers = 100;
X shipx.torps = 100;
X shipx.mines = 100;
X shipx.numtorps = num_torps[shipx.type]; /* Copy over config values */
X shipx.nummines = num_mines[shipx.type];
X shipx.wstatus = weapons[shipx.type];
X while (quit == 0) {
X release(semid);
X move(21,0);
X printw("Your ship is called the %s, a %s with %ld pts.", shipx.name, shiptypes[shipx.type], shipx.points);
X clrtoeol();
X mvaddstr(22,0,"Enter desired ship token: ");
X refresh();
X if (cxx > 1) {
X key = *ptr;
X cxx = 1;
X } else
X key = getchx();
X if ((key >= 'a') && (key <= 'z'))
X key = key - 32;
X if ((key < 'A') || (key > 'Z'))
X continue;
X addch(key);
X refresh();
X entry.token = key;
X acquire(semid);
X if ((index = locship(&entry, 1)) >= 0)
X mvaddstr(23,0, "In use, try again");
X else
X quit++;
X }
X shipx.token = key;
X shipx.uid = getuid();
X entry.token = 0;
X x = locship(&entry, 1); /* Find open slot */
X if (x == -1) {
X endwin();
X puts("Too many players!");
X release(semid);
X return((char *) NULL);
X }
X storename(x, shipx);
X return((char *) buffer + sizeof(ccount) + (sizeof(shipx) * x));
X}
END_OF_FILE
if test 5450 -ne `wc -c <'getship.c'`; then
echo shar: \"'getship.c'\" unpacked with wrong size!
fi
# end of 'getship.c'
fi
if test -f 'givedamage.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'givedamage.c'\"
else
echo shar: Extracting \"'givedamage.c'\" \(4738 characters\)
sed "s/^X//" >'givedamage.c' <<'END_OF_FILE'
X/* Give Damage to another object */
X
X#include "cosmos.h"
X
extern int drone;
extern struct nameblock *shp;
X
void givedamage(x, y, edmg, shp, explosion)
int x, y;
int edmg;
struct nameblock *shp;
int explosion;
X{
X int shiedmg;
X char tmp[80];
X int xx, hitperson;
X struct grid ogrid;
X struct nameblock oname;
X
X shiedmg = edmg / EPERSHIELD;
X if (shp != NULL)
X shp->points += (edmg / 200); /* Give the hitter points */
X readgrid(x, y, &ogrid);
X ogrid.hit++; /* Make it light up */
X if ((ogrid.type == EMPTY) || (ogrid.type == VOID)) {/* Nothing? */
X storegrid(x, y, ogrid); /* Save it back */
X return; /* Get the heck out */
X }
X if ((ogrid.type == BASE) || (ogrid.type == NEGBASE)) {
X if (ogrid.shield == 100) {
X sprintf(tmp, "Base under attack at %d %d", x, y);
X putmsg(tmp);
X }
X if (ogrid.shield > shiedmg) {
X ogrid.shield -= shiedmg;
X edmg = 0;
X } else {
X ogrid.shield = 0;
X }
X ogrid.energy -= edmg;
X }
X if (shp != NULL)
X if (drone == 0) {
X move(23,20);
X }
X if ((ogrid.shield <= 0) && ((ogrid.type == BASE) || (ogrid.type == NEGBASE))) {
X if (shp != NULL) {
X if (ogrid.align != shp->align)
X shp->points += 1000; /* Pts iff not yours */
X }
X ogrid.type = PLANET;
X ogrid.shield = 0;
X storegrid(x, y, ogrid);
X if (shp != NULL)
X if (drone == 0) {
X printw("FLASH! The base is DESTROYED!");
X }
X explode(x, y, (BASE_DEATH * EXPLOSION), BASE_DEATH);
X } else {
X if (shp != NULL) {
X if (drone == 0) {
X printw("Scored hit on '%c'", ogrid.type);
X }
X clrtoeol();
X }
X }
X if ((ogrid.type >= 'A') && (ogrid.type <= 'Z')) { /* A shp? */
X xx = 0;
X hitperson = -1;
X while (hitperson == -1) {
X readname(xx, &oname);
X if (oname.token == ogrid.type)
X hitperson = xx;
X xx++;
X }
X if (hitperson >= 0) /* Big shp has better shield */
X shiedmg = shiedmg / ((oname.type / 2) + 2);
X if (oname.wstatus & SHIELD_UP) {
X if (ogrid.shield > shiedmg) {
X ogrid.shield -= shiedmg;
X edmg = 0;
X } else {
X edmg -= ((ogrid.shield * ((oname.type / 2) + 2)) * EPERSHIELD);
X ogrid.shield = 0;
X }
X }
X ogrid.energy -= edmg; /* No diff for raw E hits */
X if (hitperson >= 0) { /* Systems are less fragile */
X edmg = edmg / oname.type;/* Divide by type */
X if (!explosion) { /* If not an explosion */
X xx = roll(8);
X switch(xx) {
X case 0:
X oname.engines -= edmg/100;
X break;
X case 1:
X oname.life -= edmg/150;
X break;
X case 2:
X oname.crew -= edmg/200;
X break;
X case 3:
X oname.shield -= edmg/75;
X break;
X case 4:
X oname.hull -= edmg/300;
X break;
X case 5:
X oname.lasers -= edmg/500;
X break;
X case 6:
X oname.torps -= edmg/200;
X break;
X case 7:
X oname.mines -= edmg/50;
X break;
X }
X } else { /* Explosion hurts everything */
X oname.engines -= edmg/(75 + roll(50));
X oname.life -= edmg/(100 + roll(100));
X oname.crew -= edmg/(150 + roll(100));
X oname.shield -= edmg/(50 + roll(50));
X oname.hull -= edmg/(200 + roll(200));
X oname.lasers -= edmg/(400 + roll(200));
X oname.torps -= edmg/(150 + roll(100));
X oname.mines -= edmg/(25 + roll(50));
X }
X }
X storename(hitperson, oname);
X if (ogrid.energy < 0) { /* If a shp blows up */
X if (shp != NULL)
X shp->points += (oname.points / 5);
X }
X } else {
X if (ogrid.type != VOID) {
X if (ogrid.shield > 0)
X ogrid.shield -= (edmg/100);
X if (ogrid.shield <= 0) {
X ogrid.shield = 0;
X ogrid.energy -= edmg;
X }
X }
X }
X if (ogrid.energy < 0) {
X if (drone == 0)
X mvaddstr(23,20,"FLASH! There is an explosion!");
X if ((ogrid.type < 'A') || (ogrid.type > 'Z')) {
X if ((ogrid.type == MINE) || (ogrid.type == TORPEDO)) {
X if (shp != NULL)
X shp->points += 25;
X ogrid.type = EMPTY;
X storegrid(x, y, ogrid);
X if (roll(NUKECHANCE) < 2) /* Nuke? */
X explode(x, y, (NUKE_MINE * EXPLOSION),
X NUKE_MINE);/* Nuclear mine */
X else
X explode(x, y, (MINE_BOOM * EXPLOSION),
X MINE_BOOM);/* Normal Mine */
X }
X if (ogrid.type == PLANET) {
X if (shp != NULL)
X shp->points += 3000;
X ogrid.type = EMPTY;
X storegrid(x, y, ogrid);
X explode(x, y, (BIG_BOOM * EXPLOSION), BIG_BOOM); /* Oh oh ! */
X sprintf(tmp, "Planet destroyed at %d %d", x, y);
X putmsg(tmp);
X }
X if (ogrid.type == STAR) {
X if (shp != NULL)
X shp->points += 8000;
X ogrid.type = VOID;
X ogrid.energy = roll(SIZE);
X ogrid.shield = roll(SIZE);
X storegrid(x, y, ogrid);
X explode(x, y, (NOVA * (EXPLOSION * 2)), NOVA); /* Ouch! */
X sprintf(tmp, "NOVA at %d %d!", x, y);
X putmsg(tmp);
X }
X } else {
X ogrid.type = EMPTY;
X storegrid(x, y, ogrid);
X explode(x, y, (SHIP_DEATH * EXPLOSION), SHIP_DEATH);
X }
X }
X storegrid(x, y, ogrid);
X return;
X}
END_OF_FILE
if test 4738 -ne `wc -c <'givedamage.c'`; then
echo shar: \"'givedamage.c'\" unpacked with wrong size!
fi
# end of 'givedamage.c'
fi
if test -f 'makechoice.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'makechoice.c'\"
else
echo shar: Extracting \"'makechoice.c'\" \(4177 characters\)
sed "s/^X//" >'makechoice.c' <<'END_OF_FILE'
X/* Space module MAKECHOICE - run the drone ship */
X
X#include "cosmos.h"
extern char *buffer;
extern struct nameblock *ship;
X
checkchoice(x, y, key, lastret) /* Is this a wise choice? */
int x, y;
int key;
int *lastret;
X
X{
X static int keyvec[10] = {'1', '4', '7', '8', '9', '6', '3', '2', 0};
X int retval;
X int xx, yy;
X struct grid ourgrid;
X int quit = 0;
X int infloop = 0;
X
X retval = key;
X if (key == 0) {
X if (roll(10) > 8) {
X retval = keyvec[roll(7)];
X } else {
X retval = *lastret;
X }
X }
X quit = 0;
X while (quit == 0) {
X infloop++; /* Infinite loop detector */
X xx = x; yy = y;
X switch(retval) {
X case '8':
X yy = y + 1;
X break;
X case '7':
X yy = y + 1;
X xx = x - 1;
X break;
X case '1':
X yy = y - 1;
X xx = x - 1;
X break;
X case '9':
X xx = x + 1;
X yy = y + 1;
X break;
X case '3':
X yy = y - 1;
X xx = x + 1;
X break;
X case '2':
X yy = y - 1;
X break;
X case '4':
X xx = x - 1;
X break;
X case '6':
X xx = x + 1;
X break;
X }
X if ((xx >= 0) && (yy >= 0) && (xx < SIZE) && (yy < SIZE)) {
X readgrid(xx, yy, &ourgrid);
X if (ourgrid.type == EMPTY) { /* Found an out */
X quit++;
X *lastret = retval;
X return(retval);
X }
X }
X retval = keyvec[roll(8)];
X if (infloop > 15) { /* Can't find a way out */
X retval = 0; /* So don't move anywhere */
X quit++;
X printf("Can't find path; sit\n");
X fflush(stdout);
X }
X }
X *lastret = retval;
X return(retval);
X}
X
makechoice(x, y, window, lastkey)
int x, y;
int window;
int *lastkey;
X{
X int xx, yy; /* Temp storage */
X int threat; /* If there is a threat... */
X int dist; /* Distance from 'mark' */
X int key; /* Code to be returned */
X static int list[10] = {'1','4','7','8','9','6','3','2',0 };
X static int conv[10] = {'9','6','3','2','1','4','7','8',0 };
X
X /* See if it's ok to hunt bases, energy must be full */
X
X if (ship->energy > (e_require[ship->type] - (e_require[ship->type]/5))) { /* Full? */
X xx = x; yy = y;
X key = findobj(&xx, &yy, &dist, BASE, BASE, window);
X if (key) { /* Oh boy! I see a base! */
X if (dist < 3) {
X for (xx = 0; xx < 9; xx++) { /* Back off! */
X if (list[xx] == key) {
X *lastkey = conv[xx];
X return(conv[xx]);
X }
X }
X } else {
X if (dist > 6) { /* Move in */
X *lastkey = key;
X return(key); /* Return move code */
X }
X *lastkey = 'L'; /* Shoot it! */
X return('L'); /* And out */
X }
X }
X }
X xx = x; yy = y;
X key = findobj(&xx, &yy, &dist, 'A', 'Z', window);
X if (!key) { /* There is a ship in range */
X if (ship->wstatus & SHIELD_UP)
X return('s'); /* Drop shields */
X } else {
X if (!(ship->wstatus & SHIELD_UP)) {
X if (dist > 4) { /* If a good distance */
X if ((ship->energy > (e_require[ship->type] / 5)) &&
X (ship->numtorps) && (ship->torps) &&
X (roll(dist - 4) > 1))
X return('t'); /* Fire torpedoes at ship */
X }
X if (!(ship->wstatus & SHIELD_DEAD)) { /* Not dead */
X return('s'); /* Raise shields! */
X }
X }
X if (ship->energy > (e_require[ship->type] / 5)) {/* Attack! */
X if (roll(dist) > 2) { /* If we outroll it */
X *lastkey = key;
X return(key); /* Move in */
X } else {
X *lastkey = 'l';
X return('l'); /* Else shoot! */
X }
X } else {
X for (xx = 0; xx < 9; xx++) {
X if (list[xx] == key) {
X *lastkey = conv[xx];
X return(conv[xx]);
X }
X }
X }
X } /* There is no ship in range to attack or run from */
X if (ship->energy < (e_require[ship->type] / 5)) {/* If low on power */
X xx = x; yy = y;
X key = findobj(&xx, &yy, &dist, BASE, BASE, window);
X if (key) {
X if (dist == 1) {
X *lastkey = 'D';
X return('D'); /* Dock */
X } else
X return(key); /* Go to the base */
X }
X }
X if (ship->energy < (e_require[ship->type] / 5) /* Need to build here */
X xx = x; yy = y;
X key = findobj(&xx, &yy, &dist, PLANET, PLANET, window);
X if (key) {
X if (dist == 1)
X return('B'); /* Build */
X else
X return(key); /* Go to the planet */
X }
X } /* Otherwise power is ok */
X if (*lastkey == 'D') { /* If docked... */
X if (ship->energy != e_require[ship->type])
X return('D'); /* Continue if not full */
X else {
X *lastkey = 0;
X return(0);
X }
X }
X return(*lastkey);
X}
END_OF_FILE
if test 4177 -ne `wc -c <'makechoice.c'`; then
echo shar: \"'makechoice.c'\" unpacked with wrong size!
fi
# end of 'makechoice.c'
fi
if test -f 'mines.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mines.c'\"
else
echo shar: Extracting \"'mines.c'\" \(1503 characters\)
sed "s/^X//" >'mines.c' <<'END_OF_FILE'
X/* Put a mine in someone's way :-) */
X
X#include "cosmos.h"
extern char *buffer;
extern int drone;
extern struct nameblock *ship;
X
extern int window;
extern void givedamage();
X
mines(semid, x, y)
int semid;
int x, y;
X{
X
X
X struct grid ourgrid;
X int xx = 0, yy = 0;
X int key = 0;
X
X if ((ship->mines < 30) || (ship->wstatus & MINE_DEAD))
X return(0); /* Weapon is dead */
X if (ship->nummines <= 0) {
X mvaddstr(23,20,"No more mines on board!");
X clrtoeol();
X return(0);
X }
X mvaddstr(15,59,"Mines.... ARMED");
X clrtoeol();
X mvaddstr(22,20,"Mines (1) -> ");
X clrtoeol();
X release(semid);
X refresh();
X key = getchx();
X acquire(semid);
X switch(key) {
X case '8':
X xx = 0;
X yy = 1;
X break;
X case '9':
X xx = 1;
X yy = 1;
X break;
X case '6':
X xx = 1;
X yy = 0;
X break;
X case '3':
X xx = 1;
X yy = -1;
X break;
X case '2':
X xx = 0;
X yy = -1;
X break;
X case '1':
X xx = -1;
X yy = -1;
X break;
X case '4':
X xx = -1;
X yy = 0;
X break;
X case '7':
X xx = -1;
X yy = 1;
X break;
X }
X if ( ((x + xx) >= SIZE) || ((x + xx) < 0) || ((y + yy) >= SIZE) || ((y + yy) < 0))
X return(0);
X readgrid((x + xx), (y + yy), &ourgrid);
X if (ourgrid.type != EMPTY) {
X mvaddstr(23,20,"EMERGENCY OVERRIDE! That space is not empty!");
X clrtoeol();
X return(0);
X }
X ourgrid.type = MINE;
X ourgrid.energy = MINE_ENERGY; /* Low value deliberately */
X ourgrid.shield = 0;
X ourgrid.hit = 0;
X storegrid((x + xx), (y + yy), ourgrid); /* Save it */
X ship->nummines--; /* Laid one */
X return(0);
X}
END_OF_FILE
if test 1503 -ne `wc -c <'mines.c'`; then
echo shar: \"'mines.c'\" unpacked with wrong size!
fi
# end of 'mines.c'
fi
if test -f 'modgame.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'modgame.c'\"
else
echo shar: Extracting \"'modgame.c'\" \(4582 characters\)
sed "s/^X//" >'modgame.c' <<'END_OF_FILE'
X/* Modgame - change game parameters */
X
X#include "cosmos.h"
X
extern int extx, exty;
X
modgame(semid)
int semid;
X{
X
X struct grid ourgrid;
X struct nameblock ourname;
X int key;
X char tmp[80];
X int xx, yy, x, y;
X
X release(semid);
X mvaddstr(23,20,"Modify <G>rid, <S>hip, <F>ind or <T>eleport > ");
X clrtoeol();
X refresh();
X key = toupper(getchx());
X switch (key) {
X case 'T':
X mvaddstr(23,20,"Teleport to -> ");
X clrtoeol();
X refresh();
X echo();
X get_str(tmp);
X noecho();
X if (!tmp[0]) {
X acquire(semid);
X return;
X }
X if (sscanf(tmp, "%d %d", &xx, &yy) != 2) {
X acquire(semid);
X return;
X }
X acquire(semid);
X readgrid(xx, yy, &onegrid);
X if (onegrid.type != EMPTY) {
X mvaddstr(23,20,"Space not empty");
X clrtoeol();
X refresh();
X sleep(2);
X return;
X }
X readgrid(extx, exty, &onegrid);
X storegrid(xx, yy, onegrid);
X onegrid.type = EMPTY;
X onegrid.energy = 0;
X onegrid.shield = 0;
X storegrid(extx, exty, onegrid);
X extx = xx;
X exty = yy;
X break;
X case 'F':
X mvaddstr(23,20,"Find what -> ");
X clrtoeol();
X refresh();
X key = toupper(getchx());
X if (!key) {
X acquire(semid);
X return;
X }
X move(23,40);
X printw("Find %c", key);
X refresh();
X for (x = 0; x < SIZE; x++) {
X for (y = 0; y < SIZE; y++) {
X readgrid(x, y, &ourgrid);
X if (ourgrid.type == key) {
X move(23,40);
X printw("Found at %d %d", x, y);
X clrtoeol();
X refresh();
X sleep(5);
X break;
X }
X }
X }
X acquire(semid);
X break;
X case 'G':
X mvaddstr(23,20,"X Y coordinates > ");
X clrtoeol();
X refresh();
X get_str(tmp);
X if (tmp[0] == 0) {
X acquire(semid);
X return;
X }
X if (sscanf(tmp, "%d %d", &x, &y) != 2) {
X mvaddstr(23,20,"Invalid coordinates");
X clrtoeol();
X acquire(semid);
X return;
X }
X if ((x < 0) || (y < 0) || (x >= SIZE) || (y >= SIZE)) {
X mvaddstr(23,20,"Invalid coordinates");
X clrtoeol();
X acquire(semid);
X return;
X }
X readgrid(x, y, &ourgrid);
X move(22,20);
X printw("Type = %d, E = %d, Shield = %d", ourgrid.type, ourgrid.energy, ourgrid.shield);
X clrtoeol();
X mvaddstr(23,20,"New type (`.,@*+) > ");
X clrtoeol();
X refresh();
X key = getchx();
X acquire(semid);
X ourgrid.type = EMPTY;
X switch(key) {
X case '.':
X case ' ':
X ourgrid.type = EMPTY;
X ourgrid.shield = 0;
X ourgrid.energy = 0;
X break;
X case '@':
X ourgrid.type = PLANET;
X ourgrid.shield = 0;
X ourgrid.energy = 10000000L;
X break;
X case '*':
X ourgrid.type = STAR;
X ourgrid.shield = 0;
X ourgrid.energy = 20000000L;
X break;
X case ',':
X ourgrid.type = MINE;
X ourgrid.energy = 5L;
X ourgrid.shield = 0;
X break;
X case '`':
X ourgrid.type = ASTEROID;
X ourgrid.energy = 500000L;
X ourgrid.shield = 20;
X break;
X case '+':
X ourgrid.type = BASE;
X ourgrid.energy = 10000000L;
X ourgrid.shield = 100;
X break;
X }
X move(22,20);
X printw("Type = %d, E = %d, Shield = %d", ourgrid.type, ourgrid.energy, ourgrid.shield);
X mvaddstr(23,20,"Energy = ");
X clrtoeol();
X refresh();
X get_str(tmp);
X sscanf(tmp, "%d", &ourgrid.energy);
X mvaddstr(23,20,"Shield = ");
X clrtoeol();
X refresh();
X get_str(tmp);
X sscanf(tmp, "%d", &ourgrid.shield);
X storegrid(x, y, ourgrid);
X break;
X case 'S':
X mvaddstr(23,20,"Ship letter> ");
X clrtoeol();
X refresh();
X key = getchx();
X for (x = 0; x < MAXSHIPS; x++) {
X readname(x, &ourname);
X if (ourname.token == key) {
X move(23,20);
X printw("Type = %d, E = %d, Sh = %d, Pts = %d", ourname.type, ourname.energy, ourname.shield, ourname.points);
X clrtoeol();
X mvaddstr(22,20,"New Type = ");
X clrtoeol();
X refresh();
X get_str(tmp);
X sscanf(tmp, "%d", &ourname.type);
X mvaddstr(22,20,"New E = ");
X clrtoeol();
X refresh();
X get_str(tmp);
X sscanf(tmp, "%d", &ourname.energy);
X mvaddstr(22,20,"New Shield = ");
X clrtoeol();
X refresh();
X get_str(tmp);
X sscanf(tmp, "%d", &ourname.shield);
X mvaddstr(22,20,"New Points = ");
X clrtoeol();
X refresh();
X get_str(tmp);
X sscanf(tmp, "%d", &ourname.points);
X acquire(semid);
X ourname.gods++;
X storename(x, ourname);
X for (x = 0; x < SIZE; x++) {
X for (y = 0; y < SIZE; y++) {
X readgrid(x, y, &ourgrid);
X if (ourgrid.type == ourname.token) {
X
X ourgrid.energy = ourname.energy;
X ourgrid.shield = ourname.shield;
X storegrid(x, y, ourgrid);
X }
X }
X }
X return(0);
X }
X }
X }
X return;
X}
END_OF_FILE
if test 4582 -ne `wc -c <'modgame.c'`; then
echo shar: \"'modgame.c'\" unpacked with wrong size!
fi
# end of 'modgame.c'
fi
if test -f 'phasers.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'phasers.c'\"
else
echo shar: Extracting \"'phasers.c'\" \(2943 characters\)
sed "s/^X//" >'phasers.c' <<'END_OF_FILE'
X/* Phaser/laser fire - Part of the COSMOS universe
X
X Copyright 1988 Karl Denninger & MCS, Inc.
X All rights reserved
X
X*/
X
X#include "cosmos.h"
X
extern char *buffer;
extern int drone;
extern struct nameblock *ship;
X
extern int window;
extern void givedamage();
X
phasers(semid, x, y)
int semid;
int x, y;
X{
X
X static int xx, yy;
X static int x1, y1;
X static char tmp[80];
X static char tmp2[80];
X
X struct grid onegrid;
X struct grid ourgrid;
X char args[40];
X char *arg[3];
X long edmg;
X long shiedmg;
X int hitperson;
X struct nameblock onename;
X int dist;
X
X if (ship->wstatus & LASERS_DEAD)
X return(0); /* Weapon is dead */
X mvaddstr(14,59,"Lasers... ARMED");
X clrtoeol();
X mvaddstr(22,20,"Lasers -> ");
X clrtoeol();
X release(semid);
X refresh();
X get_str(args);
X acquire(semid);
X if (args[0])
X strcpy(tmp2, args);
X strcpy(tmp, tmp2);
X if ((!isdigit(tmp[0])) && (tmp[0] != '-')) {
X if (ship->type < 3) { /* Small doesn't have lock */
X mvaddstr(23,20,"We don't have weapons locking!");
X clrtoeol();
X return(0);
X }
X xx = x;
X yy = y;
X if (!findobj(&xx, &yy, &dist, toupper(tmp[0]), toupper(tmp[0]), window)) {
X mvaddstr(23,20,"Target not found");
X clrtoeol();
X return(0);
X } else {
X x1 = (xx - x);
X y1 = (yy - y);
X }
X } else {
X if ((arg[0] = strtok(tmp, ":, ")) == NULL) {
X mvaddstr(23,20,"Requires two parameters");
X clrtoeol();
X return(0);
X } else
X x1 = atoi(arg[0]);
X if ((arg[1] = strtok((char *) NULL, ":, ")) == NULL) {
X mvaddstr(23,20,"Requires two parameters");
X clrtoeol();
X return(0);
X } else
X y1 = atoi(arg[1]);
X }
X if (((x + x1) < 0) || ((x + x1) >= SIZE)
X || ((y + y1) < 0) || ((y + y1) >= SIZE)) {
X mvaddstr(23,20,"Invalid coordinates");
X clrtoeol();
X return(0);
X }
X if ((x1 == 0) && (y1 == 0)) {
X mvaddstr(23,20,"Silly -- you can't shoot yourself!");
X clrtoeol();
X return(0);
X }
X edmg = (int) ((800 + roll(700)) * ship->type) / sqr((x1 * x1) + (y1 * y1) + 1);
X readgrid((x + x1), (y + y1), &ourgrid); /* Anything there? */
X if ((ourgrid.type != EMPTY) && (ourgrid.type != VOID)) {
X readgrid(x, y, &ourgrid);
X ship->energy -= (200 * ship->type);
X ourgrid.energy -= (200 * ship->type);
X storegrid(x, y, ourgrid);
X givedamage((x + x1), (y + y1), edmg, ship, 0); /* Give it damage */
X }
X return(0);
X}
X
cphasers(x, y, startobj, endobj)
int x, y;
int startobj, endobj;
X{
X
X int xx, yy;
X int dist;
X int go;
X int tmpx, dir;
X int edmg;
X struct grid ourgrid;
X
X if (ship->lasers < 30) {
X if (roll(200) > ship->lasers)
X return(0);
X }
X xx = x; yy = y;
X dir = findobj(&xx, &yy, &dist, startobj, endobj, window);
X if (dir == 0)
X return(0); /* No target in range */
X if (dir) {
X edmg = ((1000 + roll(700)) * ship->type) / sqr(((xx - x) * (xx - x)) + ((yy - y) * (yy - y)) + 1);
X readgrid(x, y, &ourgrid);
X ship->energy -= (200 * ship->type);
X ourgrid.energy -= (200 * ship->type);
X storegrid(x, y, ourgrid);
X givedamage(xx, yy, edmg, ship, 0); /* Give it damage */
X }
X return(1);
X}
END_OF_FILE
if test 2943 -ne `wc -c <'phasers.c'`; then
echo shar: \"'phasers.c'\" unpacked with wrong size!
fi
# end of 'phasers.c'
fi
if test -f 'players.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'players.c'\"
else
echo shar: Extracting \"'players.c'\" \(348 characters\)
sed "s/^X//" >'players.c' <<'END_OF_FILE'
int addplayer(limited, timed, ac, av)
int *limited; /* Return, NZ = limited player */
int *timed; /* Return, NZ = timed player */
int ac; /* Count of arguments */
char *av; /* Second argument */
X{
X
X}
X
void delplayer(ac, av, start)
int ac; /* Count of arguments */
char *av; /* Second argument */
long start; /* Game start time */
X{
X
X}
END_OF_FILE
if test 348 -ne `wc -c <'players.c'`; then
echo shar: \"'players.c'\" unpacked with wrong size!
fi
# end of 'players.c'
fi
if test -f 'rmseg.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'rmseg.c'\"
else
echo shar: Extracting \"'rmseg.c'\" \(1430 characters\)
sed "s/^X//" >'rmseg.c' <<'END_OF_FILE'
X/* Spacewar - The final frontier
X
X This package is Copyright 1988 Karl Denninger. All rights reserved.
X
X All unauthorized mutants shall be destroyed, fed to vermin, and the
X remains from this process will be prosecuted.
X
X*/
X
X/* Definitions go below - Make sure you have these in front of include
X files as these definitions should override the include files */
X
X
X#include "cosmos.h"
X
struct nameblock name;
struct grid onegrid;
X
main()
X{
X int seg; /* Shared segment number */
X char *buffer; /* Buffer pointer */
X
X int size;
X int x, y; /* X & Y coordinates of ship */
X int key;
X int quit = 0; /* Halt variable */
X int tempint;
X
X struct nameblock namebuf;
X long game = (sizeof(onename) * MAXSHIPS) + sizeof(ccount) +
X (sizeof(onegrid) * MAXGRID) + (sizeof(onemsg) * MAXMSG);
X size = (game); /* Get size of game module */
X
X printf("COSMOS Maintenance cleanup\n");
X printf("Remove segment %s\n",VERSION);
X if ((seg = shmget(122L, size, IPC_CREAT|0660)) == -1) {
X perror("create");
X puts("Cannot execute due to shared-segment create fault");
X exit(1);
X }
X if (shmctl(seg, IPC_RMID, 0)) {
X perror("destroy");
X puts("Cannot delete segment");
X exit(1);
X }
X if ((seg = semget(122L, 1, IPC_CREAT|0660)) == -1) {
X perror("create");
X puts("Cannot execute due to semaphore create fault");
X exit(1);
X }
X if (semctl(seg, IPC_RMID, 0)) {
X perror("destroy");
X puts("Cannot delete semaphore");
X exit(1);
X }
X
X exit(0);
X}
END_OF_FILE
if test 1430 -ne `wc -c <'rmseg.c'`; then
echo shar: \"'rmseg.c'\" unpacked with wrong size!
fi
# end of 'rmseg.c'
fi
if test -f 'scan.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'scan.c'\"
else
echo shar: Extracting \"'scan.c'\" \(2693 characters\)
sed "s/^X//" >'scan.c' <<'END_OF_FILE'
X/* Cosmos - A game of the cosmos */
X
X#include "cosmos.h"
extern char *buffer;
extern struct nameblock *ship;
X
scan(semid, x, y, window)
int semid, x, y;
int window;
X{
X
X int xx, yy;
X int z = 0, zx;
X int dist;
X int key;
X struct grid ourgrid;
X struct nameblock name;
X int vector;
X
X release(semid);
X mvaddstr(22,20,"Scan object -> ");
X refresh();
X key = getchx();
X acquire(semid);
X if ((key == 10) || (key == 13) || (key == 0))
X return(0);
X else {
X xx = x; yy = y;
X vector = findobj(&xx, &yy, &dist, key, key, window_size[ship->type]);
X if (vector == 0) {
X mvaddstr(23,20,"No object found");
X clrtoeol();
X return(0); /* Nothing to scan */
X }
X readgrid(xx, yy, &ourgrid);
X for (zx = 1; zx < 17; zx++) {
X mvaddstr(zx, 44, " ");
X }
X if ((ourgrid.type >= 'A') && (ourgrid.type <= 'Z')) {
X name.token = key;
X z = locship(&name, 1);
X readname(z, &name);
X name.scanned++;
X storename(z, name);
X move(1,44);
X printw("'%c', a %s", name.token, shiptypes[name.type]);
X clrtoeol();
X move(2,49);
X z = name.energy;
X printw("%9ld", z);
X move(3,49);
X printw("%9d", (name.engines + roll(20) - 10));
X move(4,49);
X printw("%9d", (name.lasers + roll(20) - 10));
X move(5,49);
X if ((ship->wstatus & MINE_DEAD) == 0)
X printw("%9d", (name.mines + roll(20) - 10));
X else
X addstr(" ");
X move(6,49);
X if ((ship->wstatus & TORPEDO_DEAD) == 0)
X printw("%9d", (name.torps + roll(20) - 10));
X else
X addstr(" ");
X move(7,49);
X printw("%9d", (ourgrid.shield + roll(20) - 10));
X move(8,49);
X printw("%9d", (name.crew + roll(20) - 10));
X move(9,49);
X printw("%9d", (name.life + roll(20) - 10));
X move(10,49);
X printw("%9d", (name.hull + roll(20) - 10));
X move(13,49);
X if (name.wstatus & SHIELD_DEAD)
X addstr("INOPER.");
X else {
X if (name.wstatus & SHIELD_UP)
X addstr("UP ");
X else
X addstr("DOWN ");
X }
X clrtoeol();
X move(14,49);
X if (name.wstatus & LASERS_DEAD)
X addstr("INOPER.");
X else {
X if (name.wstatus & LASERS_LOCK)
X addstr("LOCKED ");
X else
X addstr("STBY ");
X }
X move(15,49);
X if (name.wstatus & MINE_DEAD)
X addstr(" ");
X else {
X if (name.wstatus & MINE_LOCK)
X addstr("LOCK");
X else
X addstr("STBY");
X printw("/%d", name.nummines);
X }
X move(16,49);
X if (ship->wstatus & TORPEDO_DEAD)
X addstr(" ");
X else {
X if (ship->wstatus & TORPEDO_LOCK)
X addstr("LOCK");
X else
X addstr("STBY");
X printw("/%d", name.numtorps);
X }
X } else {
X move(2,49);
X z = ourgrid.energy;
X printw("%9ld", z);
X move(7,49);
X printw("%9d", ourgrid.shield);
X }
X }
X return(1);
X}
X
END_OF_FILE
if test 2693 -ne `wc -c <'scan.c'`; then
echo shar: \"'scan.c'\" unpacked with wrong size!
fi
# end of 'scan.c'
fi
echo shar: End of archive 1 \(of 3\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 3 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
--
Karl Denninger (karl at ddsw1.MCS.COM, ddsw1!karl)
Data: [+1 312 566-8912], Voice: [+1 312 566-8910]
Macro Computer Solutions, Inc. "Quality solutions at a fair price"
More information about the Alt.sources
mailing list