|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 9259 (0x242b) Types: TextFile Names: »main.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Mpss/main.c«
/********VERSION 1.4!!! (Files from different Versions are INCOMPATIBLE!*******/ /******************************************************************************* ******************************************************************************** ******************************************************************************** PERMISSION TO COPY THIS SOFTWARE IS HEREBY GIVEN BY THE AUTHOR PROVIDED THAT THIS LEADING MESSAGE IS INCLUDED IN ALL OF THE RELEVANT SOURCE FILES. P. SCHMITZ, UNIVERSITY OF KEELE, MAY 1988. ******************************************************************************** ******************************************************************************** *******************************************************************************/ #include <signal.h> #include "files.h" #include "header.h" lognewprocess(procno) int procno; { FILE *f, *fopen(); char arr[15]; if ((f=fopen(PROCESSFILE,"a"))==NULL) { fprintf(stdout,"slave.c : error trying to log processnumber\n"); die(); } else { sprintf(arr,"%d\n",procno); fputs(arr,f); fclose(f); } } checkmasterpidfile() { int rpid,masterpid; char string[15]; FILE *ff,*fopen(); masterpid=getpid(); sprintf(string,"%d",masterpid); if ((ff=fopen(MASTERPIDFILE,"r"))==NULL) { /*fprintf(stdout,"main.c: Can't read masterpidfile\n");*/ die(); } else { fgets(string,15,ff); /*get pid*/ fclose(ff); } sscanf(string,"%d\n",&rpid); if (rpid!=masterpid) { /*fprintf(stdout,"main.c: pids not equal!!! %d %d\n",rpid,masterpid);*/ die(); } signal(SIGALRM,checkmasterpidfile); alarm(60); } /*the only normal way out of the program*/ die() { register struct player *hh; /*fprintf(stderr,"DIE WAS CALLED.\n");*/ hh=startlist; while (hh!=NULL) { if ((hh->id!=ROMID)&&(hh->id!=KLINGID)) kill(hh->pid,9); hh=hh->next; } /*the only normal way out of the program*/ exit(0); /*the only normal way out of the program*/ } /*the only normal way out of the program*/ handler() { noofsignals++; } killcontrol() { int f; /*return(0); THIS MUST BE PUT IN DURING THE DEVELOPMENTAL PHASE*/ if ((f=open("/dev/tty",2))!= -1) { ioctl(f,TIOCNOTTY,0); } } main() { register struct player *cp; int sener,ener,f,o; register int x,y,x1,x2,y1,y2,xx1,xx2,yy1,yy2,xold,yold,xnew,ynew; register char c; register struct torpedo *torpedo; register int loop,xx,test; lognewprocess(getpid()); test=1; f=umask(000); killcontrol(); noofsignals=0; signal(SIGINT,SIG_IGN); signal(29,handler); signal(SIGALRM,checkmasterpidfile); setupuniverse(); storm=OFF; noofaliens=0; noofplayers=0; debug=OFF; startlist=NULL; taillist=NULL; tstartlist=NULL; ttaillist=NULL; cp=NULL; putmasterpidintofile(); alarm(10); for (;;) { /*main iteration loop*/ while (cp!=NULL) { if ((cp->id==ROMID)||(cp->id==KLINGID)) { servicealien(cp); x=cp->xpos; y=cp->ypos; if ((x<58)||(x>899)||(y<19)||(y>899)) { if (x<58) cp->xvel=1; if (x>899) cp->xvel= -1; if (y<19) cp->yvel=1; if (y>899) cp->yvel= -1; } goto goonlabel; } cp->clflg=OFF; /**********************TUNING DELAY LOOP FOR SINGLE-PLAYER-MODE****************/ /* Alter the number (10) below. Increase it to slow down the game, decrease it to speed it up, or delete the loop as a whole if your machine runs mpss to slowly in single player mode. This number > v v v if (noofplayers==1) for (loop=1; loop < 10; loop++); */ /**********************TUNING DELAY LOOP FOR SINGLE-PLAYER-MODE****************/ ioctl(cp->fd,FIONREAD,&noofchars); if (noofchars>0) processinput(cp,&noofchars); if ((cp->stat==5)&&(cp->flyto>=0)&&(cp->flyto<4)) auto_pilot(cp); if (cp->stat>=9) goto goonlabel; /*****************PLOTTING OBJECT STARTS HERE!!!******************/ f=cp->xvel; o=cp->yvel; test=1; x=cp->xpos; y=cp->ypos; cp->oldxpos=x; cp->oldypos=y; xx1=x-28; xx2=xx1+57; yy1=y-9; yy2=yy1+19; x+=f; y+=o; x1=x-28; x2=x1+57; y1=y-9; y2=y1+19; cp->xpos=x; cp->ypos=y; if ((cp->stat>5)||((f==0)&&(o==0))) goto plotmoving; cp->chflg=FLAG; for (i=yy1; i<yy2; ++i) { if ((xp=univ[i])==NULL) continue; do { if ((xx=xp->x)>=xx1) { l=19-(i-yy1); if(((k=20+(xx-xx1))>19)&&(k<77)&&(l>0)&&(l<20)) { test=0; poscurs(cp,k,l); write(cp->fd, ((l==10)&&((k<47)||(k>49)))? "-":((k==48)&&(l!=10))?"|":" ",1); } l+=o; if(((k-=f)>19)&&(l>0)&&(k<77)&&(l<20)) { poscurs(cp,k,l); test=0; write(cp->fd,&(xp->c),1); } } if (xx>x2) xp=NULL; else xp=xp->next_thing; } while (xp!=NULL); } if (test) plotposition(cp); /***************************************************************************** Player plotting starts here!!!! *****************************************************************************/ plotmoving: player=startlist; while (player!=NULL) { if ((cp==player)||((cp->chflg==0)&&(player->chflg==0))) { player=player->next; continue; } xold=player->oldxpos; yold=player->oldypos; xnew=player->xpos; ynew=player->ypos; if (inuniv(xold+f,yold+o)<36) { if ((player->cloakingdevice==OFF)||(player->clflg)) { l=19-(yold-yy1); if(((k=20+(xold-xx1))>19)&&(k<77)&&(l>0)&&(l<20)) { poscurs(cp,k,l); write(cp->fd,((l==10)&&((k<47)||(k>49)))?"-":((k==48)&&(l!=10))?"|":" ",1); } } } if (inuniv(xnew,ynew)<36) { if (player->cloakingdevice==OFF) { if (player->stat<12) { l=19-(ynew-y1); if(((k=20+(xnew-x1))>19)&&(l>0)&&(k<77)&&(l<20)) { poscurs(cp,k,l); write(cp->fd,&(player->id),1); } } } } player=player->next; } /************************************************************************** Torpedo plotting starts here!! ***************************************************************************/ torpedo=tstartlist; while (torpedo!=NULL) { xold=torpedo->oldxpos; yold=torpedo->oldypos; xnew=torpedo->xpos; ynew=torpedo->ypos; player=torpedo->whofrom; if (((player!=NULL)&&(cp!=player)&&(xold==player->oldxpos)&& (yold==player->oldypos)) || ((inuniv(xold,yold)!=NULL))) { torpedo=torpedo->next; continue; } k=20+(xold-xx1); l=19-(yold-yy1); if((k>19)&&(k<77)&&(l>0)&&(l<20)) { poscurs(cp,k,l); write(cp->fd,((l==10)&&((k<47)||(k>49)))?"-":((k==48)&&(l!=10))?"|":" ",1); } if (torpedo->life>0) { l=19-(ynew-y1); if(((k=20+(xnew-x1))>19)&&(l>0)&&(k<77)&&(l<20)) { poscurs(cp,k,l); write(cp->fd,&(torpedo->weapon),1); } } torpedo=torpedo->next; } /*****************PLOTTING OBJECTS STOPS HERE!!!******************/ if ((x<58)||(x>899)||(y<19)||(y>899)) { if (x<58) { cp->xvel=1; plotvelocity(cp); } if (x>899) { cp->xvel= -1; plotvelocity(cp); } if (y<19) { cp->yvel=1; plotvelocity(cp); } if (y>899) { cp->yvel= -1; plotvelocity(cp); } } else { if ((c=inuniv(x,y))!=NULL) collision(cp,c); if (((f!=0)||(o!=0))&&((x==450)||(y==450))) { j=which_sector(cp->xpos,cp->ypos,f,o); switch (j) { case 1: { plot1(cp," You have just entered Federation space again. "); plot2(cp," It's nice to be home. "); break; } case 2: { plot1(cp,"You have just entered Klingon Space. Remember the klingon"); plot2(cp,"proverb : Revenge is a dish that is best served cold....."); break; } case 3: { plot1(cp," You have just entered the Mutara Nebula. "); plot2(cp," Here, Shields and Cloaking Devices will not function! "); cp->cloakingdevice=OFF; if (cp->shields) { cp->id=(char)(cp->id+32); cp->shields=OFF; } plotshields(cp); plotcloakingdevice(cp); if (cp->stat<12) cp->chflg=FLAG; break; } case 4: { plot1(cp," You have just entered the Neutral Zone. "); plot2(cp," We are now in violation of treaty Captain!! "); break; } default : break; } /*switch*/ } } if ((storm)&&(f==-1)) storm=OFF; /*ENERGY CALCULATION*/ i=cp->cloakingdevice; i+=cp->shields; j=(abs(f)>abs(o))?abs(f):abs(o); if (j==0) { if ((i==0)&&(cp->energy<cp->maxenergy)) ++cp->energy; else goto skipenergy; } else { if ((j==1) && (i==0)) goto skipenergy; cp->energy -= (i+j); } skipenergy: ener=cp->energy; sener=cp->screenenergy; if ((ener==75)&&(storm==OFF)) flare(); if (ener!=sener) { if ((ener<=100) || (((ener%50)==0)) || (ener==cp->maxenergy)) plotenergy(cp); } /*ENERGY CALCULATION*/ goonlabel: if (cp->impulsemove>0) { cp->impulsemove=0; cp->xvel=0; cp->yvel=0; } if (cp->chflg>0) --(cp->chflg); cp=cp->next; } /*while cp!=NULL*/ remove_finished_players(); if (tstartlist!=NULL) move_torpedos(); if (noofsignals>0) { makenewplayerandjoinhimin(); --noofsignals; } if ((noofplayers==1)&&(noofaliens<MAXALIENS)) makealien(); cp=startlist; /*main iteration loop*/ } } remove_finished_players() { struct player *y; y=startlist; while (y!=NULL) { if ((y->stat==12)&&(y->chflg<1)) remove_player_from_list(y); y=y->next; } } flare() { register struct player *x; broadcast("Galactic ion storm commencing. Cloaking devices are off. "); storm=ON; x=startlist; while (x!=NULL) { x->cloakingdevice=OFF; plotcloakingdevice(x); x->chflg=FLAG; x=x->next; } }