#ifndef __BRIKXH__
#define __BRIKXH__

//#define WIZRES

#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"

#define VERSION         "0.4.2"

#ifdef	WIZ
#define WIZRES
#endif

#ifdef	WIZRES
#define WIDTH           320
#define HEIGHT          240
#else
#define WIDTH           640
#define HEIGHT          480
#endif

#ifdef	WIZ
#define BPP             16
#else
#define BPP             32
#endif

#define NAME_MAXLEN     16
#define MAX_HIGHENTRIES 20
#define BACKGROUND_MAX  50
#define MAX_TILES       99

#ifdef	WIZRES
#define TILE_WIDTH      30
#define TILE_HEIGHT     30
#else
#define TILE_WIDTH      60
#define TILE_HEIGHT     60
#endif

#define WINDOWX         0
#define WINDOWY         0
#define TILESET_DEFAULT "stone"

#ifdef	WIZ
#define	DELAY			40
#else
#define DELAY           20
#endif

#define TILE_EMPTY      0
#define TILE_WALL       1
#define TILE_RIGHT      2
#define TILE_LEFT       3
#define TILE_PEAK       4
#define TILE_PRIORRIGHT 5
#define TILE_PRIORLEFT  6
#define TILE_STRONG     7
#define TILE_STRONGRANDOM 10
#define TILE_STRONGPRIORRIGHT 8
#define TILE_STRONGPRIORLEFT 9
#define TILE_LEVITATOR  11
#define TILE_PAINTER    12
#define TILE_DESTRUCTOR 13
#define TILE_DEAD       99
#define TILE_FIRST	    40
#define IsTile(a)       ((a)>=TILE_FIRST)
#define IsLivingTile(a) ((a)>=TILE_FIRST && (a)!=TILE_DEAD)
#define IsEmpty(a)      ((a)==TILE_EMPTY)
#define IsWeak(a)       ((a)==TILE_WALL || (a)==TILE_RIGHT || (a)==TILE_LEFT || (a)==TILE_PEAK || (a)==TILE_PRIORRIGHT || (a)==TILE_PRIORLEFT)
#define IsRYB(a)        ((a)>=TILE_FIRST && (a)<=TILE_FIRST+2)

#define DIR_DATA        "data/"
#define DIR_LEVEL       DIR_DATA"levels/"
#define DIR_MUSIC       DIR_DATA"music/"
#define DIR_SOUND       DIR_DATA"sounds/"
#define DIR_FONT        DIR_DATA"fonts/"
#define FILE_HIGH       DIR_DATA"high/high.dat"
#define FONTNAME_SCORE  DIR_FONT"bankgothic.ttf"
#define FONTNAME_NORMAL DIR_FONT"bankgothic.ttf"

#ifdef	WIZRES
#define DIR_BACKGROUND  DIR_DATA"backgrounds-wiz/"
#define DIR_IMAGE       DIR_DATA"images-wiz/"
#define DIR_TILESET     DIR_DATA"tilesets-wiz/"
#define DIR_HELP        DIR_DATA"help-wiz/"
#else
#define DIR_BACKGROUND  DIR_DATA"backgrounds/"
#define DIR_IMAGE       DIR_DATA"images/"
#define DIR_TILESET     DIR_DATA"tilesets/"
#define DIR_HELP        DIR_DATA"help/"
#endif

#ifdef	WIZRES
#define FONTSIZE_SCORE  12
#define FONTSIZE_SMALL  7
#else
#define FONTSIZE_SCORE  20
#define FONTSIZE_SMALL  14
#endif

#define MODES   9

