tb1/tb1.c

349 lines
12 KiB
C
Raw Normal View History

1998-03-07 20:37:00 +00:00
/****************************************************************\
\* TOM BOMBEM AND THE INVASION OF THE INANIMATE_OBJECTS */
2000-09-16 23:23:00 +00:00
/* version 2.9.2 15 September 2000 *\
1998-03-07 20:37:00 +00:00
\* by Vince Weaver weave@eng.umd.edu */
/* *\
\* Originally written in Pascal and x86 assembly for DOS */
2000-09-05 03:57:00 +00:00
/* using the PCGPE code as an example in 1994 *\
\* Ported to Linux, C, and ggi late 1997-early 1998 */
/* Port continued to SDL in June of 2000 *\
1998-03-07 20:37:00 +00:00
\* This source is released under the GPL */
/****************************************************************/
2000-09-16 23:23:00 +00:00
#define TB1_VERSION "2.9.2"
1998-03-07 20:37:00 +00:00
#include <stdio.h>
2000-09-16 23:23:00 +00:00
#include <stdlib.h> /* for calloc */
#include <string.h> /* for strncpy */
1998-03-07 20:37:00 +00:00
#include <unistd.h>
#include <sys/time.h>
2000-09-16 23:23:00 +00:00
#include "svmwgraph/svmwgraph.h"
2000-09-05 03:57:00 +00:00
#include "tb1_state.h"
1998-03-07 20:37:00 +00:00
#include "tblib.h"
2000-09-05 03:57:00 +00:00
#include "sound.h"
1998-03-07 20:37:00 +00:00
2000-09-17 05:47:00 +00:00
#include "graphic_tools.h"
2000-09-16 23:23:00 +00:00
#include "help.h"
#include "quit.h"
#include "story.h"
#include "credits.h"
#include "about.h"
2000-09-17 05:47:00 +00:00
#include "loadsave.h"
2000-09-16 23:23:00 +00:00
#include "options.h"
#include "playgame.h"
1998-03-07 20:37:00 +00:00
int command_line_help(int show_version,char *runas)
{
if (!show_version) {
printf("Usage: %s [-force8bpp] [-nosound] [-readonly]"
" [-version] [-?]\n\n",runas);
printf(" -force8bpp : force to run in 8bpp mode\n");
printf(" -nosound : disables sound within game\n");
printf(" -readonly : don't try to write files to disk\n");
printf(" -version : print version\n");
printf(" -? : print this help message\n");
printf("\n");
}
return 0;
}
int main(int argc,char **argv)
{
2000-09-05 03:57:00 +00:00
int i,grapherror,reloadpic=0;
int custom_palette[256];
int ch,x,barpos,time_sec;
2000-09-16 23:23:00 +00:00
int scale=1;
1998-03-07 20:37:00 +00:00
FILE *fff;
2000-09-17 05:47:00 +00:00
vmwVisual *virtual_1,*virtual_2,*virtual_3;
2000-09-05 03:57:00 +00:00
2000-09-17 05:47:00 +00:00
tb1_state *game_state;
2000-09-05 03:57:00 +00:00
2000-09-16 23:23:00 +00:00
vmwFont *tb1_font;
2000-09-05 03:57:00 +00:00
struct timeval time_info;
struct timezone dontcare;
1998-03-07 20:37:00 +00:00
printf("\nTom Bombem v%s by Vince Weaver weave@eng.umd.edu\n",TB1_VERSION);
printf(" http://www.glue.umd.edu/~weave/tb1\n\n");
2000-09-05 03:57:00 +00:00
/* Setup the game state */
2000-09-17 05:47:00 +00:00
if ( (game_state=calloc(1,sizeof(tb1_state)))==NULL) {
2000-09-05 03:57:00 +00:00
printf("You are seriously low on RAM!\n");
return 3;
}
/* Some sane defaults */
game_state->level=0;
game_state->shields=0;
game_state->score=0;
game_state->virtual_1=NULL;
game_state->virtual_2=NULL;
game_state->virtual_3=NULL;
game_state->sound_enabled=1;
1998-03-07 20:37:00 +00:00
/* Parse Command Line Arguments */
i=1;
while(i<argc) {
if (argv[i][0]=='-') {
switch (argv[i][1]) {
case 'h': case '?':
command_line_help(0,argv[0]); return 5; break;
case 'v':
command_line_help(1,argv[0]); return 5; break;
2000-09-05 03:57:00 +00:00
1998-03-07 20:37:00 +00:00
case 'n':
2000-09-05 03:57:00 +00:00
game_state->sound_enabled=0;
1998-03-07 20:37:00 +00:00
printf(" + Sound totally disabled\n");
break;
case 'r':
2000-09-05 03:57:00 +00:00
// read_only_mode=1;
1998-03-07 20:37:00 +00:00
printf(" + Read Only mode enabled\n");
break;
default : command_line_help(0,argv[0]);
printf("Unknown Option: %s\n\n",argv[i]);
return 5;
}
}
else {
command_line_help(0,argv[0]);
printf("Unknown Option: %s\n\n",argv[i]);
return 5;
}
i++;
}
/* Find the Data */
/* FIXME : User Defined Path Info*/
if ( (fff=fopen("./data/data_files_here","r"))!=NULL) {
2000-09-05 03:57:00 +00:00
strncpy(game_state->path_to_data,"./data/",20);
1998-03-07 20:37:00 +00:00
}
else if ( (fff=fopen("/usr/local/games/tb1/data/data_files_here","r"))
!=NULL) {
2000-09-05 03:57:00 +00:00
strncpy(game_state->path_to_data,"/usr/local/games/tb1/data/",40);
1998-03-07 20:37:00 +00:00
}
else {
char tempst[200];
sprintf(tempst,"%s/.tb1/data/data_files_here",getenv("HOME"));
if ( (fff=fopen(tempst,"r"))!=NULL) {
2000-09-05 03:57:00 +00:00
sprintf(game_state->path_to_data,"%s/.tb1/data/",getenv("HOME"));
1998-03-07 20:37:00 +00:00
}
else {
printf("ERROR! Could not find tb1 data!\n");
printf(" Checked ./data, /usr/local/games/tb1/data\n");
printf(" and %s/.tb1/data\n\n",getenv("HOME"));
return 9;
}
}
2000-09-05 03:57:00 +00:00
printf(" + Found tb1 data in %s\n",game_state->path_to_data);
1998-03-07 20:37:00 +00:00
/* FIXME : find where writing info out to */
/* REMNANT OPERATION BOTTLECAP STUFF---> *\
\* No 9-22-94 Back to yes 10-6-94 uh_oh 2-21-95 */
/* gone for real long time 10-12-95 *\
\* 11-95 not Amy anymore, but Gus */
/* 3-96 oh well... gave up on Gus finally *\
\* 5-11-96 Now Marie... what fun life is */
/* Randomize random number generator */
srandom(time(NULL));
2000-09-05 03:57:00 +00:00
printf(" + Seeding random number generator...\n");
/* Load sounds */
initSound(game_state->path_to_data);
loadSound(tb1_data_file("vmwfan.mod",game_state->path_to_data));
printf(" + Loaded sounds...\n");
1998-03-07 20:37:00 +00:00
/* Setup Graphics */
2000-09-16 23:23:00 +00:00
if ( (game_state->graph_state=vmwSetupSVMWGraph(VMW_SDLTARGET,
320*scale,200*scale,
16,1))==NULL) {
1998-03-07 20:37:00 +00:00
fprintf(stderr,"ERROR: Couldn't get display set up properly.\n");
2000-09-16 23:23:00 +00:00
return VMW_ERROR_DISPLAY;
1998-03-07 20:37:00 +00:00
}
2000-09-16 23:23:00 +00:00
/* Load the tom bombem font */
game_state->graph_state->default_font=
vmwLoadFont(tb1_data_file("tbfont.tb1",
game_state->path_to_data),8,16,256);
printf(" + Loaded tb1 font...\n");
if ((game_state->virtual_1=vmwSetupVisual(320,200,256))==NULL) {
2000-09-05 03:57:00 +00:00
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 1!\n");
2000-09-16 23:23:00 +00:00
return VMW_ERROR_MEM;
2000-09-05 03:57:00 +00:00
}
2000-09-16 23:23:00 +00:00
if ((game_state->virtual_2=vmwSetupVisual(320,400,256))==NULL) {
2000-09-05 03:57:00 +00:00
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 2!\n");
2000-09-16 23:23:00 +00:00
return VMW_ERROR_MEM;
2000-09-05 03:57:00 +00:00
}
2000-09-16 23:23:00 +00:00
if ((game_state->virtual_3=vmwSetupVisual(320,200,256))==NULL) {
2000-09-05 03:57:00 +00:00
fprintf(stderr,"ERROR: Couldn't get RAM for virtual screen 3!\n");
2000-09-16 23:23:00 +00:00
return VMW_ERROR_MEM;
2000-09-05 03:57:00 +00:00
}
printf(" + Allocated virtual screens...\n");
/* To ease typing burden */
virtual_1=game_state->virtual_1;
virtual_2=game_state->virtual_2;
2000-09-17 05:47:00 +00:00
virtual_3=game_state->virtual_3;
2000-09-16 23:23:00 +00:00
tb1_font=game_state->graph_state->default_font;
for (x=0;x<256;x++) custom_palette[x]=vmwPack3Bytes(0,0,0); /* 0=black */
2000-09-05 03:57:00 +00:00
1998-03-07 20:37:00 +00:00
/* Do the VMW Software Production Logo */
2000-09-05 03:57:00 +00:00
for(x=0;x<=40;x++) {
custom_palette[100+x]=vmwPack3Bytes( ((x+20)*4),0,0);
custom_palette[141+x]=vmwPack3Bytes(0,0, ( (x+20)*4 ));
custom_palette[182+x]=vmwPack3Bytes(0, ( (x+20)*4),0);
1998-03-07 20:37:00 +00:00
}
2000-09-05 03:57:00 +00:00
1998-03-07 20:37:00 +00:00
/* Set the white color */
2000-09-05 03:57:00 +00:00
custom_palette[15]=vmwPack3Bytes(0xff,0xff,0xff);
1998-03-07 20:37:00 +00:00
/* Finalize Pallette Stuff */
2000-09-16 23:23:00 +00:00
vmwLoadCustomPalette(virtual_1,custom_palette);
1998-03-07 20:37:00 +00:00
/* Actually draw the stylized VMW */
for(x=0;x<=40;x++){
2000-09-05 03:57:00 +00:00
vmwDrawVLine(x+40,45,2*x,100+x,virtual_1);
vmwDrawVLine(x+120,45,2*x,141+x,virtual_1);
vmwDrawVLine(x+200,45,2*x,141+x,virtual_1);
vmwDrawVLine(x+80,125-(2*x),2*x,182+x,virtual_1);
vmwDrawVLine(x+160,125-(2*x),2*x,182+x,virtual_1);
1998-03-07 20:37:00 +00:00
}
for(x=40;x>0;x--){
2000-09-05 03:57:00 +00:00
vmwDrawVLine(x+80,45,80-(2*x),140-x,virtual_1);
vmwDrawVLine(x+160,45,80-(2*x),181-x,virtual_1);
vmwDrawVLine(x+240,45,80-(2*x),181-x,virtual_1);
vmwDrawVLine(x+120,45+(2*x),80-(2*x),222-x,virtual_1);
vmwDrawVLine(x+200,45+(2*x),80-(2*x),222-x,virtual_1);
1998-03-07 20:37:00 +00:00
}
2000-09-05 03:57:00 +00:00
vmwTextXY("A VMW SOFTWARE PRODUCTION",60,140,
2000-09-16 23:23:00 +00:00
15,15,0,tb1_font,virtual_1);
2000-09-05 03:57:00 +00:00
2000-09-16 23:23:00 +00:00
if (game_state->sound_enabled) playSound();
2000-09-05 03:57:00 +00:00
2000-09-16 23:23:00 +00:00
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
1998-03-07 20:37:00 +00:00
pauseawhile(5);
2000-09-05 03:57:00 +00:00
stopSound();
loadSound(tb1_data_file("weave1.mod",game_state->path_to_data));
1998-03-07 20:37:00 +00:00
/* Clear the Screen and get ready for the Menu */
2000-09-05 03:57:00 +00:00
vmwClearScreen(virtual_1,0);
1998-03-07 20:37:00 +00:00
/* Load the title screen */
2000-09-05 03:57:00 +00:00
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,1,
tb1_data_file("tbomb1.tb1",game_state->path_to_data));
2000-09-17 05:47:00 +00:00
/* Set up palettes */
2000-09-05 03:57:00 +00:00
grapherror=vmwLoadPicPacked(0,0,virtual_2,1,1,
tb1_data_file("tbomb1.tb1",game_state->path_to_data));
2000-09-17 05:47:00 +00:00
grapherror=vmwLoadPicPacked(0,0,game_state->virtual_3,1,1,
tb1_data_file("tbomb1.tb1",game_state->path_to_data));
2000-09-16 23:23:00 +00:00
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
1998-03-07 20:37:00 +00:00
/* Main Menu Loop */
while (1) {
if (reloadpic) {
2000-09-17 05:47:00 +00:00
grapherror=vmwLoadPicPacked(0,0,virtual_3,1,1,
2000-09-05 03:57:00 +00:00
tb1_data_file("tbomb1.tb1",game_state->path_to_data));
2000-09-16 23:23:00 +00:00
grapherror=vmwLoadPicPacked(0,0,virtual_1,1,0,
tb1_data_file("tbomb1.tb1",game_state->path_to_data));
1998-03-07 20:37:00 +00:00
reloadpic=0;
}
2000-09-05 03:57:00 +00:00
2000-09-17 05:47:00 +00:00
vmwFlipVirtual(virtual_1,virtual_3,320,200);
2000-09-16 23:23:00 +00:00
if (game_state->sound_enabled) playSound();
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
2000-09-05 03:57:00 +00:00
while (!vmwGetInput()) usleep(300);
2000-09-16 23:23:00 +00:00
1998-03-07 20:37:00 +00:00
barpos=0;
2000-09-05 03:57:00 +00:00
vmwTextXY("F1 HELP",0,190,9,7,0,tb1_font,virtual_1);
coolbox(117,61,199,140,1,virtual_1);
2000-09-16 23:23:00 +00:00
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
1998-03-07 20:37:00 +00:00
ch=0;
2000-09-05 03:57:00 +00:00
2000-09-16 23:23:00 +00:00
while(ch!=VMW_ENTER){
2000-09-05 03:57:00 +00:00
if (barpos==0) vmwTextXY("NEW GAME",123,67,32,0,1,tb1_font,virtual_1);
else vmwTextXY("NEW GAME",123,67,32,7,1,tb1_font,virtual_1);
if (barpos==1) vmwTextXY("OPTIONS",123,77,32,0,1,tb1_font,virtual_1);
else vmwTextXY("OPTIONS",123,77,32,7,1,tb1_font,virtual_1);
if (barpos==2) vmwTextXY("ABOUT",123,87,32,0,1,tb1_font,virtual_1);
else vmwTextXY("ABOUT",123,87,32,7,1,tb1_font,virtual_1);
if (barpos==3) vmwTextXY("LOAD GAME",123,97,32,0,1,tb1_font,virtual_1);
else vmwTextXY("LOAD GAME",123,97,32,7,1,tb1_font,virtual_1);
if (barpos==4) vmwTextXY("STORY",123,107,32,0,1,tb1_font,virtual_1);
else vmwTextXY("STORY",123,107,32,7,1,tb1_font,virtual_1);
if (barpos==5) vmwTextXY("CREDITS",123,117,32,0,1,tb1_font,virtual_1);
else vmwTextXY("CREDITS",123,117,32,7,1,tb1_font,virtual_1);
if (barpos==6) vmwTextXY("QUIT",123,127,32,0,1,tb1_font,virtual_1);
else vmwTextXY("QUIT",123,127,32,7,1,tb1_font,virtual_1);
2000-09-16 23:23:00 +00:00
vmwBlitMemToDisplay(game_state->graph_state,virtual_1);
2000-09-05 03:57:00 +00:00
1998-03-07 20:37:00 +00:00
/* If at title screen too long, run credits */
gettimeofday(&time_info,&dontcare);
time_sec=time_info.tv_sec;
2000-09-05 03:57:00 +00:00
while( ((ch=vmwGetInput())==0)) {
1998-03-07 20:37:00 +00:00
usleep(10);
gettimeofday(&time_info,&dontcare);
if (time_info.tv_sec-time_sec>40) {
2000-09-05 03:57:00 +00:00
stopSound();
credits(game_state);
2000-09-16 23:23:00 +00:00
ch=VMW_ENTER;
1998-03-07 20:37:00 +00:00
barpos=9;
reloadpic=1;
gettimeofday(&time_info,&dontcare);
time_sec=time_info.tv_sec;
}
}
/* Change menu position based on key pressed */
2000-09-16 23:23:00 +00:00
if ((ch==VMW_DOWN)||(ch==VMW_RIGHT)) barpos++;
if ((ch==VMW_UP) || (ch==VMW_LEFT)) barpos--;
if (ch==VMW_F1) {barpos=10; ch=VMW_ENTER;} /*F1*/
2000-09-05 03:57:00 +00:00
if (ch=='n') barpos=0; /*N*/
if (ch=='o') barpos=1; /*O*/
if (ch=='a') barpos=2; /*A*/
if (ch=='l') barpos=3; /*L*/
if (ch=='s') barpos=4; /*S*/
if (ch=='c') barpos=5; /*C*/
if (ch=='q') barpos=6; /*Q*/
2000-09-16 23:23:00 +00:00
if (ch==VMW_ESCAPE){ /* escape */
1998-03-07 20:37:00 +00:00
barpos=6;
2000-09-16 23:23:00 +00:00
ch=VMW_ENTER;
1998-03-07 20:37:00 +00:00
}
if(barpos==7) barpos=0;
if(barpos<0) barpos=6;
}
2000-09-05 03:57:00 +00:00
stopSound();
1998-03-07 20:37:00 +00:00
/* Run whatever it was that the person pressed */
switch (barpos) {
2000-09-05 03:57:00 +00:00
case 0: playthegame(game_state); reloadpic=1; break;
2000-09-17 05:47:00 +00:00
case 1: options(game_state); break;
2000-09-05 03:57:00 +00:00
case 2: about(game_state); reloadpic=1; break;
2000-09-17 05:47:00 +00:00
case 3: loadgame(game_state); reloadpic=1; break;
2000-09-05 03:57:00 +00:00
case 4: story(game_state); reloadpic=1; break;
2000-09-17 05:47:00 +00:00
case 5: credits(game_state); break;
2000-09-05 03:57:00 +00:00
case 6: barpos=quit(game_state); break;
2000-09-17 05:47:00 +00:00
case 10: help(game_state); reloadpic=1; break;
1998-03-07 20:37:00 +00:00
}
}
}