1/********************************************************************* 2* $Id: sweep.h.in,v 1.36 2002-12-21 21:32:09 hartmann Exp $ 3*********************************************************************/ 4 5#ifndef __SWEEP_H__ 6#define __SWEEP_H__ 7 8#include "config.h" 9 10#define mkstr2(s) mkstr(s) 11#define mkstr(s) # s 12 13/* The library header files. */ 14#ifdef HAVE_UNISTD_H 15#include <unistd.h> 16#endif /* HAVE_UNISTD_H */ 17 18#ifdef HAVE_STRING_H 19#include <string.h> 20#endif /* HAVE_STRING_H */ 21 22#ifdef HAVE_GETOPT_H 23#include <getopt.h> 24#endif /* HAVE_GETOPT_H */ 25 26#ifdef HAVE_ERRNO_H 27#include <errno.h> 28#endif /* HAVE_ERRNO_H */ 29 30#include <stdlib.h> 31#include <stdio.h> 32#include <ctype.h> 33#include <sys/types.h> 34#include <sys/stat.h> 35#include <time.h> 36#include <assert.h> 37#include <math.h> 38#include <stdarg.h> 39#include <signal.h> 40 41#ifdef HAVE_LIBNCURSES 42#include "@NCURSES_INCLUDE@/ncurses.h" 43#define DEFAULT_LINEDRAW 1 44#else /* HAVE_LIBNCURSES */ 45#include <curses.h> 46#define DEFAULT_LINEDRAW 0 47#endif /* HAVE_LIBNCURSES */ 48 49#if defined HAVE_FLOCK && defined HAVE_SYS_FILE_H 50#include <sys/file.h> 51#endif 52 53#if defined(HAVE_LIMITS_H) 54#include <limits.h> 55#endif 56 57/* XXX make this work with configure */ 58#include <sys/types.h> 59#include <dirent.h> 60 61#ifdef NCURSES_MOUSE_VERSION 62#define SWEEP_MOUSE 63#endif /* NCURSES_MOUSE_VERSION */ 64 65#if defined SCORESDIR 66#define USE_GROUP_BEST_FILE 67#endif 68 69#include "defaults.h" 70 71/* These are all the defines used in freesweep */ 72/* These are defines for convenience */ 73#define DELIMITERS " \t=" 74#define DFL_GROUP_PATH "@SCORESDIR@" 75#define MAGIC_NUMBER 128 76 77#ifdef __CYGWIN__ 78#define DFL_PREFS_FILE "_sweeprc" 79#define DFL_BESTS_FILE "_sweeptimes" 80#else 81#define DFL_PREFS_FILE ".sweeprc" 82#define DFL_BESTS_FILE ".sweeptimes" 83#endif /* __CYGWIN__ */ 84 85#define GLOBAL_PREFS_FILE "@PREFSDIR@/sweeprc" 86 87/* used for the superclick feature in the game */ 88#define SUPERCLICK 0 89#define DIE 1 90#define DONOTHING 2 91 92/* These are defines for maximum accepted values */ 93#define MAX_LINE 1024 94#define MAX_H 2048 95#define MAX_W 2048 96#define L_MAX_H 4 97#define L_MAX_W 4 98#define INFO_W 21 99#define MAX_NAME 80 100#define MAX_DATE 26 101 102/* These are the macros for cell values. */ 103#define UNKNOWN 0x0 104#define MINE 0x9 105#define MARKED 0xa 106#define BAD_MARK 0xb 107#define EMPTY 0xc 108#define DETONATED 0xd 109 110/* These are for winning and losing. */ 111#define INPROG 0 112#define WIN 1 113#define LOSE 2 114#define ABORT 3 115#define RECONF 4 116 117/* These are for the alert types. */ 118#define BEEP 0 119#define FLASH 1 120#define NO_ALERT 2 121 122/* These are the macros that reduce the memory usage by *half*. */ 123#define GetMine(x,y,ret) \ 124 ret=(unsigned char)(!((ret)=Game->Field[((x)/2+(y)*( ( Game->Width +1 )/2))])\ 125 ?UNKNOWN:((x)%2)?(ret)&0x0f:((ret)&0xf0)>>4) 126 127#define SetMine(x,y,val) \ 128 Game->Field[((x)/2)+(y)*( ( Game->Width +1 )/2)]=(!((x)%2)?((Game->Field[((x)\ 129 /2)+(y)*( ( Game->Width +1 )/2)]&0x0f)|((unsigned char)(val)<<4)):\ 130 ((Game->Field[((x)/2)+(y)*( ( Game->Width +1 ) /2)]&0xf0)|((unsigned char)(val)\ 131 &0x0f))) 132 133/* This extends the naming convention of ncurses functions. */ 134#define mvclrtoeol(y,x) (move(y,x)==ERR?ERR:clrtoeol()); 135#define noutrefresh() wnoutrefresh(stdscr) 136 137#ifndef mvwhline 138#define mvwhline(w,y,x,z,n) (wmove(w,y,x)==ERR?ERR:whline(w,z,n)); 139#endif /* mvwhline */ 140 141#ifndef mvwvline 142#define mvwvline(w,y,x,z,n) (wmove(w,y,x)==ERR?ERR:wvline(w,z,n)); 143#endif /* mvwvline */ 144 145#ifndef mvgetnstr 146#define mvgetnstr(y, x, str, n) (wmove(stdscr, y, x)==ERR?ERR:wgetnstr(stdscr, str, n)); 147#endif /* mvgetnstr */ 148 149#ifndef ValidCoordinate 150#define ValidCoordinate(x,y) ( ( (x>=0) && (x<Game->Width) && (y>=0) && (y<Game->Height) ) ? 1 : 0 ) 151#endif 152 153/* These are all the structs used in freesweep */ 154/* This is the struct containing all the various drawing characters. */ 155typedef struct _DrawChars 156{ 157 chtype ULCorner; 158 chtype URCorner; 159 chtype LLCorner; 160 chtype LRCorner; 161 chtype HLine; 162 chtype VLine; 163 chtype UArrow; 164 chtype DArrow; 165 chtype LArrow; 166 chtype RArrow; 167 chtype Mine; 168 chtype Space; 169 chtype Mark; 170 chtype FalseMark; 171 chtype Bombed; 172} DrawChars; 173 174/* This is the struct containing all the relevant game information. */ 175typedef struct _GameStats 176{ 177 int Height; 178 int Width; 179 int Percent; 180 unsigned int NumMines; 181 unsigned int MarkedMines; 182 unsigned int BadMarkedMines; 183 int Color; 184 int Fast; 185 int Alert; 186 int LineDraw; 187 int CursorX, CursorY; 188 int LargeBoardX, LargeBoardY; 189 int Status; 190 unsigned int FocusX, FocusY; 191 unsigned int Time; 192 unsigned char* Field; 193 WINDOW* Border; 194 WINDOW* Board; 195} GameStats; 196 197/* This is the struct for the clearing algo. */ 198struct Mark 199{ 200 int x, y; 201 struct Mark *next; 202}; 203 204/* this is the _NEW_ format for the best times score */ 205struct BestEntry 206{ 207 unsigned int area; 208 unsigned int mines; 209 unsigned int time; 210 211 char name[MAX_NAME]; 212 char date[MAX_DATE]; 213 char *attribs; 214}; 215 216struct BestFileDesc 217{ 218 /* the array of entries from the file, with one more in it. */ 219 struct BestEntry *ents; 220 221 /* the number of entries in the descriptor */ 222 int numents; 223 224 /* did I replace, or add? */ 225 int replflag; 226}; 227 228typedef struct _CoordPair 229{ 230 int CoordX, CoordY; 231} CoordPair; 232 233/* stuff needed for the file gui */ 234/* this is not very well designed, but oh well */ 235struct FileBuf 236{ 237 char *fpath; 238 char *path; 239 int numents; 240 struct FileBuf *next; 241 struct FileBuf *prev; 242}; 243 244 245#ifdef DEBUG_LOG 246FILE* DebugLog; 247#endif /* DEBUG_LOG */ 248 249extern DrawChars CharSet; 250 251/* These are the functions defined in files.c */ 252int SourceHomeFile(GameStats* Game); 253int SourceGlobalFile(GameStats* Game); 254int SourceFile(GameStats* Game,FILE* PrefsFile); 255int WritePrefsFile(GameStats* Game); 256int OldPrefsFile(GameStats* Game); 257 258/* These are the functions defined in drawing.c */ 259void StartCurses(); 260void PrintInfo(); 261void AskPrefs(GameStats* Game); 262void Help(); 263void PrintBestTimes(char* FileName); 264int DrawBoard(GameStats* Game); 265void DrawCursor(GameStats* Game); 266void UndrawCursor(GameStats* Game); 267int Pan(GameStats* Game); 268int Center(GameStats* Game); 269int CenterY(GameStats* Game); 270int CenterX(GameStats* Game); 271 272/* These are the functions defined in game.c */ 273int CheckColor(int NewVal); 274int CheckFast(int NewVal); 275int CheckHeight(int NewVal); 276int CheckLineDraw(int NewVal); 277int CheckNumMines(int NewVal, int Height, int Width); 278int CheckPercent(int NewVal); 279int CheckWidth(int NewVal); 280int InitGame(GameStats* Game); 281int ReadyGame(GameStats* Game); 282void SwitchCharSet(GameStats* Game); 283int InitCharSet(GameStats* Game,int Value); 284void SetCharSet(int Value); 285int ParseArgs(GameStats* Game, int Argc, char** Argv); 286void DumpGame(GameStats* Game); 287int ReReadyGame(GameStats* Game); 288void Wipe(GameStats *Game); 289 290/* These are the functions defined in play.c */ 291int GetInput(GameStats* Game); 292void MoveLeft(GameStats* Game, int Num); 293void MoveRight(GameStats* Game, int Num); 294void MoveUp(GameStats* Game, int Num); 295void MoveDown(GameStats* Game, int Num); 296void Boom(void); 297void YouWin(void); 298int ClickSquare(GameStats* Game, int ThisX, int ThisY); 299int DoubleClickSquare(GameStats* Game, int ThisX, int ThisY); 300 301/* These are the functions defined in error.c */ 302void SweepError(char* format, ...); 303int InitErrorWin(GameStats* Game); 304void ClearError(); 305int RedrawErrorWin(); 306void SweepAlert(); 307void SweepMessage(char* format, ...); 308void ChangeSweepAlert(int NewAlert); 309 310/* These are the functions defined in stats.c */ 311void PrintStats(GameStats *Game); 312int InitStatsWin(void); 313int RedrawStatsWin(void); 314 315/* These are the functions described in utils.c */ 316void* xmalloc(size_t num); 317char* xgetcwd(char *buf, size_t size); 318DIR* xopendir(const char *buf); 319void StartTimer(void); 320void StopTimer(void); 321 322/* this is in pbests.c, which will eventually become bests.c */ 323void UpdateBestTimesFile(GameStats *Game, char *filename); 324char* FPTBTF(void); 325#if defined USE_GROUP_BEST_FILE 326char* FPTGBTF(void); 327#endif 328 329/* These are the functions defined in clear.c */ 330void InsertMark(struct Mark **ht, int x, int y); 331char DeleteRandomMark(struct Mark **ht, int *x, int *y); 332void Clear(GameStats *Game); 333void SuperClear(GameStats *Game); 334int FindNearest(GameStats *Game); 335int FindNearestBad(GameStats *Game); 336 337/* These are the functions in fgui.c */ 338char* FSGUI(void); 339 340/* macros to lookup crap in the look up table for the clearing algo */ 341#define LOOKUP(t, xx, yy) \ 342 (unsigned char)((t)[(xx)/8 + yy * g_table_w]) & \ 343 (((unsigned char)0x80)>>((xx)%8)) 344 345#define SET(t, xx, yy) \ 346 ((t)[(xx)/8 + yy * g_table_w]) |= \ 347 (((unsigned char)0x80)>>((xx)%8)) 348 349#define UNSET(t, xx, yy) \ 350 ((t)[(xx)/8 + yy * g_table_w]) &= \ 351 ~(((unsigned char)0x80)>>((xx)%8)) 352 353/* functions defined in sl.c for save/load games */ 354void SaveGame(GameStats* Game, char *fname); 355GameStats* LoadGame(char *fname); 356 357/* functions defined in gpl.c */ 358void PrintGPL(); 359 360/* functions defined in tick.c */ 361extern volatile unsigned int g_tick; 362RETSIGTYPE sighandler(int signo); 363 364/* functions in image.c */ 365void SaveGameImage(GameStats* Game, char *fname); 366 367#endif /* __SWEEP_H__ */ 368