DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T t

⟦3813a3d2d⟧ TextFile

    Length: 10102 (0x2776)
    Types: TextFile
    Names: »torpedo.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Mpss/torpedo.c« 

TextFile


/********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 "header.h"

move_torpedos()
{
int x,y,ll;
int hit;
struct torpedo *t,*a;
struct player *p,*h;
char bcstring[57];

t=tstartlist;
while (t!=NULL) 
	{
	if (t->life==0)
		{
		a=t;
		remove_torpedo_from_list(a);
		t=t->next;
		continue;
		}
hit=OFF;
t->oldxpos=t->xpos;
t->oldypos=t->ypos;
t->xpos+=t->xvel;
t->ypos+=t->yvel;
x=t->xpos;
y=t->ypos;

if ((x<58)||(x>899)||(y<19)||(y>899))
	{
	if (x<58) t->xvel=1;
	if (x>899) t->xvel= -1;
	if (y<19) t->yvel=1;
	if (y>899) t->yvel= -1;
	}

p=startlist;
	while ((hit==OFF)&&(p!=NULL))
	{
	if ((p->xpos==x)&&(p->ypos==y)) {hit=ON; h=p;}
	p=p->next;
	}

if (hit) 
	{
	t->life=0;
	t->xpos-=t->xvel;
	t->ypos-=t->yvel;
	if (t->whofrom != NULL)
		{

		if (h->stat<12)
			{
			plot1(t->whofrom,"        Direct hit on enemy Captain! Well Done!          ");
			plot2(t->whofrom,"                                                         ");
		if (h->id==ROMID) 
				{
				h->photonpower +=10; 
				h->phaserpower +=5;
				}
		if (h->id==KLINGID)
				{
				h->photonpower +=5; 
				h->phaserpower +=2;
				}
			}
		t->whofrom->score += 10;
		plotscore(t->whofrom);
	if (h->id==ROMID || h->id==KLINGID)
		{
		i=rand()%100;
		if (i<25) 
			{
			/*take off away from the guy*/
			h->yvel=h->xvel;
			h->xvel=1;
			} else
			{
			i=rand()%100;
			if (i>50)
				{
				/*stay and fight*/
				if (t->whofrom->ypos == h->ypos)
					{
					if (t->whofrom->xpos <  h->xpos)
						{
						if (i<75)
						fire_torpedo(h,'4',0);
						else
						{
						fire_torpedo(h,'4',0);
						fire_torpedo(h,'1',0);
						fire_torpedo(h,'7',0);
						}
						}
						else	
						if (i<75)
						fire_torpedo(h,'6',0);
						else
						{
						fire_torpedo(h,'6',0);
						fire_torpedo(h,'9',0);
						fire_torpedo(h,'3',0);
						if (i>85)
							{
						fire_torpedo(h,'2',0);
						fire_torpedo(h,'8',0);
						fire_torpedo(h,'6',0);
							}
						}
					} else
					{
					if (t->whofrom->ypos < h->ypos)
						{
						fire_torpedo(h,'1',0);
						fire_torpedo(h,'2',0);
						fire_torpedo(h,'3',0);
						}
						else	
						{
						fire_torpedo(h,'7',0);
						fire_torpedo(h,'8',0);
						fire_torpedo(h,'9',0);
						}
					}
				}
			}
		}
	else
	{
	switch (h->stat)
	{
	case 9 :
	plot1(h,"   Spock : Sir, stop scanning. We are being attacked!!   ");
	plot2(h,"                                                         ");
	break;
	case 10 :
	plot1(h,"   Scott to Captain : Sir we are under attack!! better   ");
	plot2(h,"         beam back up to the ship NOW...                 ");
	break;
	case 11 :
	plot1(h,"   Spock : Sir, Exit Help mode. We are being attacked!!  ");
	plot2(h,"                                                         ");
	break;
	case 12 : break;
	default :
	plot1(h,"        Battle Stations...Battle Stations                ");
	plot2(h,"                                                         ");
	break;
	}
	}
		if (t->weapon=='+')
			{
			if (h->shields)
				h->energy-=((t->whofrom->photonpower)/2);
        			else h->energy-=(t->whofrom->photonpower);
			} else
			{
			if (h->shields)
				h->energy-=((t->whofrom->phaserpower)/2);
				else h->energy-=(t->whofrom->phaserpower);
			}
		h->maxenergy=h->energy+1;
		plotbattleenergy(h);
		if (h->stat<7) 
			plotstatus(h,2);
		if ((h->energy<1)&&(h->stat<12))
			{
			plot1(h,"        You have been blown out of the sky!!!            ");
			plot2(h,"       Shame the force wasn't with you this time.        ");
	if (t->whofrom->id!=ROMID 
	 && t->whofrom->id!=KLINGID 
         && h->reason>0) h->reason= -4;
	if (t->whofrom->id==ROMID && h->reason>0) h->reason= -10;
	if (t->whofrom->id==KLINGID && h->reason>0) h->reason= -9;
			finish(h);
			t->whofrom->score += 100;
			plot1(t->whofrom,"        Chekov : Got him!! Bones : He's dead Jim!        ");
			plot2(t->whofrom,"        Score has been increased by 100 points.          ");
			plotscore(t->whofrom);
			} else
			{
		if ((h->shields)&&(h->energy<=200)&&(h->energy>0)&&(h->stat<12))
			{
			plot1(h,"        Shields Collapsed Captain!!!                     ");
			plot2(h,"                                                         ");
			h->shields=OFF;
			h->id=(char)(h->id+32);
			plotshields(h);
			h->chflg=FLAG;
			}
			}
		} else
		{
		plot1(h,"   You were hit by a piece of debris from the explosion! ");
		plot2(h,"         Your energy capability has been lowered.        ");
		h->energy-=30;
		h->maxenergy-=30;
		plotbattleenergy(h);
		if (h->energy<0 && h->reason>0) 
			{
			h->reason= -11;
			finish(h);
			}
		}
	} else /*hit is off!*/
	{
	if ((c=inuniv(x,y))!=NULL)
		{ 
		t->life=0;
		t->xpos-=t->xvel;
		t->ypos-=t->yvel;
		if (t->whofrom!=NULL)
			{
			j=which_sector(t->xpos,t->ypos,0,0);
		if (j==2 && t->whofrom->id!=ROMID && t->whofrom->id!=KLINGID) 
				{
				gethim(t->whofrom,KLINGID);
				gethim(t->whofrom,KLINGID);
				gethim(t->whofrom,KLINGID);
				gethim(t->whofrom,KLINGID);
				}
		if (j==3 && t->whofrom->id!=ROMID && t->whofrom->id!=KLINGID) 
				{
				gethim(t->whofrom,ROMID);
				gethim(t->whofrom,ROMID);
				gethim(t->whofrom,ROMID);
				gethim(t->whofrom,ROMID);
				}
		if (j==4 && t->whofrom->id!=ROMID && t->whofrom->id!=KLINGID) 
				{
				for (ll=1;ll<MAXALIENS;ll++)   
				    gethim(t->whofrom,ROMID);
				for (ll=1;ll<MAXALIENS;ll++)   
				    gethim(t->whofrom,KLINGID);
				}
			}
		if (c=='*')
			{
sprintf(bcstring,"       Starbase at quadrant %3d %3d is under attack.     ",x,y);
broadcast(bcstring);
			}
		if (c=='O')
			{
sprintf(bcstring,"         Planet at quadrant %3d %3d is under attack.     ",x,y);
broadcast(bcstring);
			}
		if (c=='.')
			{
sprintf(bcstring,"           Star at quadrant %3d %3d is under attack.     ",x,y);
broadcast(bcstring);
			}
		if (c=='@')
			{
sprintf(bcstring,"Someone is fireing into a Black Hole at quadrant %3d %3d.",x,y);
broadcast(bcstring);
			}
		} else --(t->life);
	}
	t=t->next;
	} /*while loop*/
}

