lars@myab.UUCP (lars) (03/13/86)
#--------CUT---------CUT---------CUT---------CUT--------#
#########################################################
# #
# This is a shell archive file. To extract files: #
# #
# 1) Make a directory for the files. #
# 2) Write a file, such as "file.shar", containing #
# this archive file into the directory. #
# 3) Type "sh file.shar". Do not use csh. #
# #
#########################################################
#
#
echo x - aliens.c
sed 's/^Z//' >aliens.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: aliens.c,v 2.1 85/04/10 17:30:09 matt Stab $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Greg Ordy 1979
Z * Rewrite by Sam Leffler 1981
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines dealing with aliens
Z *
Z * Copyright (c) 1979
Z *
Z * $Log: aliens.c,v $
Z * Revision 2.1 85/04/10 17:30:09 matt
Z * Major de-linting and minor restructuring.
Z *
Z */
Z
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Z/*
Z * Move an alien -- update displays
Z */
Zvoid movealien(pa)
Zregister t_alien *pa;
Z{
Z extern int rand();
Z extern void launch();
Z void phaser();
Z int psycho();
Z register t_player *pl;
Z char dx,
Z dy;
Z
Z pa->count--;
Z /*
Z * If we're not on screen, just update internally
Z */
Z if (pa->onscr == OFF || pa->whotoget == NOTHING) {
Z if (pa->count == 0) { /* shanker alarm clock */
Z pa->count = (rand()%20)+100;
Z pa->cix = (rand()%3)-1;
Z pa->ciy = (rand()%3)-1;
Z if (pa->cix == 0 && pa->ciy == 0)
Z pa->ciy = -1;
Z }
Z pa->cx += pa->cix;
Z pa->cy += pa->ciy;
Z return;
Z }
Z pl = &pa->whotoget->u_player;
Z pa->onscr = OFF;
Z if (pa->count <= 0) {
Z pa->count = 10; /* reset alarm clock */
Z dx = pl->curx - pa->cx;
Z dy = pl->cury - pa->cy;
Z /*
Z * Close enough to a player to shoot?
Z */
Z if (dx < 9 && dx > -9 && dy < 5 && dy > -5) {
Z pa->fx = pl->offx;
Z pa->fy = pl->offy;
Z if (pl->status.alive == FALSE) {
Z pa->whotoget = 0;
Z return;
Z }
Z if (dx == 0) {
Z if (dy == 0) {
Z phaser(pa, pl);
Z return;
Z }
Z if (!psycho(pa))
Z launch((thing *)pa, dy > 0 ? SO : NO,
Z ALIEN, pa->fx, pa->fy, 0,
Z pa->cx, pa->cy, 0);
Z } else if (dx == dy) {
Z if (!psycho(pa))
Z launch((thing *)pa, dx > 0 ? SE : NW,
Z ALIEN, pa->fx, pa->fy, 0,
Z pa->cx, pa->cy, 0);
Z } else if (dx == -dy) {
Z if (!psycho(pa))
Z launch((thing *)pa, dx > 0 ? NE : SW,
Z ALIEN, pa->fx, pa->fy, 0,
Z pa->cx, pa->cy, 0);
Z } else if (dy == 0) {
Z if (dx == 0) {
Z phaser(pa, pl);
Z return;
Z }
Z if (!psycho(pa))
Z launch((thing *)pa, dx > 0 ? EA : WE,
Z ALIEN, pa->fx, pa->fy, 0,
Z pa->cx, pa->cy, 0);
Z }
Z if (dx > 0) {
Z if (dy > 0)
Z pa->cx++;
Z else
Z pa->cy--;
Z } else {
Z if (dy > 0)
Z pa->cy++;
Z else
Z pa->cx--;
Z }
Z return;
Z }
Z if (dx < 0)
Z pa->cx--;
Z if (dx > 0)
Z pa->cx++;
Z
Z if (dy < 0)
Z pa->cy--;
Z if (dy > 0)
Z pa->cy++;
Z }
Z if (pl->offx > 3 || pl->offx < -3)
Z pa->cx += pa->cix;
Z else
Z pa->cx += pl->offx;
Z if (pl->offy > 3 || pl->offy < -3)
Z pa->cy += pa->ciy;
Z else
Z pa->cy += pl->offy;
Z}
Z
Z/*
Z * Check for psychos -- if found, unleash torpedo barrage
Z */
Zint psycho(pa)
Zregister t_alien *pa;
Z{
Z extern int rand();
Z register char x,y;
Z char ox,
Z oy;
Z
Z if(((rand()>>5)%6) != 5) /* magic decision */
Z return(0);
Z x = pa->cx;
Z y = pa->cy;
Z ox = pa->fx;
Z oy = pa->fy;
Z launch((thing *)pa, SO, ALIEN, ox, oy, 0, x, y, 8);
Z launch((thing *)pa, NO, ALIEN, ox, oy, 0, x, y, 8);
Z launch((thing *)pa, SE, ALIEN, ox, oy, 0, x, y, 8);
Z launch((thing *)pa, NW, ALIEN, ox, oy, 0, x, y, 8);
Z launch((thing *)pa, NE, ALIEN, ox, oy, 0, x, y, 8);
Z launch((thing *)pa, SW, ALIEN, ox, oy, 0, x, y, 8);
Z launch((thing *)pa, EA, ALIEN, ox, oy, 0, x, y, 8);
Z launch((thing *)pa, WE, ALIEN, ox, oy, 0, x, y, 8);
Z return(1);
Z}
Z
Z/*
Z * Phaser a player for a shanker
Z */
Zvoid phaser(pa, p)
Zregister t_alien *pa;
Zregister t_player *p;
Z{
Z extern int rand();
Z extern void pmesg();
Z
Z pa->whotoget = 0;
Z pa->cix++;
Z pa->ciy = (rand()%4)-2;
Z p->maxe -= 50;
Z if (p->maxe < p->energy)
Z p->energy = p->maxe;
Z pmesg(p, "Enjoy the shankers revenge!");
Z}
STUNKYFLUFF
set `sum < aliens.c`
if test 56769 != $1
then
echo aliens.c: Error. number of characters is: $1, should be: 56769.
fi
#
#
echo x - bursts.c
sed 's/^Z//' >bursts.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: bursts.c,v 1.2 85/07/08 17:22:19 matt Exp $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Greg Ordy 1979
Z * Rewrite by Sam Leffler 1981
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines to manipulate shrapnel
Z *
Z * Copyright (c) 1979
Z *
Z */
Z
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Z/*
Z * Create a burst of shrapnel upon death of a player.
Z */
Zvoid makeburst(bx, by)
Zchar bx, by;
Z{
Z extern t_burst bursts[NBURST];
Z register t_burst *bp;
Z register t_burst *last;
Z
Z last = &bursts[NBURST];
Z for (bp = bursts; bp < last; bp++) {
Z if (bp->cbactive != 0)
Z continue;
Z bp->cbactive++;
Z bp->cbx = bx;
Z bp->cby = by;
Z bp->shrap[0][0] = bx;
Z bp->shrap[0][1] = by;
Z bp->cbcnt = 100;
Z return;
Z }
Z}
Z
Z/*
Z * Update shrapnel position and display
Z */
Zvoid moveburst() {
Z extern int nplayer;
Z extern char xxi,
Z yyi;
Z extern t_burst bursts[NBURST];
Z void getdir();
Z register int j;
Z register t_burst *bp,
Z *last;
Z register char xi,
Z yi,
Z qrt;
Z
Z last = &bursts[NBURST];
Z for (bp = bursts; bp < last; bp++) {
Z if (bp->cbactive == 0)
Z continue;
Z if (bp->cbcnt == 100) {
Z bp->cbcnt--;
Z break;
Z }
Z if (bp->cbcnt == 98) {
Z bp->cbcnt = 50;
Z for (j=1; j != 4; j++) {
Z qrt = (rand()>>4)%8;
Z xi = bp->cbx;
Z yi = bp->cby;
Z switch (qrt) {
Z case 0:
Z xi++;
Z break;
Z case 1:
Z xi++;
Z yi--;
Z break;
Z case 2:
Z yi--;
Z break;
Z case 3:
Z xi--;
Z yi--;
Z break;
Z case 4:
Z xi--;
Z break;
Z case 5:
Z xi--;
Z yi++;
Z break;
Z case 6:
Z yi++;
Z break;
Z case 7:
Z xi++;
Z yi++;
Z break;
Z }
Z bp->shrap[j][0] = xi;
Z bp->shrap[j][1] = yi;
Z bp->shrapd[j] = qrt;
Z }
Z break;
Z }
Z if (bp->cbcnt > 48) {
Z bp->cbcnt--;
Z break;
Z }
Z if (bp->cbcnt == 48) {
Z bp->cbcnt = (rand()>>4)%(16-nplayer);
Z qrt = bp->shrapd[1];
Z xi = bp->shrap[1][0];
Z yi = bp->shrap[1][1];
Z getdir(qrt, xi, yi);
Z bp->shrap[0][0] = xxi;
Z bp->shrap[0][1] = yyi;
Z getdir(qrt, xi, yi);
Z bp->shrap[4][0] = xxi;
Z bp->shrap[4][1] = yyi;
Z qrt = bp->shrapd[2];
Z xi = bp->shrap[2][0];
Z yi = bp->shrap[2][1];
Z getdir(qrt, xi, yi);
Z bp->shrap[5][0] = xxi;
Z bp->shrap[5][1] = yyi;
Z getdir(qrt, xi, yi);
Z bp->shrap[6][0] = xxi;
Z bp->shrap[6][1] = yyi;
Z qrt = bp->shrapd[3];
Z xi = bp->shrap[3][0];
Z yi = bp->shrap[3][1];
Z getdir(qrt, xi, yi);
Z bp->shrap[7][0] = xxi;
Z bp->shrap[7][1] = yyi;
Z getdir(qrt, xi, yi);
Z bp->shrap[8][0] = xxi;
Z bp->shrap[8][1] = yyi;
Z break;
Z }
Z bp->cbcnt--;
Z if (bp->cbcnt == 3) {
Z for (j = 1; j != 4; j++) {
Z bp->shrap[j][0] = 0;
Z bp->shrap[j][1] = 0;
Z }
Z bp->shrap[0][0] = 0;
Z bp->shrap[0][1] = 0;
Z break;
Z }
Z if (bp->cbcnt == 0) {
Z for (j = 4; j != 9; j++) {
Z bp->shrap[j][0] = 0;
Z bp->shrap[j][1] = 0;
Z }
Z bp->cbactive = 0;
Z break;
Z }
Z }
Z}
Z
Z/*
Z * Furnish random movement for shrapnel pieces
Z */
Zstatic void getdir(dir, xi, yi)
Zchar dir, xi, yi;
Z{
Z extern int rand();
Z extern char xxi,
Z yyi;
Z register char dx,
Z dy;
Z
Z dx = ((rand()>>3)%3)-1;
Z dy = ((rand()>>3)%3)-1;
Z switch (dir) {
Z case 0:
Z if (dx < 0)
Z dx = 2;
Z break;
Z case 1:
Z if (dx < 0)
Z dx = 2;
Z if (dy > 0)
Z dy = -2;
Z break;
Z case 2:
Z if (dy > 0)
Z dy = -2;
Z break;
Z case 3:
Z if (dx > 0)
Z dx = -2;
Z if (dy > 0)
Z dy = -2;
Z break;
Z case 4:
Z if (dx > 0)
Z dx = -2;
Z break;
Z case 5:
Z if (dx > 0)
Z dx = -2;
Z if (dy < 0)
Z dy = 2;
Z break;
Z case 6:
Z if (dy < 0)
Z dy = 2;
Z break;
Z case 7:
Z if (dx < 0)
Z dx = 2;
Z if (dy < 0)
Z dy = 2;
Z break;
Z }
Z xxi = xi+dx;
Z yyi = yi+dy;
Z}
STUNKYFLUFF
set `sum < bursts.c`
if test 54986 != $1
then
echo bursts.c: Error. number of characters is: $1, should be: 54986.
fi
#
#
echo x - cmds1.c
sed 's/^Z//' >cmds1.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: cmds1.c,v 2.3 85/08/06 22:28:20 matt Exp $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Greg Ordy 1979
Z * Rewrite by Sam Leffler 1981
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines to execute player commands
Z *
Z * Copyright (c) 1979
Z *
Z * $Log: cmds1.c,v $
Z * Revision 2.3 85/08/06 22:28:20 matt
Z * Change handling of "r", "b", "g", "j", "q" commands to
Z * provide better feedback, using per-player message buffer.
Z *
Z * Revision 2.2 85/05/30 22:43:05 matt
Z * You can't send a "Temporary malfunction" message to an alien!!
Z *
Z * Revision 2.1 85/04/10 17:30:46 matt
Z * Major de-linting and minor restructuring.
Z *
Z */
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Zint TDIST = TSIZE; /* max distance a torpedoe travels */
Z
Z/*
Z * Launch a torpedo.
Z * "firer" shot it, using the "where" key, firing in the <ox, oy> direction.
Z * "dd" indicates distance until it dies.
Z * "mess" indicates if a launch message should be given.
Z * "xl" and "yl" give the origin for calculating distance.
Z * "type" identifies the type of the firer.
Z */
Zvoid launch(firer, where, type, ox, oy, mess, xl, yl, dd)
Zregister thing *firer;
Zchar where, xl, yl, ox, oy;
Z{
Z extern void pstatus();
Z extern t_torps torps[NTORP];
Z register char x,
Z y;
Z register t_torps *tp,
Z *last;
Z
Z last = &torps[NTORP];
Z x = ox; y = oy;
Z switch (where) {
Z case NO: y--; break;
Z case NE: x++; y--; break;
Z case EA: x++; break;
Z case SE: x++; y++; break;
Z case SO: y++; break;
Z case SW: x--; y++; break;
Z case WE: x--; break;
Z case NW: x--; y--; break;
Z default:
Z if (x == ox && y == oy) {
Z pstatus(&firer->u_player, "Illegal direction\n");
Z return;
Z }
Z }
Z for (tp = torps; tp < last; tp++) {
Z if (tp->owner != NOTHING) continue;
Z if (type==PLAYER && firer->u_player.energy<TPCOST) {
Z if (mess) {
Z pstatus(&firer->u_player, "Need more energy!");
Z firer->u_player.cmdpend = 0;
Z }
Z return;
Z }
Z tp->owner = firer; tp->torx = xl; tp->tory = yl;
Z tp->tcount = dd != 0 ? dd : TDIST;
Z tp->xinc = x; tp->yinc = y;
Z if (type != PLAYER) return;
Z firer->u_player.energy -= TPCOST;
Z firer->u_player.cmdpend = 0;
Z if (mess) pstatus(&firer->u_player, "Launch!");
Z return;
Z }
Z if (type != PLAYER) return;
Z pstatus(&firer->u_player, "Temporary malfunction!");
Z firer->u_player.cmdpend = 0;
Z}
Z
Z/*
Z * Show coordinates of an object locked in on channel "channel".
Z */
Zvoid home(p, channel)
Zregister t_player *p;
Zchar channel;
Z{
Z extern void pstatus();
Z void showhome();
Z
Z p->cmdpend = 0;
Z if (channel < '1' || channel > '3') {
Z pstatus(p, "Invalid channel number!");
Z return;
Z }
Z channel -= '1';
Z if (p->home[channel] == NOTHING) {
Z pstatus(p, "Channel not locked on object!");
Z return;
Z }
Z showhome(p, channel);
Z}
Z
Z/*
Z * Show the coordinates of a homing radar channel on the screen --
Z * assumes the channel is valid.
Z */
Zstatic void showhome(p, channel)
Zregister t_player *p;
Zregister int channel;
Z{
Z extern void put();
Z extern t_sbase sbase[NBASE];
Z extern t_alien alien[NALIEN];
Z extern t_player player[NPLAYER];
Z extern t_torps torps[NTORP];
Z thing *val; /* should be union */
Z
Z switch (channel) {
Z
Z case 0:
Z move(H1DATAX, H1DATAY, p); /* macro */
Z break;
Z case 1:
Z move(H2DATAX, H2DATAY, p);
Z break;
Z case 2:
Z move(H3DATAX, H3DATAY, p);
Z break;
Z }
Z val = p->home[channel];
Z if (isalien(val))
Z put(p, "%d %d", val->u_alien.cx, -val->u_alien.cy);
Z else if (isplayer(val))
Z put(p, "%d %d", val->u_player.curx, -val->u_player.cury);
Z else if (isbase(val))
Z put(p, "%d %d", val->u_sbase.xpos, -val->u_sbase.ypos);
Z else
Z put(p, "%d %d", val->u_torps.torx, -val->u_torps.tory);
Z}
Z
Z/*
Z * Set channel "channel" so that it's locked in on the object
Z * currently "underneath" player "p".
Z */
Zvoid sethome(p, channel)
Zregister t_player *p;
Zchar channel;
Z{
Z extern void pstatus();
Z void showhome();
Z
Z p->cmdpend = 0;
Z if (channel < '1' || channel > '3') {
Z pstatus(p, "Invalid channel number!");
Z return;
Z }
Z channel -= '1';
Z if (p->whocent == NOTHING) {
Z pstatus(p, "Not over an object!");
Z return;
Z }
Z p->home[channel] = p->whocent;
Z showhome(p, channel);
Z pstatus(p, "Locked on %c", gettype(p->whocent));
Z}
Z
Z/*
Z * Get a character representing the thing 't'.
Z */
Zgettype(t)
Zunion thing_u *t;
Z{
Z if (isbase(t)) return '*';
Z else if (isplayer(t)) return 'A'+&t->u_player-player;
Z else if (isalien(t)) return t->u_alien.aname;
Z else return ' ';
Z}
Z
Z
Z/*
Z * Invisibility toggle -- useless during solar flares.
Z */
Zvoid invisible (p)
Zregister t_player *p;
Z{
Z extern int sfflag,
Z gutsflag;
Z extern void pmesg(),
Z put();
Z
Z move(INDATAX, INDATAY, p); /* macro */
Z if (p->status.invis == FALSE) {
Z if (sfflag == ON) {
Z put(p, "off");
Z pmesg(p, "From radar-- Solar flare up!!");
Z return;
Z } else if (gutsflag) {
Z put(p, "off");
Z pmesg(p, "No invisibility in GUTS mode");
Z return;
Z }
Z put(p, "on ");
Z p->status.invis = TRUE;
Z } else {
Z put(p, "off");
Z p->status.invis = FALSE;
Z }
Z}
Z
Z/*
Z * Dock at a starbase -- causes refueling to take place.
Z */
Zvoid dock(p)
Zregister t_player *p;
Z{
Z extern void pstatus(),
Z cput();
Z
Z if (!isbase(p->whocent)) {
Z pstatus(p, "Not over a starbase!");
Z return;
Z }
Z pstatus(p, "Successful docking!");
Z if (p->maxe < p->maxmaxe) p->maxe = p->maxe+25;
Z if (p->maxe > p->maxmaxe) p->maxe = p->maxmaxe;
Z p->energy = p->maxe;
Z cput(EGYDATA, p, "%d", p->energy);
Z}
Z
Z/*
Z * Autopilot on a channel which has previously been locked onto
Z * an object -- normally this is a starbase, but it could be a
Z * player, alien, or even a planet.
Z */
Zvoid autopi(p, channel)
Zregister t_player *p;
Zchar channel;
Z{
Z extern t_planet planet;
Z extern void pstatus();
Z thing *val;
Z register char *x,
Z *y;
Z
Z p->cmdpend = 0;
Z if (channel < '1' || channel > '3') {
Z pstatus(p, "Invalid channel number!");
Z return;
Z }
Z channel -= '1';
Z val = p->home[channel];
Z if (val == NOTHING) {
Z pstatus(p, "Channel not locked on object!");
Z return;
Z }
Z if (isalien(val)) {
Z x = & val->u_alien.cx;
Z y = & val->u_alien.cy;
Z } else if (isplayer(val)) {
Z x = & val->u_player.curx;
Z y = & val->u_player.cury;
Z } else if (isbase(val)) {
Z x = & val->u_sbase.xpos;
Z y = & val->u_sbase.ypos;
Z } else { /* planet !?!?!? */
Z x = & planet.places[0][0];
Z y = & planet.places[0][1];
Z }
Z
Z p->apx = x;
Z p->apy = y;
Z p->status.ap = TRUE;
Z p->status.orb = FALSE;
Z pstatus(p, "Autopilot process begun to %c", gettype(val));
Z}
Z
Z/*
Z * Broadcast a message.
Z */
Zvoid bcast(p, letter)
Zregister t_player *p;
Zchar letter;
Z{
Z extern void pmesg(),
Z echomsg(),
Z donemsg(),
Z makescab();
Z register t_player *pl;
Z
Z if (letter != '\n' && letter != '\r') {
Z if (letter == SCABLETTER) { /* no tty tricks! */
Z makescab(p);
Z letter = '^';
Z }
Z echomsg(p, letter);
Z } else {
Z
Z for (pl = player; pl < &player[NPLAYER]; pl++)
Z if (pl->status.alive == TRUE)
Z pmesg(pl, "\07From %s -- %s", p->plname, p->mesgbuf);
Z p->cmdpend = 0;
Z donemsg(p);
Z }
Z}
Z
Z/*
Z * broadcast and radio message echoing routines
Z */
Z
Zvoid
Zgathermsg(p)
Zregister t_player *p;
Z{
Z if (p->mesgdst >= NPLAYER)
Z pmesg(p, "From radio room-- enter message to group");
Z else if (p->mesgdst > 0)
Z pmesg(p, "From radio room-- enter message to %c (%s)",
Z p->mesgdst-1+'A', player[p->mesgdst-1].plname);
Z else
Z pmesg(p, "From radio room-- enter message");
Z prompt(p, "TEXT: ");
Z p->mesglen = 0;
Z p->mesgbuf[0] = '\0';
Z bflush(p);
Z#ifdef DEBUG
Z errlog ("GATHERMSG: after bflush.\n");
Z#endif DEBUG
Z}
Z
Z/*
Z * echoing is relative to the prompt string given above
Z */
Z#define INPUTSTART PROMPTX+6
Z#define INPUTY PROMPTY
Z
Zvoid
Zechomsg(p, c)
Zregister t_player *p;
Zchar c;
Z{
Z if (c=='\b' || c=='\177') {
Z if (p->mesglen) {
Z cput(p->mesglen+INPUTSTART, INPUTY, p, " \b");
Z p->mesglen--;
Z }
Z p->mesgbuf[p->mesglen] = '\0';
Z } else if (c=='@' || c=='\025') {
Z gathermsg(p);
Z return;
Z } else {
Z /* unprintable cacters show up as blanks */
Z if (c < ' ')
Z c = ' ';
Z
Z if (p->mesglen < 35) {
Z p->mesgbuf[p->mesglen++] = c;
Z p->mesgbuf[p->mesglen] = '\0';
Z cput(p->mesglen+INPUTSTART, INPUTY, p, "%c", c);
Z }
Z }
Z
Z bflush(p);
Z}
Z
Zvoid
Zdonemsg(p)
Zregister t_player *p;
Z{
Z prompt(p, "");
Z p->mesgdst = 0;
Z p->mesglen = 0;
Z p->mesgbuf[0] = '\0';
Z bflush(p);
Z#ifdef DEBUG
Z errlog ("DONEMSG: after bflush.\n");
Z#endif DEBUG
Z}
STUNKYFLUFF
set `sum < cmds1.c`
if test 60355 != $1
then
echo cmds1.c: Error. number of characters is: $1, should be: 60355.
fi
#
#
echo x - cmds2.c
sed 's/^Z//' >cmds2.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: cmds2.c,v 2.2 85/08/06 22:29:33 matt Exp $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Greg Ordy 1979
Z * Rewrite by Sam Leffler 1981
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * more routines to execute player commands
Z *
Z * Copyright (c) 1979
Z *
Z * $Log: cmds2.c,v $
Z * Revision 2.2 85/08/06 22:29:33 matt
Z * Change handling of "r", "b", "g", "j", "q" commands to
Z * provide better feedback, using per-player message buffer.
Z *
Z * Revision 2.1 85/04/10 17:30:53 matt
Z * Major de-linting and minor restructuring.
Z *
Z */
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Zstatic int nukedir[9][4] = {
Z { 0,-1, 1, 0}, { -1, 0, 1, 0}, { -1, 0, 0,-1},
Z { 0,-1, 0, 1}, { 0, 0, 0, 0}, { 0,-1, 0, 1},
Z { 0, 1, 1, 0}, { -1, 0, 1, 0}, { -1, 0, 0, 1}
Z};
Z
Z/*
Z * Launch a nuke.
Z */
Zvoid
Znuke(p, c)
Zregister t_player *p;
Zchar c;
Z{
Z extern void launch();
Z register char x,
Z y;
Z char ox,
Z oy,
Z c1 = c;
Z
Z p->cmdpend = 0;
Z ox = p->offx;
Z oy = p->offy;
Z launch((thing *)p, c, PLAYER, ox, oy, 0, p->curx, p->cury, 10);
Z if(p->nkcnt-- <= 0) {
Z p->nkcnt = 0;
Z return;
Z }
Z c -= '1';
Z if (c < 0 || c > 8)
Z return;
Z x = nukedir[c][0] + p->curx;
Z y = nukedir[c][1] + p->cury;
Z launch((thing *)p, c1, PLAYER, ox, oy, 0, x, y, 8);
Z x = nukedir[c][2] + p->curx;
Z y = nukedir[c][3] + p->cury;
Z launch((thing *)p, c1, PLAYER, ox, oy, 1, x, y, 8);
Z}
Z
Z/*
Z * Send a radio message.
Z */
Zvoid
Zrmsg(p, letter)
Zregister t_player *p;
Zchar letter;
Z{
Z extern void pstatus(),
Z pmesg(),
Z echomsg(),
Z gathermsg(),
Z donemsg(),
Z makescab();
Z extern t_player player[NPLAYER];
Z register int i;
Z register t_player *pl;
Z
Z if (p->mesgdst == 0) {
Z if (letter >= 'a')
Z letter -= 'a';
Z else if (letter >= 'A')
Z letter -= 'A';
Z else
Z letter = NPLAYER;
Z if (letter < 0 || letter >= NPLAYER)
Z pmesg(p, "From radio room-- frequency jammed!");
Z else if (player[letter].status.alive == TRUE) {
Z p->mesgdst = letter+1;
Z gathermsg(p);
Z return;
Z } else
Z pstatus(p, "Inactive channel requested!");
Z p->cmdpend = 0;
Z p->mesgdst = 0;
Z return;
Z }
Z if (letter != '\n' && letter != '\r') {
Z if (letter == SCABLETTER) {
Z letter = '^';
Z makescab(p);
Z }
Z echomsg(p, letter);
Z } else {
Z pl = &player[p->mesgdst-1];
Z if (pl->status.alive != TRUE)
Z pmesg(p, "From radio room-- Too late! %c is dead!",
Z p->mesgdst-1+'A');
Z else {
Z pmesg(p, "From radio room -- Message sent!");
Z pmesg(pl, "Private from %s-- %s", p->plname, p->mesgbuf);
Z }
Z
Z p->cmdpend = 0;
Z donemsg(p);
Z }
Z}
Z
Z/*
Z * Change the magnification factor on the viewing port.
Z */
Zvoid
Zmagnif(p, power)
Zregister t_player *p;
Zchar power;
Z{
Z extern void pstatus(),
Z cput();
Z
Z p->cmdpend = 0;
Z if (power < '1' || power > MAXMAG) {
Z pstatus(p, "M-factor request out of range!");
Z return;
Z }
Z p->mflg = power-'0';
Z cput(MFDATA, p, "%c", power);
Z}
Z
Z/*
Z * Show current facts about a player.
Z */
Zvoid
Zfacts(p)
Zregister t_player *p;
Z{
Z extern void pstatus();
Z extern long ptime;
Z long rate;
Z
Z rate = ((long)p->points*100+(long)p->phits*100+
Z (long)p->pkills*1000)/(ptime-p->pltime);
Z pstatus(p, "hits: %dp %da kills: %d level: %d", p->phits,
Z p->ahits, p->pkills, rate);
Z}
Z
Z/*
Z * Exploit aliens living on quartone so that nukes may be
Z * fired.
Z */
Zvoid
Zxploit(p)
Zregister t_player *p;
Z{
Z extern void pmesg(),
Z makescab();
Z register int i;
Z
Z if(p->status.orb == FALSE) {
Z pmesg(p, "Must be in orbit around planet");
Z return;
Z }
Z if(p->status.invis == TRUE) {
Z pmesg(p, "Must be visible to exploit");
Z return;
Z }
Z if(p->nkcnt >= p->maxmaxe/20) {
Z pmesg(p, "Maximum modifications are complete");
Z return;
Z }
Z p->energy -= 20;
Z p->nkcnt++;
Z i = ((rand()>>4)%40)+60;
Z p->qkill += i;
Z pmesg(p, "Dead: %d total: %d", i, p->qkill);
Z /*
Z * ouch! if we kill more than 8000, make the player a scab!
Z */
Z if(p->qkill > 8000)
Z makescab(p);
Z}
STUNKYFLUFF
set `sum < cmds2.c`
if test 31405 != $1
then
echo cmds2.c: Error. number of characters is: $1, should be: 31405.
fi
#
#
echo x - excl.c
sed 's/^Z//' >excl.c <<\STUNKYFLUFF
Z#include <fcntl.h>
Z#include <stdio.h>
Z
Zexcl(str)
Zchar *str;
Z{
Z int fd, i;
Z struct flock flock;
Z
Z flock.l_type = F_WRLCK;
Z flock.l_start = 0;
Z flock.l_len = 0;
Z
Z if (!access(str,0)) return -1;
Z fd = open(str, O_CREAT|O_WRONLY, 0666);
Z if (fd < 0) return fd;
Z i = fcntl(fd, F_SETLK, &flock);
Z return i;
Z}
STUNKYFLUFF
set `sum < excl.c`
if test 24477 != $1
then
echo excl.c: Error. number of characters is: $1, should be: 24477.
fi
#
#
echo x - groups.c
sed 's/^Z//' >groups.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: groups.c,v 1.3 85/08/06 22:29:38 matt Exp $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Greg Ordy 1979
Z * Rewrite by Sam Leffler 1981
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines to execute player "team" commands l, q, j, g
Z *
Z * Copyright (c) 1979
Z *
Z * $Log: groups.c,v $
Z * Revision 1.3 85/08/06 22:29:38 matt
Z * Change handling of "r", "b", "g", "j", "q" commands to
Z * provide better feedback, using per-player message buffer.
Z *
Z */
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Z/*
Z * Look at your group's members.
Z */
Zvoid lookg(p)
Zregister t_player *p;
Z{
Z extern void cput(),
Z clearline(),
Z put();
Z extern t_player player[NPLAYER];
Z extern char visual[NPLAYER][NPLAYER];
Z register t_player *pl;
Z register int i;
Z
Z cput(MSDATA, p, "From security-- group = ");
Z clearline(p);
Z for (pl = player; pl < &player[NPLAYER]; pl++) {
Z if (pl->status.alive == FALSE)
Z continue;
Z if (visual[p-player][i = pl-player])
Z put(p, "%c ", i+'A');
Z }
Z}
Z
Z/*
Z * Join a group.
Z */
Zvoid joing(pl, person)
Zregister t_player *pl;
Zchar person;
Z{
Z extern t_player player[NPLAYER];
Z extern char visual[NPLAYER][NPLAYER];
Z register int i;
Z register t_player *p;
Z
Z if (person == '\n' || person == '\r') {
Z pl->cmdpend = 0;
Z prompt(pl, "");
Z return;
Z }
Z if (person >= 'a')
Z person -= 'a' - 'A';
Z for (p = player; p < &player[NPLAYER]; p++) {
Z if (p->status.alive == FALSE || p == pl)
Z continue;
Z if ((i = p-player) == person-'A') {
Z visual[pl-player][i] = 1;
Z return;
Z }
Z }
Z}
Z
Z/*
Z * Quit a group.
Z */
Zvoid quitg(pl, person)
Zregister t_player *pl;
Zchar person;
Z{
Z extern t_player player[NPLAYER];
Z extern char visual[NPLAYER][NPLAYER];
Z register int i,
Z j;
Z register t_player *p;
Z
Z if (person == '\n' || person == '\r') {
Z pl->cmdpend = 0;
Z prompt(pl, "");
Z return;
Z }
Z if (person == '.') {
Z j = pl-player;
Z for (i = 0; i < NPLAYER; i++)
Z visual[j][i] = 0;
Z pl->cmdpend = 0;
Z prompt(pl, "");
Z return;
Z }
Z if (person >= 'a')
Z person -= 'a' - 'A';
Z for (p = player; p < &player[NPLAYER]; p++) {
Z if (p->status.alive == FALSE || p == pl)
Z continue;
Z if ((i = p-player) == person-'A') {
Z visual[pl-player][i] = 0;
Z return;
Z }
Z }
Z}
Z
Z/*
Z * Send a group message.
Z */
Zvoid groupm(pl, c)
Zregister t_player *pl;
Zchar c;
Z{
Z extern void makescab(),
Z pmesg();
Z extern t_player player[NPLAYER];
Z extern char visual[NPLAYER][NPLAYER];
Z register t_player *p;
Z register int j;
Z char cc;
Z
Z if (c == '\n' || c == '\r') {
Z j = pl-player;
Z cc = j+'A';
Z for (p = player; p < &player[NPLAYER]; p++)
Z if (visual[j][p-player] && p->status.alive == TRUE) {
Z pmesg(p, "From %c-- %s", cc, pl->mesgbuf);
Z }
Z pl->cmdpend = 0;
Z donemsg(pl);
Z return;
Z }
Z if (c == SCABLETTER) { /* Benedict Arnold */
Z c = '^';
Z makescab(pl);
Z }
Z echomsg(pl, c);
Z}
STUNKYFLUFF
set `sum < groups.c`
if test 23411 != $1
then
echo groups.c: Error. number of characters is: $1, should be: 23411.
fi
#
#
echo x - init.c
sed 's/^Z//' >init.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: init.c,v 2.2 85/08/06 22:29:44 matt Exp $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Greg Ordy 1979
Z * Rewrite by Sam Leffler 1981
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines to initialize the search databases and to
Z * open needed files
Z *
Z * Copyright (c) 1979
Z *
Z * $Log: init.c,v $
Z * Revision 2.2 85/08/06 22:29:44 matt
Z * Change handling of "r", "b", "g", "j", "q" commands to
Z * provide better feedback, using per-player message buffer.
Z *
Z * Revision 2.1 85/04/10 17:31:03 matt
Z * Major de-linting and minor restructuring.
Z *
Z * Revision 1.2 85/02/11 12:43:47 matt
Z * added GUTS mode
Z */
Z
Z#include <fcntl.h>
Z#include <stdio.h>
Z#include <sys/types.h>
Z#include <sys/file.h>
Z#include <signal.h>
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Zstatic struct message message;
Zextern sock;
Z/*
Z * initialize all the databases for search
Z */
Z
Zvoid init() {
Z extern time_t time();
Z extern int trap(),
Z core_dump(),
Z srand(),
Z rand();
Z extern long lseek();
Z extern t_player player[NPLAYER];
Z extern t_alien alien[NALIEN];
Z extern t_sbase sbase[NBASE];
Z extern t_planet planet;
Z extern int pfd,
Z nplayer,
Z sfflag,
Z errfile,
Z sfcount;
Z extern char ppx,
Z ppy;
Z void initplayer();
Z register t_alien *pa;
Z register t_sbase *ps;
Z register int i;
Z time_t tvec;
Z char buf[100];
Z extern childdeath(), quit();
Z
Z (void) signal(SIGHUP, SIG_IGN);
Z (void) signal(SIGQUIT, SIG_DFL);
Z (void) signal(SIGINT, SIG_IGN);
Z (void) signal(SIGALRM, SIG_IGN);
Z (void) signal(SIGPIPE, SIG_IGN);
Z (void) signal(SIGTERM, quit);
Z (void) signal(SIGCLD, childdeath);
Z /*
Z * clear everything out
Z */
Z bzero((char *)player, sizeof(t_player) * NPLAYER);
Z pfd = open(POINTFILE, O_RDWR, 0);
Z if (pfd < 0) {
Z perror(POINTFILE);
Z exit(1);
Z }
Z /*
Z * no big deal if we can't open the error log
Z */
Z errfile = open(ERRLOG, O_RDWR|O_CREAT, 0666);
Z if (errfile >= 0) {
Z lseek(errfile, 0L, 2);
Z sprintf(buf, "starting daemon, pid %d\n", getpid());
Z errlog(buf);
Z }
Z tvec = time((time_t *)0);
Z srand(tvec);
Z nplayer = 0;
Z /*
Z * Setup aliens with random locations and random directions.
Z */
Z for (pa = alien; pa < &alien[NALIEN]; pa++) {
Z pa->cx = (rand()%80)+20;
Z pa->cy = (rand()%50)+25;
Z pa->cix = (rand()%3)-1;
Z pa->ciy = (rand()%3)-1;
Z if (pa->ciy == 0 && pa->cix == 0)
Z pa->cix = pa->ciy = 1;
Z pa->aname = NAMEAL;
Z pa->type = NORM;
Z }
Z /*
Z * Add in the shankers.
Z */
Z for (pa = alien; pa < &alien[NSHANK]; pa++) {
Z pa->type = SHANK;
Z pa->count = (rand()%30)+15; /* shanker alarm clock */
Z }
Z /*
Z * Some others are the wandering type.
Z */
Z for (; pa < &alien[NSHANK+NWAND]; pa++) {
Z pa->type = WANDER;
Z pa->aname = NAMEWD;
Z pa->count = (rand()%32)+16;
Z }
Z /*
Z * Star bases get random places also -- but spread out.
Z */
Z for (ps = sbase, i = 0; i != NBASE - 1; i++, ps++) {
Z ps->xpos = ((rand()%50)+(25*(i+1))%120)+3;
Z ps->ypos = ((rand()%50)+(25*(i+1))%120)+3;
Z }
Z /*
Z * Build quartone.
Z */
Z planet.planetname = "Quartone";
Z planet.places[0][0] = -((rand()%30)+30);
Z planet.places[0][1] = -((rand()%30)+30);
Z for (i = 0; i != 5; i++) {
Z planet.places[i][1] = planet.places[0][1];
Z planet.places[i][0] = planet.places[0][0]+i;
Z }
Z for (i = 5; i != 12; i++) {
Z planet.places[i][1] = planet.places[0][1]-1;
Z planet.places[i][0] = planet.places[0][0]+i-6;
Z }
Z for (i = 12; i != 17; i++) {
Z planet.places[i][1] = planet.places[0][1]-2;
Z planet.places[i][0] = planet.places[0][0]+i-12;
Z }
Z ppx = planet.places[8][0];
Z ppy = planet.places[8][1];
Z
Z sbase[NBASE-1].xpos = ppx-(rand()%20)-4;
Z sbase[NBASE-1].ypos = ppy-(rand()%20)-4;
Z /*
Z * Solar flare alarm clock....
Z */
Z sfcount = 800+(rand()%100);
Z sfflag = OFF;
Z}
Z
Zstruct initlist {
Z char x;
Z char y;
Z char *output;
Z} initlist[] = {
Z { XAXISTITLE, "--------------- ---------------" },
Z { POSTITLE, "POSITION" },
Z { EGYTITLE, "ENERGY" },
Z { HRTITLE, "HOMING RADAR" },
Z { H1TITLE, "1) " },
Z { H2TITLE, "2) " },
Z { H3TITLE, "3) " },
Z { PTTITLE, "POINTS" },
Z { STTITLE, "STATUS: " },
Z { MSTITLE, "MESSAGE: " },
Z { INTITLE, "INVISIBILTY" },
Z { VLTITLE, "VELOCITY" },
Z { TMTITLE, "TIME" },
Z { MFTITLE, "M-FACTOR" },
Z { PLTITLE, "----- PLAYER MAP ----" },
Z { 0, 0, 0 }
Z};
Z
Zvoid initplayer(p)
Zregister t_player *p;
Z{
Z extern void bflush(),
Z clear(),
Z cput(),
Z initpdisplay(),
Z pldisplay();
Z register int j;
Z register struct initlist *pi = initlist;
Z
Z p->eoq = p->outputq;
Z *p->eoq = NULL;
Z clear(p);
Z for (j = CENTY; j < XWIND; j++)
Z cput(YAXISTITLE, j, p, "|");
Z while (pi->x) {
Z cput(pi->x, pi->y, p, pi->output);
Z pi++;
Z }
Z cput(EGYDATA, p, "%d", p->energy);
Z cput(PTDATA, p, "%d", p->points);
Z cput(INDATA, p, p->status.invis == TRUE ? "on " : "off");
Z cput(MFDATA, p, "%c", p->mflg+'0');
Z initpdisplay(p);
Z pldisplay(p, "a");
Z p->plstp = 0;
Z bflush(p);
Z}
Z
Z/*
Z * initializes player stuff
Z */
Zt_player *startup(fileform)
Zt_file *fileform;
Z{
Z extern void makescab();
Z extern char *strncpy();
Z extern t_player player[NPLAYER];
Z extern char ppx, ppy;
Z extern long ptime;
Z extern int gutsflag;
Z register t_player *p;
Z
Z for (p = player; p < &player[NPLAYER]; p++)
Z if (p->status.alive == FALSE)
Z break;
Z /*
Z * too many players in the game.
Z */
Z if (p >= &player[NPLAYER]) {
Z message.mtype = fileform->uid+1;
Z message.text[0] = 0;
Z msgsnd(sock, &message, 4+4+1, 0);
Z return(NULL);
Z }
Z /*
Z * clear out everything.
Z */
Z bzero((char *)p, sizeof(*p));
Z if (!ioinit (p, fileform)) {
Z p->status.alive = FALSE;
Z errlog("STARTUP: ioinit failed.\n");
Z return (NULL);
Z }
Z p->status.alive = TRUE;
Z p->status.begin = TRUE;
Z p->status.guts = gutsflag;
Z p->curx = ppx+(rand()%10)+5;
Z p->cury = ppy+(rand()%10)+5;
Z p->mflg = 1;
Z p->pltime = ptime;
Z p->maxmaxe = p->maxe = p->energy = 250;
Z p->uid = fileform->uid;
Z (void) strncpy(p->plname, fileform->p_name, sizeof(p->plname)-1);
Z return(p);
Z}
Z
Zbzero(p, n)
Zregister char *p;
Zregister n;
Z{
Z while (n--) *p++ = 0;
Z}
Z
Zchilddeath() {
Z signal(SIGCLD, childdeath);
Z
Z errlog("My child died!\n");
Z errlog("Return status = %d\n", wait(0));
Z}
Z
Zquit() {
Z register t_player *p;
Z FILE *f = fopen("/usr/src/local/search/lib/apa", "w");
Z fprintf(f, "Got a quit signal\n"); fflush(f);
Z errlog("Got a quit signal\n");
Z for (p = player; p < &player[NPLAYER]; p++) {
Z if (p->status.alive == FALSE) continue;
Z fprintf(f, "name: %s, uid %d, energy %d\n",
Z p->plname, p->uid, p->energy); fflush(f);
Z errlog("name: %s, uid %d, energy %d\n",
Z p->plname, p->uid, p->energy);
Z fprintf(f, " outputchars:\n%s\n", p->outputq); fflush(f);
Z errlog(" outputchars:\n%s\n", p->outputq);
Z }
Z fclose(f);
Z core_dump();
Z}
STUNKYFLUFF
set `sum < init.c`
if test 41738 != $1
then
echo init.c: Error. number of characters is: $1, should be: 41738.
fi
#
#
echo x - io.c
sed 's/^Z//' >io.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: io.c,v 2.1 85/04/10 17:31:07 matt Stab $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Sam Leffler 1981
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines for termcap interface and general i/o support
Z * Changes were made to the original code to minimize
Z * the total number of "write" calls to the sockets
Z * (an attempt to increase performance)
Z *
Z * Copyright (c) 1981
Z *
Z */
Z
Z#include <sys/types.h>
Z#include <sys/ipc.h>
Z#include <sys/msg.h>
Z#include "defines.h"
Z#include "structs.h"
Z
Zextern int sock;
Zstatic struct message message;
Z
Z/*
Z * Goto <x, y> on who's terminal and put
Z */
Z/*VARARGS3*/
Zvoid cput(x, y, p, args)
Zint x, y;
Zt_player *p;
Zint args;
Z{
Z char *print();
Z register char *bp;
Z register char *qp;
Z register c;
Z
Z move(x, y, p);
Z bp = print(&args);
Z for (qp=p->eoq; c = *bp; bp++) {
Z *qp = c;
Z qp++;
Z }
Z *qp = NULL;
Z p->eoq = qp;
Z}
Z
Z/*
Z * clear screen
Z */
Zvoid clear(p)
Zt_player *p;
Z{
Z register char *bp;
Z register char *qp;
Z register c;
Z
Z bp = p->CL;
Z for (qp=p->eoq; c = *bp; bp++) {
Z *qp = c;
Z qp++;
Z }
Z *qp = NULL;
Z p->eoq = qp;
Z}
Z
Z
Z/*
Z * move to <x, y>
Z */
Zmove(x, y, p)
Zint x;
Zint y;
Zt_player *p;
Z{
Z extern char *tgoto();
Z register char *bp;
Z register char *qp;
Z register c;
Z
Z bp = tgoto(p, x, y);
Z for (qp=p->eoq; c = *bp; bp++) {
Z *qp = c;
Z qp++;
Z }
Z *qp = NULL;
Z p->eoq = qp;
Z}
Z
Z/*
Z * Do the put, but make sure it occupies the entire line -- for
Z * status and message lines
Z */
Zvoid /*VARARGS1*/
Zputblank(p, args)
Zregister t_player *p;
Zint *args;
Z{
Z char *print();
Z register char *bp;
Z register int n;
Z register char *qp;
Z register c;
Z
Z qp = p->eoq;
Z if (p->CE) { /* cheat clear out line first */
Z bp = p->CE;
Z for (qp=p->eoq; c = *bp; bp++) {
Z *qp = c;
Z qp++;
Z }
Z *qp = NULL;
Z p->eoq = qp;
Z bp = print(args);
Z } else { /* have to overwrite line, then clear out remainder */
Z bp = print(args);
Z n = strlen(bp);
Z while (n++ < 40) /* kludge for now */
Z bp[n] = ' ';
Z bp[40] = NULL;
Z }
Z for (qp=p->eoq; c = *bp; bp++) {
Z *qp = c;
Z qp++;
Z }
Z *qp = NULL;
Z p->eoq = qp;
Z}
Z
Z/*
Z * Print something on the message line
Z */
Z/*VARARGS1*/
Zvoid pmesg(p, args)
Zt_player *p;
Zint args;
Z{
Z move(MSDATAX, MSDATAY, p);
Z putblank(p, &args);
Z}
Z
Z
Z/*
Z * Drop something on the prompt line
Z */
Z/*VARARGS1*/
Zvoid prompt(p, s)
Zt_player *p;
Zchar *s;
Z{
Z move(PROMPTX, PROMPTY, p);
Z putblank(p, &s);
Z}
Z
Z/*
Z * Print something on the status line
Z */
Z/*VARARGS1*/
Zvoid pstatus(p, args)
Zt_player *p;
Zint args;
Z{
Z move(STDATAX, STDATAY, p);
Z putblank(p, &args);
Z}
Z
Z/*
Z * Clear out the rest of the line from where the cursor is
Z * presently located -- easy if CE exists on this terminal
Z */
Zvoid clearline(p)
Zregister t_player *p;
Z{
Z register char *bp;
Z register char *qp;
Z register c;
Z
Z bp = p->CE;
Z if (bp == NULL)
Z return;
Z for (qp=p->eoq; c = *bp; bp++) {
Z *qp = c;
Z qp++;
Z }
Z *qp = NULL;
Z p->eoq = qp;
Z}
Z
Z
Z/*
Z * Print write around
Z */
Z/*VARARGS1*/
Zvoid put(p, args)
Zt_player *p;
Zint args;
Z{
Z char *print();
Z register char *bp;
Z register char *qp;
Z register c;
Z
Z bp = print(&args);
Z for (qp=p->eoq; c = *bp; bp++) {
Z *qp = c;
Z qp++;
Z }
Z *qp = NULL;
Z p->eoq = qp;
Z}
Z
Z
Zstatic char printbuf[80];
Zstatic char *bufp;
Z
Z/*
Z * Guts of the I/O...a hacked printf-like beast?
Z */
Zstatic char *print(parg)
Zregister int *parg; /* should be a union, or something */
Z{
Z void printn();
Z register char *fmt = (char *)(*parg++);
Z register c;
Z register char *bp;
Z
Z bufp = printbuf;
Z while (c = *fmt++) {
Z if (c == '%') switch(c = *fmt++) {
Z case 'd': /* decimal */
Z printn(*parg++, 10, 4);
Z continue;
Z case 'c': /* character */
Z *bufp++ = (char)(*parg++);
Z continue;
Z case 's': /* string */
Z bp = (char *)(*parg++);
Z for ( ; c = *bp; bp++) {
Z *bufp = c;
Z bufp++;
Z }
Z continue;
Z case '%':
Z *bufp++ = '%';
Z continue;
Z default:
Z *bufp++ = '%';
Z }
Z *bufp++ = c;
Z }
Z *bufp = NULL;
Z return printbuf;
Z}
Z
Z
Z/*
Z * Handle number conversions...everything takes up "width" spaces
Z */
Zstatic void printn(n, base, width)
Zregister int n, base;
Zint width;
Z{
Z void putn();
Z char *before;
Z
Z before = bufp;
Z if (base == 10 && n < 0) {
Z *bufp++ = '-';
Z n = abs(n);
Z } else
Z *bufp++ = ' ';
Z if (n == 0)
Z *bufp++ = '0';
Z else
Z putn(n, base);
Z n = bufp - before;
Z while (n++ < width)
Z *bufp++ = ' ';
Z}
Z
Z
Z/*
Z * Recursive number constructor
Z */
Zstatic void putn(n, b)
Zregister int n, b;
Z{
Z if (n == 0)
Z return;
Z putn(n/b, b);
Z *bufp++ = "0123456789abcdef"[n%b];
Z}
Z
Z
Z/*
Z * Flush the output buffer to "p"s terminal
Z */
Zvoid bflush(p)
Zregister t_player *p;
Z{
Z int i;
Z
Z i = strlen(p->outputq);
Z if (i == 0) return;
Z message.mtype = p->uid+1;
Z strcpy(message.text, p->outputq);
Z msgsnd(sock, &message, i+8, 0);
Z p->eoq = p->outputq;
Z *p->eoq = NULL;
Z}
Z
Z
Z/*
Z * Set up the termcap stuff in the player structure
Z */
Zint ioinit(p, pf)
Zregister t_player *p;
Zregister t_file *pf;
Z{
Z extern char *malloc();
Z char *copy();
Z register unsigned nalloc;
Z register char *cp;
Z
Z nalloc = strlen(pf->p_BC)+strlen(pf->p_UP)+ strlen(pf->p_CM)+
Z strlen(pf->p_CL)+strlen(pf->p_CE)+5;
Z nalloc += nalloc % 2;
Z if ((cp = malloc(nalloc)) == (char *)-1)
Z return(0);
Z p->BC = cp;
Z p->UP = cp = copy(cp, pf->p_BC);
Z p->CM = cp = copy(cp, pf->p_UP);
Z p->CL = cp = copy(cp, pf->p_CM);
Z p->CE = cp = copy(cp, pf->p_CL);
Z (void)copy(cp, pf->p_CE);
Z p->ttyspeed = pf->p_speed;
Z return(1);
Z}
Z
Zstatic char *
Zcopy(s1, s2)
Zregister char *s1, *s2;
Z{
Z while (*s1++ = *s2++);
Z return s1;
Z}
STUNKYFLUFF
set `sum < io.c`
if test 21015 != $1
then
echo io.c: Error. number of characters is: $1, should be: 21015.
fi
#
#
echo x - ipc.c
sed 's/^Z//' >ipc.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: ipc.c,v 2.1 85/04/10 17:31:13 matt Stab $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Dave Pare 1984
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines to initialize and watch the communications sockets
Z * for new players, "searchwho" and "sdata" requests.
Z *
Z * Copyright (c) 1984
Z *
Z * $Log: ipc.c,v $
Z * Revision 2.1 85/04/10 17:31:13 matt
Z * Major de-linting and minor restructuring.
Z *
Z * Revision 1.6 85/02/24 22:50:47 matt
Z * Make the select() polls into real polls by setting the timeouts
Z * to zero. This cuts down on context switches and speeds the game
Z * up IMMENSELY!
Z *
Z * Revision 1.5 85/02/11 14:59:28 matt
Z * Tell searchwho that game is in GUTS mode
Z *
Z * Revision 1.4 85/02/09 23:48:52 matt
Z * Eliminated the dependence on the value of the mask after
Z * select() times out. Use the return value to distinguish
Z * a timeout!!
Z *
Z * Revision 1.3 84/07/08 17:03:41 matt
Z * Added Log
Z *
Z * Revision 1.2 84/07/07 18:20:50 matt
Z * Put new->p_speed into host byte order after reading from client
Z */
Z
Z#include <stdio.h>
Z#include <sys/types.h>
Z#include <sys/file.h>
Z#include <time.h>
Z#include <sys/ipc.h>
Z#include <sys/msg.h>
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Zstatic struct message message;
Zextern int sock;
Z
Z/*
Z * newplayer checks to see if there is a new player waiting
Z * on one of the communication sockets. If there is some input
Z * waiting, newplayer() checks to see if it's a request from
Z * "searchwho", or if it's an actual player requesting to
Z * enter the game.
Z *
Z * newplayer() returns the new player, or a NULL if no new player
Z * was found.
Z */
Z
Zt_player *newplayer(mask)
Zint mask;
Z{
Z extern void core_dump();
Z extern char *strcpy();
Z extern t_player *startup();
Z extern t_player player[NPLAYER];
Z extern int errno,
Z nobody,
Z gutsflag;
Z extern struct timeval tim_inp;
Z register t_player *p, *np;
Z t_file *new;
Z long lbuf[1024]; /* Try to force alignment */
Z char *buf = (char *)lbuf;
Z int nfds,
Z namelen,
Z i;
Z
Z i = msgrcv(sock, &message, sizeof message, 1, mask ? 0 : IPC_NOWAIT);
Z#ifdef NOTDEF
Z if ( i != -1 ) { /* Special Request */
Z switch ( *buf ) {
Z case 'w': /* "who's playing search?" */
Z buf[0] = NULL;
Z for (p=player; p < &player[NPLAYER]; p++) {
Z if (p->status.alive == FALSE)
Z continue;
Z if (*buf == NULL)
Z sprintf(buf, "%s player points\n",
Z gutsflag?"*game in GUTS mode*\n":"");
Z sprintf(buf,"%s\n%-16s %-5d", buf,
Z p->plname,p->points);
Z }
Z if (buf[0] == NULL) {
Z (void)strcpy(buf, "nobody playing");
Z nobody++;
Z }
Z write(newsock, buf, strlen(buf));
Z errlog("searchwho request\n");
Z break;
Z case '#': /* "dump the player list" (top secret) */
Z for (p=player; p < &player[NPLAYER]; p++)
Z if (p->status.alive == TRUE)
Z write(newsock, (char *)p,
Z sizeof(t_player));
Z errlog("sdata request\n");
Z break;
Z default: /* garbage! */
Z write(newsock, "What?\n", 6);
Z errlog("garbage request\n");
Z break;
Z }
Z shutdown(newsock, 2);
Z close(newsock);
Z return 0;
Z } else
Z#endif NOTDEF
Z if (i == -1) return 0;
Z new = (t_file *)message.text;
Z new->uid = message.ident;
Z if ((np = startup(new)) == NULL) {
Z errlog("startup returned NULL in newplayer()\n");
Z return 0;
Z }
Z return np;
Z}
Z
Z
Z/*
Z * initsocks initializes the two "new player" communications
Z * sockets. It returns 1 if everything is ok, and 0 if not.
Z * Argument is passed in host byte order.
Z */
Z
Zint initsocks()
Z{
Z int i;
Z
Z /*
Z * bind and listen at the local socket "/tmp/slock"
Z */
Z if (access("/tmp/SEARCH", 0)) {
Z printf("File doesn't exists: /tmp/SEARCH\n");
Z return 0;
Z }
Z sock = getid();
Z if (sock == -1) {
Z perror("initsockets: got none");
Z return 0;
Z }
Z return 1;
Z}
Z
Zgetid()
Z{
Z int key = ftok("/tmp/SEARCH", 0);
Z if (key == -1) return -1;
Z return msgget(key, IPC_CREAT|IPC_EXCL|0777);
Z}
Z
Z/*
Z * read input from the socket
Z *
Z */
Z
Zint pinput(p)
Zregister t_player *p;
Z{
Z extern int errlog();
Z extern void done();
Z extern int errno;
Z register int i = 0;
Z int nfds;
Z
Z /*
Z * poll the socket for input
Z */
Z nfds = msgrcv(sock, &message, sizeof message, p->uid, IPC_NOWAIT);
Z if (nfds < 0) {
Z return 0;
Z }
Z i = strlen(message.text);
Z strncpy (p->inputq, message.text, QSIZE);
Z
Z /*
Z * If player request to die -- clean up after him.
Z */
Z if (i == 0) {
Z errlog("PINPUT: Player died the hard way\n");
Z done(p);
Z return -1;
Z }
Z
Z /*
Z * Make an acknowledge on this message.
Z */
Z message.mtype = p->uid + 2;
Z message.text[0] = 1; message.text[1] = 0;
Z if (msgsnd(sock, &message, 8+1, 0) == -1)
Z errlog("PINPUT: Msgsnd returned -1.\n");
Z
Z p->ninput = i;
Z p->pinputq = p->inputq;
Z return i;
Z}
STUNKYFLUFF
set `sum < ipc.c`
if test 40548 != $1
then
echo ipc.c: Error. number of characters is: $1, should be: 40548.
fi
#
#
echo x - lists.c
sed 's/^Z//' >lists.c <<\STUNKYFLUFF
Z#ifndef lint
Zstatic char rcsid[] = "$Header: lists.c,v 2.1 85/04/10 17:31:19 matt Stab $";
Z#endif
Z/*
Z *
Z * search
Z *
Z * multi-player and multi-system search and destroy.
Z *
Z * Original by Greg Ordy 1979
Z * Socket code by Dave Pare 1983
Z * Ported & improved
Z * by Matt Crawford 1985
Z *
Z * routines to maintain linked lists that describe what a
Z * player is currently seeing on his viewscreen
Z *
Z * Copyright (c) 1979
Z *
Z * $Log: lists.c,v $
Z * Revision 2.1 85/04/10 17:31:19 matt
Z * Major de-linting and minor restructuring.
Z *
Z * Revision 1.3 84/07/08 17:04:00 matt
Z * Added Log
Z *
Z * Revision 1.2 84/07/08 16:46:28 matt
Z * Rplaced the struct hack *pnt with the short key. The "hack" was
Z * not portable to the Sun!
Z */
Z
Z#include "defines.h"
Z#include "structs.h"
Z
Z
Zvoid enteritem(x, y, xchar)
Zchar x, y, xchar;
Z{
Z extern t_player *wholist;
Z struct plist *gnode();
Z register struct plist *xp = wholist->plstp;
Z register int glob = x | (y<<8);
Z register int *pdp = (int *) &wholist->plstp;
Z struct plist *cp;
Z short key;
Z
Z while (xp != 0) {
Z key = (xp->zx) | (xp->zy << 8);
Z if (key < glob) {
Z pdp = (int *) &xp->zpnt;
Z xp = xp->zpnt;
Z continue;
Z }
Z if (key == glob) {
Z if (xp->zflg == 1)
Z return;
Z xp->zflg = 1;
Z if (xchar == xp->zchar)
Z return;
Z xp->zchar = xchar;
Z move(x+CENTX, y, wholist); /* macro */
Z *wholist->eoq++ = xchar;
Z *wholist->eoq = NULL;
Z return;
Z }
Z if (key > glob) {
Z *pdp = (int) gnode(x, y, xchar);
Z move(x+CENTX, y, wholist);
Z *wholist->eoq++ = xchar;
Z *wholist->eoq = NULL;
Z cp = (struct plist *) *pdp;
Z cp->zpnt = xp;
Z return;
Z }
Z }
Z *pdp = (int) gnode(x, y, xchar);
Z move(x+CENTX, y, wholist);
Z *wholist->eoq++ = xchar;
Z *wholist->eoq = NULL;
Z}
Z
Zvoid uplst() {
Z extern void fnode();
Z extern t_player *wholist;
Z register struct plist *xp;
Z register int *pdp;
Z register char x, y;
Z struct plist *cp;
Z char c;
Z
Z xp = wholist->plstp;
Z pdp = (int *) &wholist->plstp;
Z while (xp != 0) {
Z x = xp->zx;
Z y = xp->zy;
Z cp = xp->zpnt;
Z switch (xp->zflg) {
Z case 0:
Z move(x+CENTX, y, wholist);
Z c = x == XWIND && y != YWIND ? '|' :
Z x != XWIND && y == YWIND ? '-' : ' ';
Z *wholist->eoq++ = c;
Z *wholist->eoq = NULL;
Z xp->zpnt = 0;
Z fnode (xp);
Z xp = cp;
Z *pdp = (int) cp;
Z break;
Z case 1:
Z xp->zflg = 0;
Z pdp = (int *) &xp->zpnt;
Z xp = cp;
Z break;
Z default:
Z errlog("bad arg to uplst");
Z xp->zflg = 0;
Z pdp = (int *) &xp->zpnt;
Z xp = cp;
Z break;
Z }
Z }
Z}
Z
Zstruct plist *gnode(x, y, c)
Zchar x, y, c;
Z{
Z extern core_dump();
Z extern char *malloc();
Z extern struct plist *avl;
Z extern int numbnode;
Z register struct plist *px,
Z *qx;
Z register int i;
Z
Z if (avl == 0) {
Z if ((avl = (struct plist *) malloc(100*sizeof(*avl))) == (struct plist *)-1) {
Z errlog("out of memory in gnode()\n");
Z (void)core_dump();
Z }
Z qx = avl;
Z px = &avl[1];
Z for (i=0; i<99; i++)
Z (qx++)->zpnt = px++;
Z qx->zpnt = 0;
Z }
Z px = avl;
Z avl = avl->zpnt;
Z px->zx = x;
Z px->zy = y;
Z px->zchar = c;
Z px->zflg = 1;
Z px->zpnt = 0;
Z numbnode++;
Z return (px);
Z}
Z
Z/*
Z * free the screen nodes up.
Z */
Zvoid fnode (px)
Zregister struct plist *px;
Z{
Z extern int numbnode;
Z extern struct plist *avl;
Z register struct plist *qx = px;
Z
Z if (px == 0)
Z return;
Z while (px->zpnt) {
Z px = px->zpnt;
Z numbnode--;
Z }
Z numbnode--;
Z px->zpnt = avl;
Z avl = qx;
Z}
STUNKYFLUFF
set `sum < lists.c`
if test 52824 != $1
then
echo lists.c: Error. number of characters is: $1, should be: 52824.
fi
#
#
echo x - lookipc.c
sed 's/^Z//' >lookipc.c <<\STUNKYFLUFF
Z#include <sys/types.h>
Z#include <sys/ipc.h>
Z#include <sys/msg.h>
Z#include "defines.h"
Z#include "structs.h"
Z
Zstruct message message;
Z
Zmain(argc, argv)
Z char *argv[];
Z{
Z int key, id, i, stat;
Z
Z if (argc == 2)
Z key = atoi (argv[1]);
Z else if ((key = ftok("/tmp/SEARCH")) == -1) {
Z perror("/tmp/SEARCH");
Z exit(1);
Z }
Z printf("Key: 0x%x\n", key);
Z if ((id = msgget(key, 0)) == -1) {
Z perror("msgget");
Z exit(1);
Z }
Z printf("id: %d\n", id);
Z
Z for (i=0;; i++) {
Z message.mtype = 0;
Z if ((stat = msgrcv(id, &message, sizeof message, 0, IPC_NOWAIT)) == -1) {
Z printf ("msgrcv failed\n");
Z exit(1);
Z }
Z printf("Msg#%d: typ=%d, id=%d, len=%d, ret=%d, str='%s'\n",
Z i, message.mtype, message.ident, strlen(message.text), stat,
Z message.text);
Z }
Z}
STUNKYFLUFF
set `sum < lookipc.c`
if test 56862 != $1
then
echo lookipc.c: Error. number of characters is: $1, should be: 56862.
fi
echo All done
exit 0
--
______________________________________________________
Lars Pensjo
{decvax,philabs}!mcvax!enea!chalmers!myab!larsssl@ptsfa.UUCP (Sam Lok) (03/20/86)
Hello! Does anybody get part 1 of search? If so, plx send me a copy!
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Sam Lok {ihnp4,dual,qantel}!ptsfa!ssltwb@mhuxh.UUCP (twb) (03/25/86)
I also need a copy - This seems to have gotten lost at ihnp4.
Can someone re-insert it in to the stream from there?
(and not from across the Atlantic)
At least send me a copy at:
Tom.
..{decvax | ucbvax}!ihnp4!hoqax!twbelw@netexa.UUCP (E. L. Wiles) (03/25/86)
> > Hello! Does anybody get part 1 of search? If so, plx send me a copy! > DITTO!!!! We missed it too! E. L. Wiles @ NetExpress Comm. Inc, Virginia