#define BACKGROUND_MENU DIR_IMAGE"title_background.jpg"
#define BACKGROUND_BASE DIR_IMAGE"play_sidebar.png"
#define BACKGROUND_EDIT DIR_IMAGE"edit.png"
#define BACKGROUND_BYE  DIR_IMAGE"bye.jpg"
#define IMAGE_GAMECURSOR    DIR_IMAGE"cursor.png"
#define IMAGE_QUIT      DIR_IMAGE"menu_quit.png"
#define IMAGE_PLAY      DIR_IMAGE"menu_play.png"
#define IMAGE_CONTINUE  DIR_IMAGE"menu_continue.png"
#define IMAGE_EDIT      DIR_IMAGE"menu_edit.png"
#define IMAGE_YES       DIR_IMAGE"menu_yes.png"
#define IMAGE_NO        DIR_IMAGE"menu_no.png"
#define IMAGE_HELP      DIR_IMAGE"menu_help.png"
#define IMAGE_HIGHS     DIR_IMAGE"menu_highs.png"
#define IMAGE_ASKQUIT   DIR_IMAGE"ask_quit.png"
#define IMAGE_OPTIONS   DIR_IMAGE"menu_options.png"
#define IMAGE_BUILD     DIR_IMAGE"button_build.png"
#define IMAGE_CLEAR     DIR_IMAGE"button_clear.png"
#define IMAGE_NORMAL    DIR_IMAGE"button_normal.png"
#define IMAGE_PUSH      DIR_IMAGE"button_push.png"
#define IMAGE_SWAP      DIR_IMAGE"button_swap.png"
#define IMAGE_HELPBUTTON DIR_IMAGE"help.png"
#define IMAGE_AUTORELOAD DIR_IMAGE"menu_autoreload.png"
#define IMAGE_AUTONORMAL DIR_IMAGE"menu_autonormal.png"
#define IMAGE_UNDO      DIR_IMAGE"button_undo.png"
#define IMAGE_SAVEBUTTON DIR_IMAGE"button_save.png"
#define IMAGE_FULLSCREEN DIR_IMAGE"menu_fullscreen.png"
#define IMAGE_TILESET   DIR_IMAGE"menu_tileset.png"
#define IMAGE_DIFFICULTY DIR_IMAGE"menu_difficulty.png"
#define IMAGE_BGALPHA   DIR_IMAGE"menu_bgalpha.png"
#define IMAGE_CURSOR    DIR_IMAGE"menu_cursor.png"
#define IMAGE_BACK      DIR_IMAGE"menu_back.png"
#define IMAGE_TICK      DIR_IMAGE"tick.png"
#define IMAGE_CROSS     DIR_IMAGE"cross.png"
#define IMAGE_EDITPLAY	DIR_IMAGE"play.png"
#define IMAGE_MAXIMUMS  DIR_IMAGE"max.png"
#define IMAGE_LOAD	    DIR_IMAGE"load.png"
#define IMAGE_SAVE	    DIR_IMAGE"save.png"
#define IMAGE_CLOCK	    DIR_IMAGE"clock.png"
#define IMAGE_TIMER	    DIR_IMAGE"timer.png"
#define IMAGE_SAND 	    DIR_IMAGE"sand.png"
#define IMAGE_RELOAD	DIR_IMAGE"reload.png"
#define IMAGE_SHINE     DIR_IMAGE"shine"
#define IMAGE_TOOLCURSOR DIR_IMAGE"tools_cursor.png"
#define SHINE_FRAMES    70
#define SHINE_SPEED     30
#define MUSIC_PLAY      DIR_MUSIC"brikx.xm"

#ifdef	WIZ
#define ALPHA1	255
#define ALPHA2  255
#else
#define ALPHA1	80
#define ALPHA2  160
#endif

#define	AUDIO_RATE				44100
#define	AUDIO_FORMAT			AUDIO_S16
#define AUDIO_CHANNELS			2
#define	AUDIO_BUFFERS			1024

#define SOUND_BALL DIR_SOUND"ball.wav"
#define SOUND_DISAPPEAR DIR_SOUND"disappear.wav"

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define           rmask (0xff000000)
#define           gmask (0x00ff0000)
#define           bmask (0x0000ff00)
#define           amask (0x000000ff)
#else
#define           rmask (0x000000ff)
#define           gmask (0x0000ff00)
#define           bmask (0x00ff0000)
#define           amask (0xff000000)
#endif

struct high_entry
{
    long score;
    int level,difficulty;
    char name[NAME_MAXLEN+1];
};


typedef high_entry high[MAX_HIGHENTRIES];
typedef int level[8][8];
typedef int maxes[MODES];

char *configdir();
int strcmpi(const char *a1, const char *a2);
SDL_Surface *LoadImage(char *fname,int Rkey=-1,int Gkey=-0,int Bkey=0);
void PutSurface(SDL_Surface *src,SDL_Surface *dest,SDL_Rect pos,int clipx=-1,int clipy=-1,int width=-1,int height=-1);
void PutSurface(SDL_Surface *src,SDL_Surface *dest,int x=0,int y=0,int clipx=-1,int clipy=-1,int width=-1,int height=-1);
int LoadLevel(char *fname,level &t,maxes &m,char *text=NULL);
int SaveLevel(char *fname,level t,int timelimit,maxes m,char *text=NULL);
int Input(SDL_Surface *screen,TTF_Font *font,SDL_Color color,int x,int y,char *s,int maxlen);
int SaveHigh(long score,int level,int difficulty,char *name);
int SaveGame(level table,long score,int levnum,long timer,int timelimit,int diff,maxes m,char *name="0",char *leveltext=NULL);
int LoadGame(level &table,long &score,int &levnum,long &timer,int &timelimit,int &diff,maxes &m,char *name="0",char *leveltext=NULL);
int LoadShinePos(char *fname,int &dx,int &dy);
void GetNextSet(char *name);
#endif
