summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dash.c491
1 files changed, 207 insertions, 284 deletions
diff --git a/dash.c b/dash.c
index 0c124ce..5b639c4 100644
--- a/dash.c
+++ b/dash.c
@@ -30,6 +30,10 @@
#include <stdarg.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
#include "Xbit.h"
#define WINX 100
@@ -47,17 +51,17 @@
# define USLEEP(x) usleep(x)
#endif
-XSizeHints size_hints;
-ulong black,white;
-Display *disp;
-Window window;
-Colormap cm;
-XFontStruct *font;
+static XSizeHints size_hints;
+static ulong black,white;
+static Display *disp;
+static Window window;
+static Colormap cm;
+static XFontStruct *font;
-char *GetPath(),
- *GetFXPath(),
- *GetLevelPath(),
- *GetLibPath();
+static char *GetPath(void),
+ *GetFXPath(const char *s),
+ *GetLevelPath(const char *s),
+ *GetLibPath(const char *s);
#define SPACESPRNAME "space"
#define EARTHSPRNAME "earth"
@@ -132,7 +136,7 @@ typedef struct
Pixmap p;
} sprite;
-sprite spr[NOSPR]=
+static sprite spr[NOSPR]=
{
{SPACESPRNAME,0},
{EARTHSPRNAME,0},
@@ -155,7 +159,7 @@ sprite spr[NOSPR]=
{CHSRGENSPRNAME,0}
};
-char glyph_map[NOSPR]=
+static char glyph_map[NOSPR]=
{
/* SPACESPR */ ' ',
/* EARTHSPR */ '.',
@@ -197,10 +201,10 @@ typedef struct
int x,y;
} Generator;
-Enemy enemy[MAX_ENEMY];
-Generator generator[MAX_GENERATOR];
-int no_enemy;
-int no_generator;
+static Enemy enemy[MAX_ENEMY];
+static Generator generator[MAX_GENERATOR];
+static int no_enemy;
+static int no_generator;
#define AMOEBA_COUNT 5
@@ -213,9 +217,9 @@ typedef struct
int could_move;
} Amoeba;
-Amoeba amoeba;
-int max_amoeba_size;
-int amoeba_move_chance;
+static Amoeba amoeba;
+static int max_amoeba_size;
+static int amoeba_move_chance;
#define WELLDONELEV -1
@@ -245,7 +249,7 @@ typedef struct
#define ROT_LEFT(d) ((((d)-1)<UP) ? (LEFT) : ((d)-1))
#define ROT_FLIP(d) (((d)+2)%4)
-struct
+static struct
{
int x,y;
} move_tbl[4]=
@@ -266,7 +270,7 @@ typedef struct
int level;
} hiscore;
-hiscore hisc[MAX_HISCORE]=
+static hiscore hisc[MAX_HISCORE]=
{
{10000,"Score 1",1},
{9000,"Score 2",2},
@@ -280,90 +284,98 @@ hiscore hisc[MAX_HISCORE]=
{1000,"Score 10",10}
};
-int chsz=16;
-int slp=-1;
-int bw=False;
-int startlev=1;
-int cursesmode=False;
-
-double si[360];
-double co[360];
-
-int level=1;
-int score=0;
-int no_levels=0;
-int lives=3;
-int quit=False;
-int dead=False;
-Level lev;
-int fr_flag;
-int title_fr;
+static int chsz=16;
+static int slp=-1;
+static int bw=False;
+static int startlev=1;
+static int cursesmode=False;
+
+static double si[360];
+static double co[360];
+
+static int level=1;
+static int score=0;
+static int no_levels=0;
+static int lives=3;
+static int quit=False;
+static int dead=False;
+static Level lev;
+static int fr_flag;
+static int title_fr;
#define AT(a,b) *((lev.data)+(a)+((lev.w)*(b)))
/* Curses/X mode function calls */
-int (*TitlePage)()=NULL;
-int (*Cls)()=NULL; /* Cls(int colour) */
-int (*Put)()=NULL; /* Put(int x,y,SprNum) */
-int (*Centre)()=NULL; /* Centre(char *str;int y,col) */
-int (*Update)()=NULL;
-int (*Repaint)()=NULL; /* Repaint (int full_flag) */
-int (*Printf)()=NULL; /* Printf(x,y,col,fmt,....) */
-int (*IntroLevel)()=NULL;
-int (*PlayLevel)()=NULL;
-int (*LevelWon)()=NULL;
-int (*LevelLost)()=NULL;
-int (*GameWon)()=NULL;
-int (*GameLost)()=NULL;
-int (*Show)()=NULL; /* Show(int (*func)(),sleep_fl,quit_fl) */
-int (*EndWindowing)()=NULL;
+static void (*TitlePage)(void);
+static void (*Cls)(ulong);
+static void (*Put)(int, int, int);
+static void (*Centre)(const char *, int, ulong);
+static void (*Update)(void);
+static void (*Repaint)(int);
+static void (*Printf)(int, int, ulong, const char *fmt, ...);
+static void (*IntroLevel)(void);
+static int (*PlayLevel)(void);
+static void (*LevelWon)(void);
+static void (*LevelLost)(void);
+static void (*GameWon)(void);
+static void (*GameLost)(void);
+static void (*Show)(void (*)(void), int, int);
+static void (*EndWindowing)(void);
/* X Versions */
-int XTitle();
-/* int XCls(); */
-int PutX();
-int XCentre();
-int XUpdate();
-int XRepaint();
-/* int Xprintf(); */
-int XIntroLevel();
-int XPlayLevel();
-int LevelOk();
-int LevelNotOk();
-int XGameOverWon();
-int XGameOverLost();
-int DoTillPress();
-int XEndWindowing();
+static void XTitle(void);
+static void PutX(int,int,int);
+static void XCentre(const char *, int, ulong);
+static void XUpdate(void);
+static void XRepaint(int);
+static void XIntroLevel(void);
+static int XPlayLevel(void);
+static void LevelOk(void);
+static void LevelNotOk(void);
+static void XGameOverWon(void);
+static void XGameOverLost(void);
+static void DoTillPress(void (*)(void),int, int);
+static void XEndWindowing(void);
/* Curses Versions */
-int CursesTitle();
-int CursesCls();
-int CursesPut();
-int CursesCentre();
-int CursesRedraw();
-int CursesRepaint();
-int CursesPrintf(int x, int y, int c, const char *fmt, ...);
-int CursesIntroLevel();
-int CursesPlayLevel();
-/* int LevelOk(); */
-/* int LevelNotOk(); */
-int CursesGameOverWon();
-int CursesGameOverLost();
-int CursesDoTillPress();
-int CursesEndWindowing();
-
-
-int main(argc,argv)
-int argc;
-char *argv[];
-
+static void CursesCls(ulong);
+static void CursesPut(int,int,int);
+static void CursesCentre(const char *, int, ulong);
+static void CursesRedraw(void);
+static void CursesRepaint(int);
+static void CursesPrintf(int x, int y, ulong c, const char *fmt, ...);
+static void CursesIntroLevel(void);
+static int CursesPlayLevel(void);
+static void CursesGameOverWon(void);
+static void CursesGameOverLost(void);
+static void CursesDoTillPress(void (*)(void),int, int);
+static void CursesEndWindowing(void);
+
+static void LoadScores(void);
+static void Exit(int n);
+static void LoadSpritesBW(void);
+static void LoadSprites(void);
+static void LoadLevelNo(void);
+static void LoadLevel(int l);
+static void AutoOff(void);
+static void AutoOn(void);
+static void DrawScore(void);
+static void IntrHandler(int);
+static void EnterHiscore(void);
+static void DrawMess(const char *s);
+static void Gravity(void);
+static void DoPause(void);
+
+
+/* ------------------------------------------------------------ MAIN
+*/
+int main(int argc, char *argv[])
{
int f;
XEvent event;
unsigned long evmask;
- void IntrHandler();
- umask(000);
+ umask(0);
signal(SIGINT,IntrHandler);
for(f=0;f<360;f++)
@@ -586,7 +598,7 @@ char *argv[];
}
-void IntrHandler()
+static void IntrHandler(int s)
{
if (EndWindowing)
(*EndWindowing)();
@@ -599,8 +611,7 @@ void IntrHandler()
/* --------------------------------------------------------------------- */
-AutoOff()
-
+static void AutoOff(void)
{
if (!cursesmode)
{
@@ -610,8 +621,7 @@ AutoOff()
}
-AutoOn()
-
+static void AutoOn(void)
{
if (!cursesmode)
{
@@ -623,7 +633,7 @@ AutoOn()
/* --------------------------------------------------------------------- */
-char *GetPath()
+static char *GetPath(void)
{
static char *env=NULL;
char *p;
@@ -647,9 +657,7 @@ char *GetPath()
}
-char *GetFXPath(s)
-char *s;
-
+char *GetFXPath(const char *s)
{
static char r[256];
char *p;
@@ -677,9 +685,7 @@ char *s;
}
-char *GetLevelPath(s)
-char *s;
-
+static char *GetLevelPath(const char *s)
{
static char r[256];
char *p;
@@ -697,9 +703,7 @@ char *s;
}
-char *GetLibPath(s)
-char *s;
-
+static char *GetLibPath(const char *s)
{
static char r[256];
char *p;
@@ -714,8 +718,7 @@ char *s;
}
-LoadScores()
-
+static void LoadScores(void)
{
int fd,f;
@@ -729,8 +732,7 @@ LoadScores()
}
-SaveScores()
-
+static void SaveScores(void)
{
int fd,f;
@@ -744,8 +746,7 @@ SaveScores()
}
-LoadSpritesBW()
-
+static void LoadSpritesBW(void)
{
int f,w,h,x,y;
@@ -754,8 +755,7 @@ LoadSpritesBW()
}
-LoadSprites()
-
+static void LoadSprites(void)
{
XColor xc[256];
XSprite s;
@@ -777,8 +777,7 @@ LoadSprites()
}
-LoadLevelNo()
-
+static void LoadLevelNo(void)
{
FILE *fp;
@@ -794,9 +793,7 @@ LoadLevelNo()
}
-LoadLevel(l)
-int l;
-
+static void LoadLevel(int l)
{
char s[256];
FILE *fp;
@@ -828,7 +825,7 @@ int l;
fgets(s,256,fp);
- s[strlen(s)-1]=NULL;
+ s[strlen(s)-1]=0;
lev.name=strdup(s);
fgets(s,256,fp);
@@ -875,7 +872,7 @@ int l;
for(y=0;y<lev.h;y++)
{
- s[strlen(s)-1]=NULL;
+ s[strlen(s)-1]=0;
if (strlen(s)!=lev.w)
{
fprintf(stderr,"Corrupt level file!\n");
@@ -1038,35 +1035,25 @@ int l;
}
}
-PutX(x,y,n)
+static void PutX(int x, int y, int n)
{
XPut(spr[n].p,0,0,chsz,chsz,X(x),Y(y));
}
-XCentre(s,y,c)
-char *s;
-int y,c;
-
+static void XCentre(const char *s,int y, ulong c)
{
XPrint(X(SCRX)/2-strlen(s)*((font->max_bounds.width)>>1),y,s,c);
}
-CursesCentre(s,y,c)
-char *s;
-int y,c;
-
+static void CursesCentre(const char *s, int y, ulong c)
{
- /* mvaddstr(y,SCRX/2-strlen(s)/2,s); */
mvaddstr(y,COLS/2-strlen(s)/2,s);
}
-DoTillPress(f,s,qf)
-int (*f)();
-int s,qf;
-
+static void DoTillPress(void (*f)(void),int s,int qf)
{
XEvent e;
@@ -1177,8 +1164,7 @@ static struct
};
-int XTitle()
-
+static void XTitle(void)
{
static int fr=True;
static int bln=0;
@@ -1253,8 +1239,6 @@ int XTitle()
}
(*Update)();
-
- return(XFUNCCONT);
}
/* --------------------------------------------------------------------- */
@@ -1266,8 +1250,7 @@ struct
int x,y;
} ispr[INTROSPR];
-XIntroLevel()
-
+static void XIntroLevel(void)
{
static int fr=True;
char s[100];
@@ -1306,14 +1289,11 @@ XIntroLevel()
(*Centre)("Press Space to continue",Y(SCRY-2),white);
(*Update)();
-
- return(XFUNCCONT);
}
/* --------------------------------------------------------------------- */
-int LevelOk()
-
+static void LevelOk(void)
{
static int ix=1;
int x,y;
@@ -1352,8 +1332,7 @@ int LevelOk()
}
-int LevelNotOk()
-
+static void LevelNotOk(void)
{
static int ix=1;
int x,y;
@@ -1392,9 +1371,7 @@ int LevelNotOk()
/* --------------------------------------------------------------------- */
-DrawMess(s)
-char *s;
-
+static void DrawMess(const char *s)
{
if (!cursesmode)
XFillBox(0,0,X(SCRX),Y(1)-1,black);
@@ -1403,8 +1380,7 @@ char *s;
}
-DrawScore()
-
+static void DrawScore(void)
{
if (!cursesmode)
{
@@ -1425,15 +1401,13 @@ DrawScore()
}
-XUpdate()
-
+static void XUpdate(void)
{
Redraw(0,0);
}
-XRepaint(full)
-
+static void XRepaint(int full)
{
static char scr[SCRX][SCRY];
static int lx,ly;
@@ -1527,8 +1501,7 @@ XRepaint(full)
/* --------------------------------------------------------------------- */
#define MOVE_AMOEBA(x,y) ((AT(x,y)==SPACESPR)||(AT(x,y)==EARTHSPR))
-CheckAmoebaMove(x,y)
-
+static int CheckAmoebaMove(int x, int y)
{
int r=False;
@@ -1575,8 +1548,7 @@ CheckAmoebaMove(x,y)
return(r);
}
-HandleAmoeba()
-
+static void HandleAmoeba(void)
{
int f,x,y,d;
@@ -1613,9 +1585,7 @@ HandleAmoeba()
/* --------------------------------------------------------------------- */
-GenerateMonsters(x,y,t)
-int x,y,t;
-
+static void GenerateMonsters(int x, int y, int t)
{
if ((AT(x-1,y)==SPACESPR)&&(no_enemy<MAX_ENEMY))
{
@@ -1667,8 +1637,7 @@ int x,y,t;
}
-HandleGenerators()
-
+static void HandleGenerators(void)
{
Generator *g;
int f;
@@ -1704,10 +1673,7 @@ HandleGenerators()
/* --------------------------------------------------------------------- */
-CheckEnemyMove(e,d)
-Enemy *e;
-int d;
-
+static int CheckEnemyMove(Enemy *e, int d)
{
switch(AT((e)->x+move_tbl[(d)].x,(e)->y+move_tbl[(d)].y))
{
@@ -1733,32 +1699,7 @@ int d;
(c==BUTTSPR)|| \
(c==CHSRSPR))
-HandleEnemies()
-
-{
- int f;
-
- for(f=0;f<no_enemy;f++)
- if (enemy[f].alive)
- switch(enemy[f].type)
- {
- case BUTTSPR:
- HandleButt(&enemy[f]);
- break;
-
- case CHSRSPR:
- HandleChsr_V2(&enemy[f]);
- break;
-
- default:
- break;
- }
-}
-
-
-HandleButt(e)
-Enemy *e;
-
+static void HandleButt(Enemy *e)
{
int x,y,b;
@@ -1795,9 +1736,7 @@ Enemy *e;
}
-HandleChsr(e)
-Enemy *e;
-
+static void HandleChsr(Enemy *e)
{
int x,y,f,od,md;
@@ -1915,9 +1854,7 @@ Enemy *e;
}
-HandleChsr_V2(e)
-Enemy *e;
-
+static void HandleChsr_V2(Enemy *e)
{
int x,y,b;
@@ -1990,9 +1927,7 @@ Enemy *e;
}
-HandleChsr_V1(e)
-Enemy *e;
-
+static void HandleChsr_V1(Enemy *e)
{
switch (AT(e->x,e->y))
{
@@ -2022,9 +1957,31 @@ Enemy *e;
}
+static void HandleEnemies(void)
+{
+ int f;
+
+ for(f=0;f<no_enemy;f++)
+ if (enemy[f].alive)
+ switch(enemy[f].type)
+ {
+ case BUTTSPR:
+ HandleButt(&enemy[f]);
+ break;
+
+ case CHSRSPR:
+ HandleChsr_V2(&enemy[f]);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
/* --------------------------------------------------------------------- */
-CanMove(d)
+static int CanMove(int d)
{
if (d==NONE)
@@ -2073,8 +2030,7 @@ CanMove(d)
}
-CheckEnemies()
-
+static int CheckEnemies(void)
{
int f,x,y;
@@ -2107,9 +2063,7 @@ CheckEnemies()
}
-Handle(c)
-int c;
-
+static int Handle(int c)
{
int x,y;
@@ -2174,9 +2128,7 @@ int c;
}
-HandlePush(d,x,y)
-int d,x,y;
-
+static int HandlePush(int d, int x, int y)
{
int c;
int lx,ly;
@@ -2255,8 +2207,7 @@ int d,x,y;
(b==AMOEBASPR)||(b==ROCKGENSPR)||(b==BUTTGENSPR)||\
(b==CHSRGENSPR))
-Gravity()
-
+static void Gravity(void)
{
int x,y,b,l,r,l2,r2;
@@ -2404,8 +2355,7 @@ Gravity()
}
-XPlayLevel()
-
+static int XPlayLevel(void)
{
XEvent e;
int dir=NONE;
@@ -2669,7 +2619,7 @@ XPlayLevel()
#define PAUSE_X 8
#define PAUSE_Y 8
-char *start_pause_map[PAUSE_SY]=
+static char *start_pause_map[PAUSE_SY]=
{
/* 123456789012345678901234567890 */
" ## # # # ## ### ## ",
@@ -2679,10 +2629,9 @@ char *start_pause_map[PAUSE_SY]=
" # # # # ## ### ## "
};
-int pause_map[PAUSE_SX][PAUSE_SY];
-
-PauseFunc()
+static int pause_map[PAUSE_SX][PAUSE_SY];
+static void PauseFunc(void)
{
int x,y;
@@ -2699,13 +2648,10 @@ PauseFunc()
}
(*Update)();
-
- return(XFUNCCONT);
}
-DoPause()
-
+static void DoPause(void)
{
int x,y;
@@ -2727,21 +2673,18 @@ DoPause()
/* --------------------------------------------------------------------- */
-DoXGameOverLost()
+static void DoXGameOverLost(void)
{
(*Printf)(RND(X(SCRX)),RND(Y(SCRY)),white,"YOU'VE LOST!!!!!");
(*Update)();
-
- return(XFUNCCONT);
}
-XGameOverLost()
-
+static void XGameOverLost(void)
{
- (*Show)(DoXGameOverLost,False);
+ (*Show)(DoXGameOverLost,False,False);
}
/* --------------------------------------------------------------------- */
@@ -2797,7 +2740,7 @@ char *gw_text[NO_GW_LINES]=
"Noddybox",
" ",
"Visit me at",
- "www.noddybox.demon.co.uk",
+ "noddybox.co.uk",
};
int gw_cast_no;
@@ -2809,8 +2752,7 @@ int gw_cast_inc;
int gw_text_no;
int gw_text_ti;
-DoXGameOverWonSmallScale()
-
+static void DoXGameOverWonSmallScale(void)
{
static int la=0;
static int lx=0;
@@ -2859,13 +2801,10 @@ DoXGameOverWonSmallScale()
}
(*Update)();
-
- return(XFUNCCONT);
}
-DoXGameOverWonLargeScale()
-
+static void DoXGameOverWonLargeScale(void)
{
static int la=0;
static char s[100];
@@ -2927,13 +2866,10 @@ DoXGameOverWonLargeScale()
}
(*Update)();
-
- return(XFUNCCONT);
}
-XGameOverWon()
-
+static void XGameOverWon(void)
{
score+=lives*2000;
@@ -2949,29 +2885,31 @@ XGameOverWon()
{
NO_GW_SPR=20;
gw_cast_inc=1;
- (*Show)(DoXGameOverWonSmallScale,False);
+ (*Show)(DoXGameOverWonSmallScale,False,False);
}
else
{
NO_GW_SPR=5;
gw_cast_inc=3;
- (*Show)(DoXGameOverWonLargeScale,False);
+ (*Show)(DoXGameOverWonLargeScale,False,False);
}
}
-XEndWindowing()
+static void XEndWindowing(void)
{
/* X11 cleans up on exit anyway... */
}
/* --------------------------------------------------------------------- */
-int CmpHi(a,b)
-hiscore *a,*b;
-
+static int CmpHi(const void *va,const void *vb)
{
+ const hiscore *a,*b;
int f;
+ a = va;
+ b = vb;
+
(*Cls)(black);
(*Centre)("YOU GOT A HISCORE!!!!!!",Y(1),white);
@@ -2989,8 +2927,7 @@ hiscore *a,*b;
}
-int ShowTable()
-
+static void ShowTable(void)
{
int f;
@@ -3011,8 +2948,7 @@ int ShowTable()
}
-EnterHiscore()
-
+static void EnterHiscore(void)
{
LoadScores();
@@ -3024,35 +2960,31 @@ EnterHiscore()
SaveScores();
- (*Show)(ShowTable,False);
+ (*Show)(ShowTable,False,False);
}
/* --------------------------------------------------------------------- */
-int CursesCls(c)
-int c;
+static void CursesCls(ulong c)
{
erase();
}
-int CursesPut(x,y,c)
-int x,y,c;
+static void CursesPut(int x, int y, int c)
{
mvaddch(y,x,glyph_map[c]);
}
-int CursesRedraw()
+static void CursesRedraw(void)
{
move(LINES-1,COLS-1);
refresh();
}
-int CursesRepaint(full)
-int full;
-
+static void CursesRepaint(int full)
{
int x,y,px,py;
@@ -3075,7 +3007,7 @@ int full;
}
-int CursesPrintf(int x, int y, int c, const char *fmt, ...)
+static void CursesPrintf(int x, int y, ulong c, const char *fmt, ...)
{
char s[128];
va_list l;
@@ -3090,7 +3022,7 @@ int CursesPrintf(int x, int y, int c, const char *fmt, ...)
}
-int CursesIntroLevel()
+static void CursesIntroLevel(void)
{
char s[128];
@@ -3105,12 +3037,10 @@ int CursesIntroLevel()
(*Centre)("Press Space to continue",Y(SCRY-2),white);
(*Update)();
-
- return(XFUNCCONT);
}
-int CursesPlayLevel()
+static int CursesPlayLevel(void)
{
int dir=NONE;
int x,y,ok,ls,kp,kpm,dt,ti;
@@ -3280,7 +3210,7 @@ int CursesPlayLevel()
}
-int _CursesGameOverWon()
+static void SubCursesGameOverWon(void)
{
static unsigned int c;
@@ -3303,13 +3233,13 @@ int _CursesGameOverWon()
}
-int CursesGameOverWon()
+static void CursesGameOverWon(void)
{
- (*Show)(_CursesGameOverWon,False,False);
+ (*Show)(SubCursesGameOverWon,False,False);
}
-int _CursesGameOverLost()
+static void SubCursesGameOverLost(void)
{
static unsigned int c;
@@ -3326,16 +3256,13 @@ int _CursesGameOverLost()
}
-int CursesGameOverLost()
+static void CursesGameOverLost(void)
{
- (*Show)(_CursesGameOverLost,False,False);
+ (*Show)(SubCursesGameOverLost,False,False);
}
-int CursesDoTillPress(f,s,q)
-int (*f)();
-int s,q;
-
+static void CursesDoTillPress(void (*f)(void), int s, int q)
{
chtype ch;
@@ -3362,7 +3289,7 @@ int s,q;
}
-CursesEndWindowing()
+static void CursesEndWindowing(void)
{
(*Cls)(black);
(*Update)();
@@ -3372,9 +3299,7 @@ CursesEndWindowing()
/* --------------------------------------------------------------------- */
-int Exit(n)
-int n;
-
+static void Exit(int n)
{
if (EndWindowing)
(*EndWindowing)();
@@ -3385,9 +3310,7 @@ int n;
#ifdef NOUSLEEP
-LocalUsleep(u)
-int u;
-
+LocalUsleep(int u)
{
struct timeval tv;