home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.wwiv.com
/
ftp.wwiv.com.zip
/
ftp.wwiv.com
/
pub
/
EVENTS
/
LONEW11.ZIP
/
LONEWOLF.C
< prev
next >
Wrap
Text File
|
1989-10-25
|
33KB
|
1,477 lines
#include <stdio.h>
#include <string.h>
#include <io.h>
#include <fcntl.h>
#include <stdlib.h>
#include <time.h>
#include <dir.h>
#include <dos.h>
/* >>>COMMENTED SKELETON.C<<< by WAYNE BELL with comments by DOUG FIELDS */
/* A commented version of SKELETON.C. All comments except global variable discriptions
are by Doug Fields, voice tel # 203-661-2976 (in CT). This program is copyright (I think it is at least)
by Wayne Bell, the programmer of WWIV. All code is his in FULL, this is
just a revision making it understandable to the novice. NOTE: This is for version 4.04
and other versions which pass the comport and bps/baud rate. Also NOTE that
this uses UNIX style file I/O instead of the ANSI proposed standard. If
you have any questions/comments feel free to call me (at reasonable hrs.). */
int usernum, /* user number for the user */
age, /* age of the user */
screenchars, /* chars/line user has specified */
screenlines, /* lines/screen user has specified */
sl, /* sec lev for user (0-255) */
so, /* non-zero if user is sysop (sl=255) */
cs, /* non-zero if user is co-sysop */
okansi, /* non-zero if user can support ANSI */
incom, /* non-zero if user is calling remotely */
comport; /* com port user is on */
char name[81], /* name/alias of user */
realname[81], /* real name of user */
callsign[10], /* amateur radio callsign of user */
sex, /* sex of user, M or F */
laston[81], /* date user was last on */
gfiles[81], /* directory for text files, ends in \ */
data[81], /* directory for non-text files, ends in \ */
sysoplog[81], /* full path & filename for sysop log */
curspeed[81]; /* speed user is on at, "KB" if local */
double gold, /* gold user has */
timeallowed; /* number of seconds before user logged off */
int read_in_data(char *fn)
/* This function will take the filename passed to it and open it as if it
were a CHAIN.TXT file and take all information out of it and place it into
the global variables defined above. If it fails to open the file, it will
return -1. */
{
char buf[1024]; /* This is where the file will be put for fast access. */
char *ptr[30]; /* This will hold pointers to parts of the buf array,
acting as an index. */
int i,f,len,i1; /* i, i1 = loop control variables;
len = number of bytes read from file;
f = file descriptor number for the filename. */
float fl; /* This holds a temporary value of the user's gold. */
/* fn = the filename of the CHAIN.TXT file. */
f=open(fn,O_RDONLY | O_BINARY); /* Open the file for input as a binary file,
i.e. without character translations. */
if (f<0) { /* If the file descriptor (f) is less than
0 (i.e. it is -1) then abort the
function and return error (-1). */
return(-1);
}
i1=1; /* Initialize i1. */
ptr[0]=buf; /* Point the first index to the first character
of the buf array. */
len=read(f,(void *)buf,1024); /* Read in from the file f into buf up to
1024 characters (until the EOF is reached)
and return the actual number of characters
read in len. */
close(f); /* We're finished with the file so put it
away. */
for (i=0; i<len; i++) /* This for loop goes through the buf array
(which now contains the contents of the
chain info file) and assigns indices to
the ptr array of pointers. It causes all
returns to be mapped into null characters
(ASCII 0) for use as strings, and skips
over the following LF character. In this
way, ptr will end up pointing to a bunch
of character strings. */
if (buf[i]==13) {
buf[i]=0;
ptr[i1++]=&buf[i+2];
}
while (*ptr[6]==32) /* Remove leading spaces for the float
values by incrementing the pointer
by one character. */
++(ptr[6]);
while (*ptr[15]==32)
++(ptr[15]);
usernum=atoi(ptr[0]); /* From here on it is straight translation
from the ptr index array into the global
variables. */
/* Get the user number from index 0. */
strcpy(name,ptr[1]); /* Get the name, real name, and callsign. */
strcpy(realname,ptr[2]);
strcpy(callsign,ptr[3]);
age=atoi(ptr[4]); /* Get the user's age. */
sex=*ptr[5]; /* Get the user's sex. */
sscanf(ptr[6],"%f",&fl); /* These two lines read in the user's gold
and typecast it into a double float. */
gold=(double)fl;
strcpy(laston,ptr[7]); /* Get his date of last being on. */
screenchars=atoi(ptr[8]); /* Get the size of his screen. */
screenlines=atoi(ptr[9]);
sl=atoi(ptr[10]); /* Get his seclev. */
so=atoi(ptr[11]); /* Is he a sysop? (nonzero if true) */
cs=atoi(ptr[12]); /* How about a cosysop? */
okansi=atoi(ptr[13]); /* Does he use ANSI graphics? */
incom=atoi(ptr[14]); /* Is he calling remotely (1) or not? */
sscanf(ptr[15],"%f",&fl); /* These two lines read in the number of
seconds left to the user and typecast
the value into a double float. */
timeallowed=(double)fl;
strcpy(gfiles,ptr[16]); /* What is the gfiles dir? */
strcpy(data,ptr[17]); /* What is the data dir? */
strcpy(sysoplog,gfiles); /* These two lines get the full pathname
for the sysoplog file. */
strcat(sysoplog,ptr[18]);
strcpy(curspeed,ptr[19]); /* A string containing the user's
bps/baud rate or KB if local. */
comport=atoi(ptr[20]); /* The user's comport if remote. */
return(0); /* Return and give a 'we read it in fine'
message. */
}
char directory[81];
struct date date;
void main(int argc, char *argv[])
{
FILE *fptr;
char path[81];
argc=argc; /* God knows what this line is for. */
if (read_in_data(argv[1])==-1) { /* Try to read in the parameter file
and if it returns the -1 error message,
quit the program with an error message. */
printf("\nData file not found\n\n");
abort();
}
getdate(&date);
getcwd(directory,80);
if((fptr=fopen("path.lw","r"))==NULL)
{
printf("There is a problem");
exit(0);
}
fgets(path,80,fptr);
fclose(fptr);
chdir(path);
welcome();
}
#include "color.h"
struct PLAYER
{
char name[81];
int number,
combat_skill,
endurance,
origendur,
skill[6],
weoponskill,
weopons[3],
food,
money,
moves,
day,
location,
special[101];
long score;
}player,player1;
struct COUNTER
{
int count;
}counter;
struct ROOMCH
{
int roomnum;
int roomtype;
int choice[5];
int dis[5];
int randhi[5];
int randlow[5];
int combat[5];
int endurance[5];
int comadder; /*added to you combat*/
int endadder; /*added to your endurnce for this fight*/
int weaponin;
int specialin;
int specialuse;
int specialuse_adder;
int moneyin;
int moneyuse;
int foodin;
int fooduse;
}roomch;
struct SCORE
{
char name[81];
long score;
}scores[10];
char *disciplines[11]={"none","Camouflage","Hunting","Sixth Sense","Tracking",
"Healing","Weaponskill","Mindshield","Mindblast","Animal Kinship","Mind over Matter"};
char *weopons[13]={"Dagger","Spear","Mace","Short Sword","WarHammer","Sword",
"Axe","Sword","Quarterstaff","Broadsword","none","none","none"};
char *spec[20]={"none","Helmet","Chainmail","Vordak Gem","healing potion",
"Golden Key","Silver Key","20 Gems","Potion of Strength","Torch","Scrolls",
"Message on animal skin","perfumed soap","Star on a Chain"};
int current=1,store,spot,stop;
welcome()
{
FILE *fptr,*fptr1;
char *file2={"instruct.sw"},ch;
int x,y,chec;
long offset;
printf(CLEAR);
printf("\n\n\n");
printf("The Adventures of Lone Wolf\n\n");
printf("Version 1.1\n");
printf("Programmed in \"C\" by Packer Fan 1@8252 and Krago of the Mountains 9@8252\n\n");
printf("on The AFTERMATH BBS, Terre Haute, Indiana\n\n");
printf("Based on the book of the same name\n");
printf(" By Joe Dever and Gary Chalk\n");
printf("c 1984, Pacer Books, New York\n");
printf("Press Enter to continue");
check();
getche();
printf(CLEAR);
printf("\n\nDo you need instructions??");
check();
ch=getche();
if(ch=='y' || ch=='Y') type(&file2);
printf(CLEAR);
printf("Would you like to see the High Score list?");
ch=getche();
if(ch=='y' || ch=='Y') Scores();
printf("Searching for previous games\n");
if((fptr1=fopen("counters.sw","rb")) == NULL)
{
printf(" Can't open counter file\n");
exit(0);
}
else
{
fread(&counter,sizeof(counter),1,fptr1);
store=counter.count;
}
if((fptr=fopen("players.sw","rb")) == NULL)
{
printf(" Can't open player file\n");
exit(0);
}
offset=0;
chec=counter.count-1;
for(x=0;x<=chec;x++)
{
if(x!=0)
{
offset=x*sizeof(player);
fseek(fptr,offset,0);
}
fread(&player,sizeof(player),1,fptr);
if(strcmp(player.name,name)==0)
{
spot=offset;
fclose(fptr);
game();
}
}
fclose(fptr);
printf("\nWould you like to play now?");
check();
ch=getche();
if(ch=='y' || ch=='Y')
{
player.number=counter.count;
counter.count=counter.count+1;
store=counter.count;
current=0;
player.score=0;
strcpy(player.name,name);
player.weopons[0]=0;
player.location=1;
for(y=0;y<=5;y++)
{
player.skill[y]=0;
}
player.food=0;
for(y=0;y<=100;y++)
{
player.special[y]=0;
}
init();
}
else
{
chdir(directory);
exit(0);
}
}
init()
{
char choice[4];
int mytime;
player.weopons[2]=12;
player.day=date.da_day;
player.moves=30;
randomize();
printf(CLEAR);
printf("Your Location is now %d\n",player.location);
player.combat_skill=random(9)+10;
player.endurance=random(9)+20;
player.origendur=player.endurance;
printf("\n\nYour Combat skill is %d",player.combat_skill);
printf("\nYour Endurance is %d\n",player.endurance);
printf("Now type in your 5 disciplines according to the following table:\n");
printf("1-Camouflage\n2-Hunting\n3-Sixth Sense\n4-Tracking\n5-Healing\n");
printf("6-Weaponskill\n7-Mindshield\n8-Mindblast\n9-Animal Kinship\n10-Mind over matter\n");
printf("Your Location is now %d\n",player.location);
dis();
}
dis()
{
char ch[2],choice,ch1[2];
int num=1,ch2=7,x,y,chec;
printf("\n\nWhat number discipline\(1 to 5\) do you want to input\n");
printf("\(0 to quit, 6 to list disciplines,7 to list yours\)\n");
gets(ch1);
ch2=atoi(ch1);
if(ch2 > 7 || ch2<0)
{
printf("You must chose 0 to 7\n");
dis();
}
if(ch2 == 0)
{
printf("Are you sure you are done, this is the only time you can adjust these!!\n");
check();
choice=getche();
if(choice == 'y' || choice=='Y')
{
for(x=1;x<=5;x++)
{
if(player.skill[x] == 6)
{
player.weoponskill=random(9);
y=player.weoponskill;
printf("Your weoponskill is in %s\n",weopons[y]);
money();
chec = 1;
}
}
if(chec != 1)
{
player.weoponskill=11;
money();
}
}
else dis();
}
if(ch2 == 6)
{
for(x=1;x<=10;x++)
{
printf("%d - %s\n",x,disciplines[x]);
}
dis();
}
if(ch2 == 7)
{
for(x=1;x<=5;x++)
{
y=player.skill[x];
printf("%d - %s\n",x,disciplines[y]);
}
dis();
}
printf("What is your discipline?");
gets(ch);
num=atoi(ch);
if(num >= 11 || num<=0)
{
printf("\nThere are only 10 disciplines\n");
dis();
}
printf("Your %d discipline is %s, is this correct?",ch2,disciplines[num]);
check();
choice=getche();
if(choice == 'y' || choice=='Y')
{
player.skill[ch2]=num;
dis();
}
else dis();
check();
getche();
}
money()
{
player.weopons[1]=6;
printf("\nYou start out with a %s\n", weopons[6]);
player.money=random(9);
printf("You have %d Gold Crowns in a pouch at your waist\n",player.money);
player.food=1;
printf("Your Location is now %d\n",player.location);
printf("You have 1 meal \n");
special();
}
special()
{
int y,z;
y=random(9);
if(y==1||y==5||y==7||y==8||y==0)
{
if(y==1) z=5;
if(y==5) z=2;
if(y==7) z=8;
if(y==8) z=1;
if(y==0) z=9;
player.weopons[2]=z;
printf("You also find a %s in the rubble\n",weopons[z]);
}
if(y==2)
{
player.special[1]=1;
printf("You find a helmet for your head in the rubble\n");
}
if(y==3)
{
player.food=player.food+2;
printf("You find two meals\n");
}
if(y==4)
{
player.special[1]=2;
printf("You find a chainmail waistcoat which you put on\n");
}
if(y==6)
{
player.special[1]=4;
printf("You find a healing potion \n");
}
if(y==9)
{
player.money=player.money+12;
printf("You find 12 gold crowns which brings your money to %d gold crowns",player.money);
}
check();
getche();
game();
}
game()
{
int x,newroom=1;
char ch,new[3];
if(player.day!=date.da_day)
{
player.moves=30;
player.day=date.da_day;
}
printf(CLEAR);
printf("\n\nThe adventures of Silent Wolf Main Menu\n");
printf("---------------------------------------\n");
printf(" [1] Scores\n");
printf(" [2] Play Game\n");
printf(" [3] Your Stats\n");
printf(" [4] Take a Healing Potion\n");
printf(" [5] Quit\n");
printf(" Choice??");
check();
ch=getche();
switch(ch)
{
case '1': Scores();
game();
break;
case '2': play();
break;
case '3': stats();
break;
case '4': pot();
break;
case '5': end();
break;
case '~':if(sl<100) game();
printf("\nWhat room?");
gets(new);
newroom=atoi(new);
player.location=newroom;
printf("\nplayer location = %d",player.location);
check();
getche();
game();
break;
case '`': if(sl<100) game();
printf("\nWhat special?");
gets(new);
newroom=atoi(new);
player.special[4]=newroom;
game();
break;
case 'c':
case 'C': if(sl<100) game();
printf("\nHow much money?");
gets(new);
newroom=atoi(new);
player.money=newroom;
game();
break;
default: game();
}
}
pot()
{
int x;
for(x=1;x<=100;x++)
{
if(player.special[x] == 4)
{
player.endurance=player.endurance+2;
player.special[x]=0;
printf("\n\nRestoring 2 endurance points\n");
check();
game();
}
}
printf("\n\nYou don't have a healing potion right now!!\n");
check();
game();
}
end()
{
FILE *fptr;
int x,offset,chec,y,slot,no=0;
char *die={"dead"};
printf(CLEAR);
if(player.endurance<=0)
{
strcpy(player.name,die);
if(player.location != 350) printf("\n\nYou are dead!!\n");
}
if(current == 0)
{
if((fptr=fopen("players.sw","ab")) == NULL)
{
printf(" Can't open player file\n");
exit(1);
}
strcpy(player.name,name);
if(player.endurance<=0)
{
strcpy(player.name,die);
if(player.location !=350) printf("\n\nYou are dead!!\n");
}
fwrite(&player,sizeof(player),1,fptr);
fclose(fptr);
}
else
{
if((fptr=fopen("players.sw","rb+")) == NULL)
{
printf(" Can't open player file\n");
exit(0);
}
fseek(fptr,spot,0);
fwrite(&player,sizeof(player),1,fptr);
fclose(fptr);
}
counter.count=store;
if((fptr=fopen("counters.sw","wb")) == NULL)
{
printf(" Can't open counter file\n");
exit(0);
}
else
{
fwrite(&counter,sizeof(counter),1,fptr);
}
fclose(fptr);
if((fptr=fopen("scores.sw","rb")) == NULL)
{
printf(" Can't open scores file\n");
exit(0);
}
for(x=0;x<=9;x++)
{
fread(&scores[x],sizeof(scores[x]),1,fptr);
}
fclose(fptr);
if(player.score<=scores[9].score)
{
Scores();
printf("\n\nThanks for Playing The Adventures of Lone Wolf\n\n");
printf("Come back soon to continue the adventure\n\n");
chdir(directory);
exit(0);
}
for(x=9;x>=0;x--)
{
if(player.score==scores[x].score&&(strcmp(name,scores[x].name))==0)no=1;
if(player.score>scores[x].score)slot=x;
}
if(no==0)
{
for(x=9;x>=slot;x--)
{
strcpy(scores[x].name,scores[x-1].name);
scores[x].score=scores[x-1].score;
}
strcpy(scores[slot].name,name);
scores[slot].score=player.score;
if((fptr=fopen("scores.sw","wb")) == NULL)
{
printf(" Can't open scores file\n");
exit(0);
}
for(x=0;x<=9;x++)
{
fwrite(&scores[x],sizeof(scores[x]),1,fptr);
}
fclose(fptr);
}
Scores();
printf("\n\nThanks for Playing The Adventures of Lone Wolf\n\n");
printf("Come back soon to continue the adventure\n\n");
chdir(directory);
exit(0);
}
Scores()
{
FILE *fptr;
int x;
printf(CLEAR);
printf("\n\nScore Board\n\n");
if((fptr=fopen("scores.sw","rb")) == NULL)
{
printf(" Can't open scores file\n");
exit(0);
}
for(x=0;x<=9;x++)
{
fread(&scores[x],sizeof(scores[x]),1,fptr);
printf("%20s %10d\n",scores[x].name,scores[x].score);
}
printf("\n\n\n Press Enter to Continue>>>");
check();
getche();
return;
}
play()
{
char ch[3],c,choice[5],file[80],*file1={"text1.sw"},
*file2={"text2.sw"},
*file3={"text3.sw"},
*file4={"text4.sw"},
*file5={"text5.sw"},
*file6={"text6.sw"},
*file7={"text7.sw"};
int count=0,intchoice,c1=0,x;
FILE *fptr;
printf(CLEAR);
if(player.moves<=0)
{
printf("You are out of moves for today, come back tommorow\n");
check();
game();
}
printf("You have %d moves left\n",player.moves);
stop=player.location;
if(stop>355) play();
read_room();
if(stop<=50) strcpy(file,file1);
if(stop >50 && stop<=100){strcpy(file,file2); stop=stop-50;}
if(stop >100 && stop<=150){strcpy(file,file3);stop=stop-100;}
if(stop >150 && stop<=200){strcpy(file,file4);stop=stop-150;}
if(stop >200 && stop<=250){strcpy(file,file5);stop=stop-200;}
if(stop >250 && stop<=300){strcpy(file,file6);stop=stop-250;}
if(stop>300){strcpy(file,file7);stop=stop-300;}
if((fptr=fopen(file,"r")) == NULL)
{
printf(" Can't open text file\n");
exit(0);
}
for(count=1;count<=stop;count++)
{
while((c=fgetc(fptr)) != '~' && (c!='@'));
}
while((c=fgetc(fptr)) != '~'&& (c!='@') && (c1 == 0))
{
putchar(c);
if(kbhit() != 0) c1=getche();
}
fclose(fptr);
if(player.location!=140&&player.location!=7&&player.location!=70&&player.location!=28)
{
player.score=player.score+1;
}
player.moves=player.moves-1;
if(player.moves==4||player.moves==8||player.moves==12||player.moves==16||player.moves==20||player.moves==24||player.moves==28)
{
if(player.endurance<player.origendur)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==5) player.endurance=player.endurance+1;
}
}
}
if(roomch.roomtype==1) type1(); /* go to rooms, choice rooms, chec disciplines*/
if(roomch.roomtype==2) type2(); /* random choice rooms*/
if(roomch.roomtype==3) type3(); /*combat sequences*/
if(roomch.roomtype==4) type4(); /*take weopon room*/
if(roomch.roomtype==33) type33();/*recieve money room*/
if(roomch.roomtype==9) type9(); /*possesion dependent room*/
if(roomch.roomtype==12) type12(); /*give money room*/
if(roomch.roomtype==20) type4(); /*take weopon and food*/
if(roomch.roomtype==29) type3(); /*combat with mindshield*/
if(roomch.roomtype==5) type5(); /*eat a meal*/
if(roomch.roomtype==99) type99(); /*die instantly*/
if(roomch.roomtype==6) type6(); /*take money and food*/
if(roomch.roomtype==7) type7(); /*take special room*/
if(roomch.roomtype==8) type8(); /*lose endurance*/
if(roomch.roomtype==10) type10(); /*take money and special*/
if(roomch.roomtype==144) type144();
if(roomch.roomtype==162) type162(); /*lose all backpack and weapons*/
if(roomch.roomtype==170) type170(); /*combat, lose combat skill if no torch*/
if(roomch.roomtype==274) type274(); /* lose weapons*/
if(roomch.roomtype==294) type294(); /*lose backpack and weapons, random choice*/
if(roomch.roomtype==304) type304(); /*take special and lose endurance*/
if(roomch.roomtype==350) type350();
if(roomch.roomtype==184) type4();
else
{
printf("\nNot type 1\n");
check();
getche();
player.location=1;
play();
}
}
stats()
{
int y,x,z,wep,hold;
printf(CLEAR);
printf("\n\n%s Stats...........\n",player.name);
printf("\nScore = %d\n",player.score);
printf("Endurance Limit = %d\n",player.origendur);
printf("Current Endurance = %d\n",player.endurance);
printf("Combat Skill = %d\n",player.combat_skill);
for(x=1;x<=5;x++)
{
y=player.skill[x];
printf("%d - %s\n",x,disciplines[y]);
if(y==6)
{
z=player.weoponskill;
printf("Skilled in %s\n",weopons[z]);
}
}
for(x=1;x<=2;x++)
{
if(player.weopons[x] <= 10)
{
wep=player.weopons[x];
printf("You have a %s\n",weopons[wep]);
}
}
printf("You have %d meals\n",player.food);
for(x=0;x<=100;x++)
{
if(player.special[x] != 0)
{
hold=player.special[x];
printf("You have a %s\n",spec[hold]);
}
}
printf("You have %d Gold Crowns\n",player.money);
printf("Player Location = %d\n",player.location);
printf("Press enter to Continue>>>");
check();
getche();
game();
}
type1()
{
int intchoice,chec=0,x;
char ch;
if(player.endurance<=0) end();
printf("\nChoice(Q to quit)??");
check();
ch=getche();
switch(ch)
{
case '1': if(roomch.dis[1] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[1]) chec=1;
}
if(chec != 1) type1();
}
player.location=roomch.choice[1];
play();
break;
case '2': if(roomch.dis[2] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[2]) chec=1;
}
if(chec != 1) type1();
}
if(roomch.choice[2]==0) play();
player.location=roomch.choice[2];
play();
break;
case '3': if(roomch.dis[3] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[3]) chec=1;
}
if(chec != 1) type1();
}
if(roomch.choice[3]==0) play();
player.location=roomch.choice[3];
play();
break;
case '4': if(roomch.dis[4] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[4]) chec=1;
}
if(chec != 1) type1();
}
if(roomch.choice[4]==0) play();
player.location=roomch.choice[4];
play();
break;
case 'Q':
case 'q': if(roomch.roomtype==1)game();
else
{
printf("You can't at this time, you must press on\nHit return>>");
check();
getche();
type1();
}
break;
default: type1();
}
}
type2()
{
int mytime,dice;
printf("Hit Enter to continue");
check();
getche();
randomize();
dice=random(9);
if(dice>=roomch.randlow[1] && dice<=roomch.randhi[1])
{
player.location=roomch.choice[1];
play();
}
if(dice>=roomch.randlow[2] && dice<=roomch.randhi[2])
{
player.location=roomch.choice[2];
play();
}
if(dice>=roomch.randlow[3] && dice<=roomch.randhi[3])
{
player.location=roomch.choice[3];
play();
}
}
type3()
{
int comskill,endure,ratio,enemy,lw,hiten,hitlw,x,y,r,mytime,chec=0;
if(roomch.roomtype==29)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==7) chec=1;
}
if(chec!=1) comskill=player.combat_skill+roomch.comadder;
if(chec==1) comskill=player.combat_skill;
}
if(roomch.roomtype!=29)
{
comskill=player.combat_skill+roomch.comadder;
}
if(player.weoponskill == player.weopons[1] ||player.weoponskill == player.weopons[2])
{
comskill=comskill+2;
}
for(x=1;x<=100;x++)
{
if(player.special[x] == 8) comskill=comskill+2;
}
endure=player.endurance+roomch.endadder;
printf("\nYour combat skill for this fight is %d\n",comskill);
printf("Your Endurance is %d\n",endure);
for(x=4;x>=1;x--)
{
if(roomch.combat[x]==0)y=x;
}
for(x=1;x<y;)
{
ratio=comskill-roomch.combat[x];
printf("\nEnemy 1--Combat skill - %d, Endurance - %d",roomch.combat[x],roomch.endurance[x]);
enemy=roomch.endurance[x];
lw=endure;
while(enemy > 0 && lw > 0)
{
randomize();
r=random(9);
hiten=-2.48+(r*(-1.01))+(ratio*(-.514))+.5;
hitlw=-6.31+(r*(.6742))+(ratio*(.273538))+.5;
if(hitlw>=0) hitlw=0;
enemy=enemy+hiten;
lw=lw+hitlw;
printf("\nHe hits you-->you have %d endurance left\n",lw);
printf("You hit him-->he has %d endurance left\n",enemy);
check();
getche();
}
if(lw<=0)
{
player.endurance=lw;
end();
}
player.endurance=lw;
player.score=player.score+roomch.combat[x]+roomch.endurance[x];
x=x+1;
if(x==y)
{
if(roomch.roomnum==17) type2();
else type1();
}
}
}
type4()
{
int what,x,old,new;
char ch1,ch,ch2;
if(roomch.roomtype==184)
{
player.food=player.food+roomch.foodin;
player.money=player.money+roomch.moneyin;
}
if(roomch.weaponin!=12)
{
what=roomch.weaponin;
if(player.weopons[1] == roomch.weaponin || player.weopons[2] ==roomch.weaponin)
{
if(roomch.roomtype==20)food();
type1();
}
printf("Would you like to take the %s\n",weopons[what]);
check();
ch=getche();
if(ch!='y' && ch!='Y')
{
if(roomch.roomtype==20)food();
type1();
}
if(player.weopons[1] <= 10 && player.weopons[2] <=10)
{
printf("\nYou already have 2 weopons\n");
printf("Would you like to leave one?");
check();
ch1=getche();
if(ch1 != 'y' && ch1 != 'Y') type1();
for(x=1;x<=2;x++)
{
old=player.weopons[x];
new=roomch.weaponin;
printf("\nWould you switch the %s for the %s",weopons[old],weopons[new]);
check();
ch2=getche();
if(ch2=='y'||ch2=='Y')
{
player.weopons[x]=roomch.weaponin;
if(roomch.roomtype==20)food();
type1();
}
}
if(roomch.roomtype==20)food();
type1();
}
else
{
if(player.weopons[2]<=10) player.weopons[2]=roomch.weaponin;
if(roomch.roomtype==20)food();
type1();
}
}
}
type5()
{
eat();
type1();
}
type6()
{
player.money=player.money+roomch.moneyin;
player.score=player.score+roomch.moneyin;
food();
type1();
}
type7()
{
take_special();
type1();
}
take_special()
{
int x=0,y;
while(player.special[x]!=0)
{
x++;
}
player.special[x]=roomch.specialin;
player.score=player.score+10;
return;
}
type8()
{
player.endurance=player.endurance+roomch.endadder;
type1();
}
type9()
{
int x,n,num,y,chec;
char ch[3];
printf("Choice?");
gets(ch);
num=atoi(ch);
if(num==2)
{
if(roomch.dis[2] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[2]) chec=1;
}
if(chec != 1) type9();
}
if(roomch.choice[2]==0) type9();
player.location=roomch.choice[2];
play();
}
if(num==3)
{
if(roomch.dis[3] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[3]) chec=1;
}
if(chec != 1) type9();
}
if(roomch.choice[3]==0) type9();
player.location=roomch.choice[3];
play();
}
for(x=0;x<=100;x++)
{
if(player.special[x] == roomch.specialuse)
{
player.location=roomch.choice[1];
player.score=player.score+25;
play();
}
}
n=roomch.specialuse;
printf("\nYou don't have a %s\n",spec[n]);
check();
getche();
type9();
}
type10()
{
take_special();
type33();
}
type12()
{
int num,x,chec;
char ch[3];
printf("choice??");
gets(ch);
num=atoi(ch);
if(num==2)
{
if(roomch.dis[2] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[2]) chec=1;
}
if(chec != 1) type12();
}
if(roomch.choice[2]==0) type12();
player.location=roomch.choice[2];
play();
}
if(num==3)
{
if(roomch.dis[3] != 0)
{
for(x=1;x<=5;x++)
{
if(player.skill[x]==roomch.dis[3]) chec=1;
}
if(chec != 1) type12();
}
if(roomch.choice[3]==0) type12();
player.location=roomch.choice[3];
play();
}
if(roomch.moneyuse>player.money)
{
printf("You don't have enough money\ntry again\n");
check();
getche();
type12();
}
player.location=roomch.choice[1];
player.money=player.money-roomch.moneyuse;
play();
}
type33()
{
player.money=player.money+roomch.moneyin;
player.score=player.score+roomch.moneyin;
type1();
}
type99()
{
printf("\nYour mission has Ended!!!\nHit enter to continue");
player.endurance=-1;
player.score=player.score-10;
check();
end();
}
type144()
{
eat();
type8();
}
type162()
{
int x;
player.food=0;
player.weopons[1]=12;
player.weopons[2]=12;
player.score=player.score-10;
for(x=0;x<=100;x++)
{
player.special[x]=0;
}
type1();
}
type170()
{
int x;
for(x=0;x<=100;x++)
{
if(player.special[x]==9) type3();
}
roomch.comadder=-3;
type3();
}
type274()
{
player.weopons[1]=12;
player.weopons[2]=12;
player.score=player.score-10;
type(1);
}
type294()
{
int x;
player.food=0;
player.weopons[1]=12;
player.weopons[2]=12;
player.score=player.score-15;
for(x=0;x<=100;x++)
{
player.special[x]=0;
}
type2();
}
type304()
{
take_special();
type8();
}
type350()
{
int x;
printf("\n\n\nYou win!!!!\n\n\n");
for(x=0;x<=100;x++)
{
if(player.special[x]!=0)player.score=player.score+20;
}
if(player.weopons[1]!=12)player.score=player.score+10;
if(player.weopons[2]!=12)player.score=player.score+10;
player.score=player.score+player.money;
player.score=player.score+(player.food*10);
player.score=player.score+100;
player.location=1;
printf("Your final score was %d\n\n",player.score);
check();
player.endurance=-2;
end();
}
food()
{
player.food=player.food+roomch.foodin;
player.food=player.food-roomch.fooduse;
player.score=player.score+10;
player.money=player.money+roomch.moneyin;
type1();
}
read_room()
{
FILE *fptr;
int x,offset;
if((fptr=fopen("rooms.sw","rb")) == NULL)
{
printf(" Can't open text file\n");
exit(0);
}
else
{
offset=0;
for(x=0;x<=360;x++)
{
if(x!=0)
{
offset=x*sizeof(roomch);
fseek(fptr,offset,0);
}
fread(&roomch,sizeof(roomch),1,fptr);
if(roomch.roomnum==stop)
{
fclose(fptr);
return;
}
}
}
fclose(fptr);
}
eat()
{
int x;
for(x=1;x<=5;x++)
{
if(player.skill[x]==2) return;
}
if(player.food==0)
{
player.endurance=player.endurance-3;
printf("You lose 3 endurance points for having no food\n");
}
if(player.food>=1)
{
player.food=player.food-1;
player.score=player.score+10;
printf("You have %d meals left\n",player.food);
}
if(player.endurance<=0)
{
printf("You have no Endurance left-->YOU DIE\nHit enter to Continue");
check();
end();
}
return;
}
check()
{
time_t tstart,tstop;
long tused;
time(&tstart);
while (!kbhit())
{
time(&tstop);
tused=difftime(tstop,tstart);
if(tused>=180) exit(1);
}
return;
}
type(file)
char *file[];
{
FILE *fptr;
char c,string[81];
int c1=0;
if((fptr=fopen(*file,"r")) == NULL)
{
printf("File Doesn't exist");
printf("Press Return>");
check();
getche();
exit(0);
}
while((c=fgetc(fptr))!='@'&& (c1 == 0))
{
putchar(c);
if(kbhit()) c1=getche();
}
fclose(fptr);
}