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