/*
 *
 * funddefs.h -- fundamental defitions
 *
 * This code is copyright 1994 by James A. Cherry, jac@doe.carleton.ca.
 * It is not to be redistributed or modified without his permission.
 *
 */

#include <curses.h>
#include <string.h>
#include <malloc.h>
#include <signal.h>
#ifdef  BSD
#include <sys/time.h>
#else   /* USG */
#define index   strchr
#define srandom srand48
#define random  lrand48
long srand48();
long lrand48();
#endif  /* USG */

/* Maximum word length */
#define MAX_WLEN 32

/* Symbols for characters on board */
#define CH_EM '.'
#define CH_DL '\''
#define CH_TL '"'
#define CH_DW '-'
#define CH_TW '='
#define CH_BL '?'
#define CH_UN '-'

/* Structure for storing new words formed */
struct another_word {
    int startx;
    int starty;
    int dir;
    int length;
    int blankloc;
    int score;
    char letters[16];
};

/* Structure for saying where a letter from the rack is on the board */
struct plrlet {
    int x;          /* column */
    int y;          /* row */
    char letter;    /* tile (A-Z or ?) */
    char blankchar; /* letter represented by ? */
    char oldlet;    /* letter that was previously there */
    int tilepos;    /* index into rack of this tile */
};

/* Structure for storing a possible move */
typedef struct cm {
    struct cm *next;         /* pointer to next entry */
    struct plrlet newlet[7]; /* letters played and their locations */
    int placed;              /* tiles placed (>0 play, <0 dump, =0 pass) */
    int dir;                 /* direction (0=horizontal, 1=vertical) */
    int score;               /* play score + rack leave score */
    int rms;                 /* rack leave score only */
    int winout;              /* 1 when an outplay wins the game */
} compmove;

#define CM_SIZE		( sizeof( compmove ) )

/* Structure for things received from the socket */
typedef struct rs {
    struct rs *next;
    char *string;
} recstr;

/* Structure for tile count and value */
struct let_distrib {
    int tiles;  /* number of tiles */
    int points; /* value of tile */
};

/* Structure for storing state information */
typedef struct ss {
    int state;          /* state number */
    void (*function)(); /* address of function that implements state */
} sstruct;

/* State numbering */
#define AWAIT_CONNECT              1
#define AWAIT_LOGIN                2
#define AWAIT_ARRIVE               3
#define IDLE_FOR_GAME              4
#define AWAIT_JOIN                 5
#define AWAIT_FLIP                 6
#define AWAIT_ME_JOIN              7
#define AWAIT_THEM_JOIN            8
#define START_GAME                 9
#define THEIR_MOVE                 10
#define CHECK_REALLY_OUT           11
#define CHECK_WORDS                12
#define INITIATE_CHALLENGE         13
#define AWAIT_PAUSE                14
#define AWAIT_RULING               15
#define AWAIT_WITHDRAW             16
#define AWAIT_ME_START_THEIR_CLOCK 17
#define MY_MOVE_F                  18
#define AWAIT_ME_DONE_TURN         19
#define AWAIT_PASS                 20
#define END_OF_GAME                21
#define AWAIT_REMATCH              22
#define CONSULT_MODE               23
#define THEIR_COMMIT               100 /* kluge for `resume' */
#define THEIR_END                  101 /* kluge for `resume' */

#define START_STATE                AWAIT_CONNECT
#define NUM_STATES                 23

/* DOoM numbers */
#define MARLDOOM 1
#define POSLDOOM 2
#define WISDOOM  3
#define DDDOOM   4

/* Keep a logfile? */
#define LOG_YES 1
#define LOG_NO  2