enter_torpedo(t)
struct torpedo *t;
{
t->next=NULL;
if (tstartlist==NULL)
{
tstartlist=t;
ttaillist=t;
} else
{
ttaillist->next=t;
ttaillist=t;
}
}

remove_torpedo_from_list(t)
struct torpedo *t;
{
struct torpedo *a; 

if (t==tstartlist)
{
a=tstartlist;
tstartlist=a->next;
if (t==ttaillist) ttaillist=a->next;
} else
{
a=tstartlist;
while (a->next!=t) a=a->next;
a->next=t->next;
if (t==ttaillist) ttaillist=a;
}
free(t);
}

fill_torpedo(cp,c,t)
register struct player *cp;
struct torpedo *t;
char c;
{
if (cp->weaponselect==1) 
{
t->weapon='+';
t->xpos=cp->xpos;
t->ypos=cp->ypos;
switch(c) {
case '1': 
 t->xvel=cp->xvel-1; t->yvel=cp->yvel-1;
break;
case '4': 
 t->xvel=cp->xvel-1; t->yvel=cp->yvel;
break;
case '7': 
 t->xvel=cp->xvel-1; t->yvel=cp->yvel+1;
break;
case '8': 
 t->xvel=cp->xvel; t->yvel=cp->yvel+1;
break;
case '9': 
 t->xvel=cp->xvel+1; t->yvel=cp->yvel+1;
break;
case '6': 
 t->xvel=cp->xvel+1; t->yvel=cp->yvel;
break;
case '3': 
 t->xvel=cp->xvel+1; t->yvel=cp->yvel-1;
break;
case '2': 
 t->xvel=cp->xvel; t->yvel=cp->yvel-1;
break;
default:t->weapon='X';  
 t->xvel=cp->xvel+1; t->yvel=cp->yvel;
break;
}
} else
{
t->xpos=cp->xpos;
t->ypos=cp->ypos;
switch(c) {
case '1':t->weapon='/'; 
 t->xvel=cp->xvel-1; t->yvel=cp->yvel-1;
break;
case '4':t->weapon='<'; 
 t->xvel=cp->xvel-1; t->yvel=cp->yvel;
break;
case '7':t->weapon='\\'; 
 t->xvel=cp->xvel-1; t->yvel=cp->yvel+1;
break;
case '8':t->weapon='^'; 
 t->xvel=cp->xvel; t->yvel=cp->yvel+1;
break;
case '9':t->weapon='/'; 
 t->xvel=cp->xvel+1; t->yvel=cp->yvel+1;
break;
case '6':t->weapon='>'; 
 t->xvel=cp->xvel+1; t->yvel=cp->yvel;
break;
case '3':t->weapon='\\'; 
 t->xvel=cp->xvel+1; t->yvel=cp->yvel-1;
break;
case '2':t->weapon='v'; 
 t->xvel=cp->xvel; t->yvel=cp->yvel-1;
break;
default:t->weapon='X'; 
 t->xvel=cp->xvel+1; t->yvel=cp->yvel;
break;
}
}
}

