#ifndef BLOCKADE_H
#define BLOCKADE_H

#include <stdio.h>

#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
#include <X11/Xresource.h>

#define BOARD_X 15
#define BOARD_Y 9

struct button_ {
  char *text;
  int (*callback)();
  Window win;
  XCharStruct textbound;
  int w;
  int h;
  int x;
  int y;
  int textx;
  int texty;
  } ;
typedef struct button_ BUTTON;

struct level_ {
  int levelno;
  struct level_seg_ *seg;
  char *name;
  int namelen;
  XCharStruct namesize;
  char layout[BOARD_Y][BOARD_X];
  } ;
typedef struct level_ LEVEL;

struct level_seg_ {
  int first;
  int num;
  int last;
  char *source;
  LEVEL **levels;
  int dirty;
  struct level_seg_ *link;
  } ;
typedef struct level_seg_ LEVEL_SEG;

void saveargv(int ac,char **av);
void addargfile(char *fn);
void handleargs(int ac,char **av);
void setlevel(char *s);
void maybeset(char **strp,char *str);
void setup_levels(void);
void setup_db(void);
void getcolor(XColor *col);
void setup_color(char *str,XColor *col);
void setup_visual(void);
void setup_font(void);
void setup_colors(void);
void setup_numbers(void);
void setup_wingc(void);
void setup_pixmaps(void);
void setup_sizes(void);
void setup_buttons(void);
void setup_windows(void);
void setup_game(void);
int set_sq_bl(int bi,int *sqp,int *blp,int *stp);
void initlevel(void);
void run(void);
void handle_event(XEvent *e);
void docmd(KeySym ks,unsigned int state,int nc,char *str);
void change_curpic(int d);
void edit_set(int x,int y);
void edit_move(int dx,int dy);
void asklevel(void);
void asklevel_done(void);
void beginhelp(void);
void sethelp(int n);
void endhelp(void);
void undopush(void);
void resetlevel(void);
void level_juggle(char (*bl)[BOARD_Y],int *pxp,int *pyp,int swap);
void nextlevel(void);
void redraw(void);
void pushsave(void);
int do_move(int dx,int dy);
void cmd_move(int dx,int dy);
void do_teleport(int fx,int fy);
void edit_ask_resize(void);
void resize(int tw,int th);
void redisplay(Window win,int x,int y,int w,int h,int count);
void damage_editwin(int x,int y,int w,int h);
void fix_edit_damage(void);
void draw_levprompt(void);
void draw_msg(void);
void update_textpanel(Window win,unsigned char *bits,int x,int y,int w,int h);
void update_textpanel_pix(Window win,int *pv);
void pickpic(int x,int y);
void motion(Window win,int x,int y,unsigned int state);
void mousegame(int x,int y);
void mouseedit(int x,int y);
void damage_gamewin(int x,int y,int w,int h);
void fix_damage(void);
void redraw_text(void);
void redraw_button(BUTTON *b);
void redraw_help_button(BUTTON *b);
void text_center(char *str,int len,int y);
void drawsq(int x,int y);
void setdispstate(int new);
void set_msg_size(void);
void place_msgwin(void);
void begin_edit(void);
void finish_edit(void);
void fwrite_level(FILE *f,LEVEL *l);
void saveseg(LEVEL_SEG *seg);
void showcredits(void);
void levname_begin(void);
void levname_done(int saveit);
void reset_sizes(void);
void clonelevel(void);
void junklevel(void);
int buttondown(Window win,int x,int y,unsigned int state,unsigned int button);
#endif
