matt@oddjob.UUCP (Matt Crawford) (08/11/85)
: This is a shar archive. Extract with sh, not csh. echo x - playmap.c sed -e 's/^X//' > playmap.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: playmap.c,v 2.2 85/04/10 22:53:20 matt Exp $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original by Sam Leffler 1981 X * Socket code by Dave Pare 1983 X * Ported & improved X * by Matt Crawford 1985 X * X * routines to manipulate the player map X * X * Copyright (c) 1981 X * X */ X X#include "defines.h" X#include "structs.h" X X/* X * Screen locations for the players map fields -- if you make X * NPLAYER > 16, you'd better change this. X */ Xstatic struct statcoords { X char s_x; X char s_y; X} scoord[] = { X {0, 20}, {20, 20}, {40, 20}, {60, 20}, X {0, 21}, {20, 21}, {40, 21}, {60, 21}, X {0, 22}, {20, 22}, {40, 22}, {60, 22}, X {0, 23}, {20, 23}, {40, 23}, {60, 23}, X}; X X/* X * Update the status of a player on everyone else's screen. X */ Xvoid pldisplay(pl, status) Xregister t_player *pl; Xchar *status; X{ X extern void cput(); X extern t_player player[NPLAYER]; X register t_player *p; X register struct statcoords *pcoord = &scoord[pl-player]; X X for (p = player; p < &player[NPLAYER]; p++) { X if (p->status.alive == FALSE || p == pl) X continue; X if (pl->status.begin == TRUE) { X cput(pcoord->s_x, pcoord->s_y, p, "%c[%s]%s ", X (pl-player)+'A', status, pl->plname); X } else X cput(pcoord->s_x+2, pcoord->s_y, p, status); X } X pl->status.begin = FALSE; X} X X/* X * Set up the player map for an entering player X */ Xvoid initpdisplay(pl) Xregister t_player *pl; X{ X extern void cput(); X extern t_player player[NPLAYER]; X char what; X register t_player *p; X register struct statcoords *pcoord; X X for (p = player; p < &player[NPLAYER]; p++) { X if (*p->plname == NULL || p->status.alive == FALSE) X continue; X pcoord = &scoord[p-player]; X if (p->status.alive == FALSE) { X if (p->status.killed == TRUE) X what = 'd'; X else X what = 'q'; X } X else X what = 'a'; X cput(pcoord->s_x, pcoord->s_y, pl, "%c[%c]: %s", X (p-player)+'A', what, p->plname); X } X} !xxENDITxx! echo x - scab.c sed -e 's/^X//' > scab.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: scab.c,v 2.1 85/04/10 17:31:37 matt Stab $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original by Greg Ordy 1979 X * Rewrite by Sam Leffler 1981 X * Socket code by Dave Pare 1983 X * Ported & improved X * by Matt Crawford 1985 X * X * routines that handle scabs - players deserving of X * "special" attention. X * X * Copyright (c) 1979 X * X */ X X#include "defines.h" X#include "structs.h" X X Xvoid makescab(p) Xregister t_player *p; X{ X extern t_alien alien[NALIEN]; X extern t_player *whoscab; X void enterscab(); X register t_alien *pa; X X p->scabcount++; X if (p->scabcount > 2) X enterscab(p); X for (pa = alien; pa < &alien[NALIEN]; pa++) { X if (pa->type != SHANK) X continue; X pa->aname = NAMESH; X pa->whotoget = (thing *)p; X } X whoscab = p; X} X Xvoid seescab(p) Xregister t_player *p; X{ X extern t_player *whoscab; X extern void pstatus(); X X if (whoscab == NOBODY) X pstatus(p, "Currently no SCAB."); X else X pstatus(p, "Current SCAB-- %s", p->plname); X} X Xstatic void enterscab(p) Xregister t_player *p; X{} !xxENDITxx! echo x - signal.c sed -e 's/^X//' > signal.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: signal.c,v 2.1 85/04/10 17:32:00 matt Stab $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original code by Dave Pare 1984 X * Ported & improved X * by Matt Crawford 1985 X * X * signal handlers for the daemon X * X * Copyright (c) 1984 X * X * $Log: signal.c,v $ X * Revision 2.1 85/04/10 17:32:00 matt X * Major de-linting and minor restructuring. X * X */ X X#include "defines.h" X#include "structs.h" X#include <stdio.h> X#include <sys/time.h> X#include <sys/file.h> X#include <signal.h> X#include <nlist.h> X X Xtrap(sig) Xint sig; X{ X extern void done(); X extern t_player player[NPLAYER]; X extern int loc_sock; X extern int pfd; X extern int errfile; X#ifdef INET X extern int in_sock; X#endif X t_player *p; X char buf[80]; X X X#ifdef INET X close(in_sock); X#endif X close(loc_sock); X for (p = player; p < &player[NPLAYER]; p++) X if (p->status.alive == TRUE) X done(p); X close(pfd); X unlink(SLOCK); X sprintf(buf, "trapped interrupt %d\n", sig); X errlog(buf); X close(errfile); X exit(sig); X /*NOTREACHED*/ X} X Xcore_dump() X{ X extern void done(); X extern t_player player[NPLAYER]; X t_player *p; X X errlog("dumping core...\n"); X signal(SIGQUIT, SIG_IGN); X for (p = player; p < &player[NPLAYER]; p++) X if (p->status.alive == TRUE) X done(p); X signal(SIGQUIT, SIG_DFL); X kill(getpid(), SIGQUIT); X /*NOTREACHED*/ X} X X X/* X * put the delay in the game. tune to taste. X */ Xvoid Xset_delay() { X extern int nplayer; X struct timeval timer; X long usecs; X X X usecs = 100000L - (nplayer * 15000L); X if (usecs < 10000L) X return; X timer.tv_sec = 0L; X timer.tv_usec = usecs; X (void)select(0, NULLINT, NULLINT, NULLINT, &timer); X /* if it fails, who cares? */ X} !xxENDITxx! echo x - groups.c sed -e 's/^X//' > groups.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: groups.c,v 1.3 85/08/06 22:29:38 matt Exp $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original by Greg Ordy 1979 X * Rewrite by Sam Leffler 1981 X * Socket code by Dave Pare 1983 X * Ported & improved X * by Matt Crawford 1985 X * X * routines to execute player "team" commands l, q, j, g X * X * Copyright (c) 1979 X * X * $Log: groups.c,v $ X * Revision 1.3 85/08/06 22:29:38 matt X * Change handling of "r", "b", "g", "j", "q" commands to X * provide better feedback, using per-player message buffer. X * X */ X X#include "defines.h" X#include "structs.h" X X/* X * Look at your group's members. X */ Xvoid lookg(p) Xregister t_player *p; X{ X extern void cput(), X clearline(), X put(); X extern t_player player[NPLAYER]; X extern char visual[NPLAYER][NPLAYER]; X register t_player *pl; X register int i; X X cput(MSDATA, p, "From security-- group = "); X clearline(p); X for (pl = player; pl < &player[NPLAYER]; pl++) { X if (pl->status.alive == FALSE) X continue; X if (visual[p-player][i = pl-player]) X put(p, "%c ", i+'A'); X } X} X X/* X * Join a group. X */ Xvoid joing(pl, person) Xregister t_player *pl; Xchar person; X{ X extern t_player player[NPLAYER]; X extern char visual[NPLAYER][NPLAYER]; X register int i; X register t_player *p; X X if (person == '\n' || person == '\r') { X pl->cmdpend = 0; X prompt(pl, ""); X return; X } X if (person >= 'a') X person -= 'a' - 'A'; X for (p = player; p < &player[NPLAYER]; p++) { X if (p->status.alive == FALSE || p == pl) X continue; X if ((i = p-player) == person-'A') { X visual[pl-player][i] = 1; X return; X } X } X} X X/* X * Quit a group. X */ Xvoid quitg(pl, person) Xregister t_player *pl; Xchar person; X{ X extern t_player player[NPLAYER]; X extern char visual[NPLAYER][NPLAYER]; X register int i, X j; X register t_player *p; X X if (person == '\n' || person == '\r') { X pl->cmdpend = 0; X prompt(pl, ""); X return; X } X if (person == '.') { X j = pl-player; X for (i = 0; i < NPLAYER; i++) X visual[j][i] = 0; X pl->cmdpend = 0; X prompt(pl, ""); X return; X } X if (person >= 'a') X person -= 'a' - 'A'; X for (p = player; p < &player[NPLAYER]; p++) { X if (p->status.alive == FALSE || p == pl) X continue; X if ((i = p-player) == person-'A') { X visual[pl-player][i] = 0; X return; X } X } X} X X/* X * Send a group message. X */ Xvoid groupm(pl, c) Xregister t_player *pl; Xchar c; X{ X extern void makescab(), X pmesg(); X extern t_player player[NPLAYER]; X extern char visual[NPLAYER][NPLAYER]; X register t_player *p; X register int j; X char cc; X X if (c == '\n' || c == '\r') { X j = pl-player; X cc = j+'A'; X for (p = player; p < &player[NPLAYER]; p++) X if (visual[j][p-player] && p->status.alive == TRUE) { X pmesg(p, "From %c-- %s", cc, pl->mesgbuf); X } X pl->cmdpend = 0; X donemsg(pl); X return; X } X if (c == SCABLETTER) { /* Benedict Arnold */ X c = '^'; X makescab(pl); X } X echomsg(pl, c); X} !xxENDITxx! echo x - planet.c sed -e 's/^X//' > planet.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: planet.c,v 1.3 85/07/08 17:22:52 matt Exp $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original by Greg Ordy 1979 X * Rewrite by Sam Leffler 1981 X * Socket code by Dave Pare 1983 X * Ported & improved X * by Matt Crawford 1985 X * X * routines to manipulate orbiting of the planet X * X * Copyright (c) 1979 X * X * $Log: planet.c,v $ X * Revision 1.3 85/07/08 17:22:52 matt X * prepare for preliminary distribution X * X * Revision 1.2 85/02/10 19:19:24 matt X * Added more realistic orbiting. X * X */ X X#include "defines.h" X#include "structs.h" X X/* orbit increments, indexed by the 0070 (CW) */ X/* or 0007 (CCW) bits of an oentry[] element */ X Xstatic char omods[8][2] = { X { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, /* E, SE, S, SW */ X {-1, 0}, {-1,-1}, { 0,-1}, { 1,-1} /* W, NW, N, NE */ X}; X X/* p->ocnt will be set odd for CCW orbits and always incremented by 2 */ X X#define ORB_INCR(N) omods[( (p->ocnt&1) ? (N) : (N)>>3 )&0007] X X#define CAN_ENTER_HERE 0200 X#define CAN_ORBIT_HERE 0100 X X#define ORB_DATA(DX,DY) (oentry[22-(DX)-9*(DY)]) X X/* the strange subscript formula above makes */ X/* the following array correspond to the map */ X Xstatic char oentry[45] = { /* orbital entry calculations */ X 0000, 0202, 0303, 0304, 0304, 0304, 0314, 0224, 0000, X 0202, 0373, 0000, 0000, 0000, 0000, 0000, 0315, 0224, X 0371, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0335, X 0260, 0351, 0000, 0000, 0000, 0000, 0000, 0337, 0246, X 0000, 0260, 0350, 0340, 0340, 0340, 0347, 0246, 0000 X}; X Xvoid orbmove(p) Xregister t_player *p; X{ X extern void pmesg(); X extern t_planet planet; X register char dx, dy, c; X X if((p->ocnt&06) == 4) { X dx = planet.places[8][0] - p->curx; X dy = planet.places[8][1] - p->cury; X if (dx < -4 || dx > 4 || dy < -2 || dy > 2 X || !((c = ORB_DATA(dx,dy))&CAN_ORBIT_HERE)) { X /* should "never" happen */ X pmesg(p, "Orbit unstable!\007"); X p->status.orb = FALSE; X return; X } X p->offx = ORB_INCR(c)[0]; X p->offy = ORB_INCR(c)[1]; X } else { X p->offx = 0; X p->offy = 0; X } X p->ocnt += 2; X} X Xvoid orbit(p) Xregister t_player *p; X{ X extern void pmesg(); X extern int rand(); X extern t_planet planet; X register char dx, dy, c; X int sense; /* CW or CCW ? */ X X move(STDATAX, STDATAY, p); X if (p->offx < -1 || p->offx > 1 || p->offy < -1 || p->offy > 1) { X pmesg(p, "Velocity too great!!"); X return; X } X dx = planet.places[8][0] - p->curx; X dy = planet.places[8][1] - p->cury; X if (dx < -4 || dx > 4 || dy < -2 || dy > 2 X || !((c = ORB_DATA(dx,dy))&CAN_ENTER_HERE)) { X pmesg(p, "Too far from planet to orbit!"); X return; X } X if ( ! p->status.orb ) { X p->status.orb = TRUE; X p->ocnt = 0; X sense = dx * p->offy - dy * p->offx; /* cross product */ X if ( sense > 0 || (sense == 0 && rand()&01) ) X p->ocnt = 1; X p->offx = p->offy = 0; X if ( !(c&CAN_ORBIT_HERE) ) { X /* jump to proper orbit location */ X p->curx += ORB_INCR(c)[0]; X p->cury += ORB_INCR(c)[1]; X } X } X pmesg(p, "In orbit around: %s", planet.planetname); X} !xxENDITxx! echo x - aliens.c sed -e 's/^X//' > aliens.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: aliens.c,v 2.1 85/04/10 17:30:09 matt Stab $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original by Greg Ordy 1979 X * Rewrite by Sam Leffler 1981 X * Socket code by Dave Pare 1983 X * Ported & improved X * by Matt Crawford 1985 X * X * routines dealing with aliens X * X * Copyright (c) 1979 X * X * $Log: aliens.c,v $ X * Revision 2.1 85/04/10 17:30:09 matt X * Major de-linting and minor restructuring. X * X */ X X X#include "defines.h" X#include "structs.h" X X/* X * Move an alien -- update displays X */ Xvoid movealien(pa) Xregister t_alien *pa; X{ X extern int rand(); X extern void launch(); X void phaser(); X int psycho(); X register t_player *pl; X char dx, X dy; X X pa->count--; X /* X * If we're not on screen, just update internally X */ X if (pa->onscr == OFF || pa->whotoget == NOTHING) { X if (pa->count == 0) { /* shanker alarm clock */ X pa->count = (rand()%20)+100; X pa->cix = (rand()%3)-1; X pa->ciy = (rand()%3)-1; X if (pa->cix == 0 && pa->ciy == 0) X pa->ciy = -1; X } X pa->cx += pa->cix; X pa->cy += pa->ciy; X return; X } X pl = &pa->whotoget->u_player; X pa->onscr = OFF; X if (pa->count <= 0) { X pa->count = 10; /* reset alarm clock */ X dx = pl->curx - pa->cx; X dy = pl->cury - pa->cy; X /* X * Close enough to a player to shoot? X */ X if (dx < 9 && dx > -9 && dy < 5 && dy > -5) { X pa->fx = pl->offx; X pa->fy = pl->offy; X if (pl->status.alive == FALSE) { X pa->whotoget = 0; X return; X } X if (dx == 0) { X if (dy == 0) { X phaser(pa, pl); X return; X } X if (!psycho(pa)) X launch((thing *)pa, dy > 0 ? SO : NO, X ALIEN, pa->fx, pa->fy, 0, X pa->cx, pa->cy, 0); X } else if (dx == dy) { X if (!psycho(pa)) X launch((thing *)pa, dx > 0 ? SE : NW, X ALIEN, pa->fx, pa->fy, 0, X pa->cx, pa->cy, 0); X } else if (dx == -dy) { X if (!psycho(pa)) X launch((thing *)pa, dx > 0 ? NE : SW, X ALIEN, pa->fx, pa->fy, 0, X pa->cx, pa->cy, 0); X } else if (dy == 0) { X if (dx == 0) { X phaser(pa, pl); X return; X } X if (!psycho(pa)) X launch((thing *)pa, dx > 0 ? EA : WE, X ALIEN, pa->fx, pa->fy, 0, X pa->cx, pa->cy, 0); X } X if (dx > 0) { X if (dy > 0) X pa->cx++; X else X pa->cy--; X } else { X if (dy > 0) X pa->cy++; X else X pa->cx--; X } X return; X } X if (dx < 0) X pa->cx--; X if (dx > 0) X pa->cx++; X X if (dy < 0) X pa->cy--; X if (dy > 0) X pa->cy++; X } X if (pl->offx > 3 || pl->offx < -3) X pa->cx += pa->cix; X else X pa->cx += pl->offx; X if (pl->offy > 3 || pl->offy < -3) X pa->cy += pa->ciy; X else X pa->cy += pl->offy; X} X X/* X * Check for psychos -- if found, unleash torpedo barrage X */ Xint psycho(pa) Xregister t_alien *pa; X{ X extern int rand(); X register char x,y; X char ox, X oy; X X if(((rand()>>5)%6) != 5) /* magic decision */ X return(0); X x = pa->cx; X y = pa->cy; X ox = pa->fx; X oy = pa->fy; X launch((thing *)pa, SO, ALIEN, ox, oy, 0, x, y, 8); X launch((thing *)pa, NO, ALIEN, ox, oy, 0, x, y, 8); X launch((thing *)pa, SE, ALIEN, ox, oy, 0, x, y, 8); X launch((thing *)pa, NW, ALIEN, ox, oy, 0, x, y, 8); X launch((thing *)pa, NE, ALIEN, ox, oy, 0, x, y, 8); X launch((thing *)pa, SW, ALIEN, ox, oy, 0, x, y, 8); X launch((thing *)pa, EA, ALIEN, ox, oy, 0, x, y, 8); X launch((thing *)pa, WE, ALIEN, ox, oy, 0, x, y, 8); X return(1); X} X X/* X * Phaser a player for a shanker X */ Xvoid phaser(pa, p) Xregister t_alien *pa; Xregister t_player *p; X{ X extern int rand(); X extern void pmesg(); X X pa->whotoget = 0; X pa->cix++; X pa->ciy = (rand()%4)-2; X p->maxe -= 50; X if (p->maxe < p->energy) X p->energy = p->maxe; X pmesg(p, "Enjoy the shankers revenge!"); X} !xxENDITxx! echo x - bursts.c sed -e 's/^X//' > bursts.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: bursts.c,v 1.2 85/07/08 17:22:19 matt Exp $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original by Greg Ordy 1979 X * Rewrite by Sam Leffler 1981 X * Socket code by Dave Pare 1983 X * Ported & improved X * by Matt Crawford 1985 X * X * routines to manipulate shrapnel X * X * Copyright (c) 1979 X * X */ X X X#include "defines.h" X#include "structs.h" X X/* X * Create a burst of shrapnel upon death of a player. X */ Xvoid makeburst(bx, by) Xchar bx, by; X{ X extern t_burst bursts[NBURST]; X register t_burst *bp; X register t_burst *last; X X last = &bursts[NBURST]; X for (bp = bursts; bp < last; bp++) { X if (bp->cbactive != 0) X continue; X bp->cbactive++; X bp->cbx = bx; X bp->cby = by; X bp->shrap[0][0] = bx; X bp->shrap[0][1] = by; X bp->cbcnt = 100; X return; X } X} X X/* X * Update shrapnel position and display X */ Xvoid moveburst() { X extern int nplayer; X extern char xxi, X yyi; X extern t_burst bursts[NBURST]; X void getdir(); X register int j; X register t_burst *bp, X *last; X register char xi, X yi, X qrt; X X last = &bursts[NBURST]; X for (bp = bursts; bp < last; bp++) { X if (bp->cbactive == 0) X continue; X if (bp->cbcnt == 100) { X bp->cbcnt--; X break; X } X if (bp->cbcnt == 98) { X bp->cbcnt = 50; X for (j=1; j != 4; j++) { X qrt = (rand()>>4)%8; X xi = bp->cbx; X yi = bp->cby; X switch (qrt) { X case 0: X xi++; X break; X case 1: X xi++; X yi--; X break; X case 2: X yi--; X break; X case 3: X xi--; X yi--; X break; X case 4: X xi--; X break; X case 5: X xi--; X yi++; X break; X case 6: X yi++; X break; X case 7: X xi++; X yi++; X break; X } X bp->shrap[j][0] = xi; X bp->shrap[j][1] = yi; X bp->shrapd[j] = qrt; X } X break; X } X if (bp->cbcnt > 48) { X bp->cbcnt--; X break; X } X if (bp->cbcnt == 48) { X bp->cbcnt = (rand()>>4)%(16-nplayer); X qrt = bp->shrapd[1]; X xi = bp->shrap[1][0]; X yi = bp->shrap[1][1]; X getdir(qrt, xi, yi); X bp->shrap[0][0] = xxi; X bp->shrap[0][1] = yyi; X getdir(qrt, xi, yi); X bp->shrap[4][0] = xxi; X bp->shrap[4][1] = yyi; X qrt = bp->shrapd[2]; X xi = bp->shrap[2][0]; X yi = bp->shrap[2][1]; X getdir(qrt, xi, yi); X bp->shrap[5][0] = xxi; X bp->shrap[5][1] = yyi; X getdir(qrt, xi, yi); X bp->shrap[6][0] = xxi; X bp->shrap[6][1] = yyi; X qrt = bp->shrapd[3]; X xi = bp->shrap[3][0]; X yi = bp->shrap[3][1]; X getdir(qrt, xi, yi); X bp->shrap[7][0] = xxi; X bp->shrap[7][1] = yyi; X getdir(qrt, xi, yi); X bp->shrap[8][0] = xxi; X bp->shrap[8][1] = yyi; X break; X } X bp->cbcnt--; X if (bp->cbcnt == 3) { X for (j = 1; j != 4; j++) { X bp->shrap[j][0] = 0; X bp->shrap[j][1] = 0; X } X bp->shrap[0][0] = 0; X bp->shrap[0][1] = 0; X break; X } X if (bp->cbcnt == 0) { X for (j = 4; j != 9; j++) { X bp->shrap[j][0] = 0; X bp->shrap[j][1] = 0; X } X bp->cbactive = 0; X break; X } X } X} X X/* X * Furnish random movement for shrapnel pieces X */ Xstatic void getdir(dir, xi, yi) Xchar dir, xi, yi; X{ X extern int rand(); X extern char xxi, X yyi; X register char dx, X dy; X X dx = ((rand()>>3)%3)-1; X dy = ((rand()>>3)%3)-1; X switch (dir) { X case 0: X if (dx < 0) X dx = 2; X break; X case 1: X if (dx < 0) X dx = 2; X if (dy > 0) X dy = -2; X break; X case 2: X if (dy > 0) X dy = -2; X break; X case 3: X if (dx > 0) X dx = -2; X if (dy > 0) X dy = -2; X break; X case 4: X if (dx > 0) X dx = -2; X break; X case 5: X if (dx > 0) X dx = -2; X if (dy < 0) X dy = 2; X break; X case 6: X if (dy < 0) X dy = 2; X break; X case 7: X if (dx < 0) X dx = 2; X if (dy < 0) X dy = 2; X break; X } X xxi = xi+dx; X yyi = yi+dy; X} !xxENDITxx! echo x - lists.c sed -e 's/^X//' > lists.c << '!xxENDITxx!' X#ifndef lint Xstatic char rcsid[] = "$Header: lists.c,v 2.1 85/04/10 17:31:19 matt Stab $"; X#endif X/* X * X * search X * X * multi-player and multi-system search and destroy. X * X * Original by Greg Ordy 1979 X * Socket code by Dave Pare 1983 X * Ported & improved X * by Matt Crawford 1985 X * X * routines to maintain linked lists that describe what a X * player is currently seeing on his viewscreen X * X * Copyright (c) 1979 X * X * $Log: lists.c,v $ X * Revision 2.1 85/04/10 17:31:19 matt X * Major de-linting and minor restructuring. X * X * Revision 1.3 84/07/08 17:04:00 matt X * Added Log X * X * Revision 1.2 84/07/08 16:46:28 matt X * Rplaced the struct hack *pnt with the short key. The "hack" was X * not portable to the Sun! X */ X X#include "defines.h" X#include "structs.h" X X Xvoid enteritem(x, y, xchar) Xchar x, y, xchar; X{ X extern t_player *wholist; X struct plist *gnode(); X register struct plist *xp = wholist->plstp; X register int glob = x | (y<<8); X register int *pdp = (int *) &wholist->plstp; X struct plist *cp; X short key; X X while (xp != 0) { X key = (xp->zx) | (xp->zy << 8); X if (key < glob) { X pdp = (int *) &xp->zpnt; X xp = xp->zpnt; X continue; X } X if (key == glob) { X if (xp->zflg == 1) X return; X xp->zflg = 1; X if (xchar == xp->zchar) X return; X xp->zchar = xchar; X move(x+CENTX, y, wholist); /* macro */ X *wholist->eoq++ = xchar; X *wholist->eoq = NULL; X return; X } X if (key > glob) { X *pdp = (int) gnode(x, y, xchar); X move(x+CENTX, y, wholist); X *wholist->eoq++ = xchar; X *wholist->eoq = NULL; X cp = (struct plist *) *pdp; X cp->zpnt = xp; X return; X } X } X *pdp = (int) gnode(x, y, xchar); X move(x+CENTX, y, wholist); X *wholist->eoq++ = xchar; X *wholist->eoq = NULL; X} X Xvoid uplst() { X extern void fnode(); X extern t_player *wholist; X register struct plist *xp; X register int *pdp; X register char x, y; X struct plist *cp; X char c; X X xp = wholist->plstp; X pdp = (int *) &wholist->plstp; X while (xp != 0) { X x = xp->zx; X y = xp->zy; X cp = xp->zpnt; X switch (xp->zflg) { X case 0: X move(x+CENTX, y, wholist); X c = x == XWIND && y != YWIND ? '|' : X x != XWIND && y == YWIND ? '-' : ' '; X *wholist->eoq++ = c; X *wholist->eoq = NULL; X xp->zpnt = 0; X fnode (xp); X xp = cp; X *pdp = (int) cp; X break; X case 1: X xp->zflg = 0; X pdp = (int *) &xp->zpnt; X xp = cp; X break; X default: X errlog("bad arg to uplst"); X xp->zflg = 0; X pdp = (int *) &xp->zpnt; X xp = cp; X break; X } X } X} X Xstruct plist *gnode(x, y, c) Xchar x, y, c; X{ X extern core_dump(); X extern char *malloc(); X extern struct plist *avl; X extern int numbnode; X register struct plist *px, X *qx; X register int i; X X if (avl == 0) { X if ((avl = (struct plist *) malloc(100*sizeof(*avl))) == (struct plist *)-1) { X errlog("out of memory in gnode()\n"); X (void)core_dump(); X } X qx = avl; X px = &avl[1]; X for (i=0; i<99; i++) X (qx++)->zpnt = px++; X qx->zpnt = 0; X } X px = avl; X avl = avl->zpnt; X px->zx = x; X px->zy = y; X px->zchar = c; X px->zflg = 1; X px->zpnt = 0; X numbnode++; X return (px); X} X X/* X * free the screen nodes up. X */ Xvoid fnode (px) Xregister struct plist *px; X{ X extern int numbnode; X extern struct plist *avl; X register struct plist *qx = px; X X if (px == 0) X return; X while (px->zpnt) { X px = px->zpnt; X numbnode--; X } X numbnode--; X px->zpnt = avl; X avl = qx; X} !xxENDITxx!