fire_torpedo(cp,c,type)
struct player *cp;
char c;
int type;
{
struct torpedo *t;
if (type==0)
{
if (cp->weaponselect==0)
{
if (cp->phaserbanks==0) 
{
plot1(cp,"      Scott to Captain : The Phaser banks are empty!     ");
plot2(cp,"                                                         ");
return(0);
}
} else
{
if (cp->photontorpedos==0) 
{
plot1(cp,"  Scott to Captain : We have no more Photon Torpedos!    ");
plot2(cp,"                                                         ");
return(0);
}
}

t=(struct torpedo *)malloc(sizeof(struct torpedo));
fill_torpedo(cp,c,t);
if ((t->xvel==0)&&(t->yvel==0))
{
plot1(cp,"                                                         ");
plot2(cp,"               Weapons must move Captain!!               ");
free(t);
return(0);
}
if (cp->weaponselect==0)
{
if ((cp->id!=ROMID)&&(cp->id!=KLINGID)) --(cp->phaserbanks);
plotphaserbanks(cp);
if ((c=='1')||(c=='7')||(c=='9')||(c=='3'))
  t->life=(cp->phaserreach)/2;
else
  t->life=cp->phaserreach;
}
else
{
if ((cp->id!=ROMID)&&(cp->id!=KLINGID))  --(cp->photontorpedos);
plotphotontorpedos(cp);
if ((c=='1')||(c=='7')||(c=='9')||(c=='3'))
t->life=(cp->photonreach)/2;
else
t->life=cp->photonreach;
}

t->oldxpos=t->xpos;
t->oldypos=t->ypos;
t->whofrom=cp;
if (cp->stat<7) plotstatus(cp,2);
plot1(cp,"                 Its away!!!!                            ");
plot2(cp,"                                                         ");
} else
{
t=(struct torpedo *)malloc(sizeof(struct torpedo));
cp->xvel=0;
cp->yvel=0;
fill_torpedo(cp,c,t);
t->life=4;
t->oldxpos=t->xpos;
t->oldypos=t->ypos;
t->whofrom=NULL;
}
enter_torpedo(t);
}