1 /*-
2 # X-BASED MISSING LINK(tm)
3 #
4 #  MlinkP.h
5 #
6 ###
7 #
8 #  Copyright (c) 1994 - 99	David Albert Bagley, bagleyd@tux.org
9 #
10 #                   All Rights Reserved
11 #
12 #  Permission to use, copy, modify, and distribute this software and
13 #  its documentation for any purpose and without fee is hereby granted,
14 #  provided that the above copyright notice appear in all copies and
15 #  that both that copyright notice and this permission notice appear in
16 #  supporting documentation, and that the name of the author not be
17 #  used in advertising or publicity pertaining to distribution of the
18 #  software without specific, written prior permission.
19 #
20 #  This program is distributed in the hope that it will be "playable",
21 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
22 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 #
24 */
25 
26 /* Private header file for Mlink */
27 
28 #ifndef _MlinkP_h
29 #define _MlinkP_h
30 
31 #include "Mlink.h"
32 
33 /*** random number generator ***/
34 #if HAVE_RAND48
35 #define SRAND srand48
36 #define LRAND lrand48
37 #define MAXRAND (2147483648.0)
38 #else /* HAVE_RAND48 */
39 #if HAVE_RANDOM
40 #define SRAND srand48
41 #define LRAND lrand48
42 #define MAXRAND (2147483648.0)
43 #else /* HAVE_RANDOM */
44 #if HAVE_RAND
45 #define SRAND srand48
46 #define LRAND lrand48
47 #ifdef AIXV3
48 #define MAXRAND (2147483648.0)
49 #else
50 #define MAXRAND (32768.0)
51 #endif
52 #endif /* HAVE_RAND */
53 #endif /* HAVE_RANDOM */
54 #endif /* HAVE_RAND48 */
55 
56 #ifndef SRAND
57 extern void SetRNG(long int s);
58 
59 #define SRAND(X) SetRNG((long) X)
60 #endif
61 #ifndef LRAND
62 extern long LongRNG(void);
63 
64 #define LRAND() LongRNG()
65 #endif
66 #ifndef MAXRAND
67 #define MAXRAND (2147483648.0)
68 #endif
69 
70 #define NRAND(X) ((int)(LRAND()%(X)))
71 
72 #define SYMBOL ':'
73 
74 #define TOP 0
75 #define RIGHT 1
76 #define BOTTOM 2
77 #define LEFT 3
78 #define COORD 4
79 
80 /* The following are in xmlink.c also */
81 #define MINFACES 1
82 #define MAXFACES 8
83 #define MINTILES 1
84 
85 #define DEFAULTTILES 4
86 #define DEFAULTFACES 4
87 
88 #define ABS(a) (((a)<0)?(-a):(a))
89 #define SIGN(a) (((a)<0)?(-1):1)
90 #define MIN(a,b) (((int)(a)<(int)(b))?(int)(a):(int)(b))
91 #define MAX(a,b) (((int)(a)>(int)(b))?(int)(a):(int)(b))
92 
93 typedef struct _MlinkPart {
94 	Pixel       foreground;
95 	Pixel       tileColor, borderColor;
96 	Pixel       faceColor[MAXFACES];
97 	int        *tileOfPosition, spacePosition;
98 	int         currentTile, currentFace, currentRef;
99 	Boolean     started, orient, mono, reverse, middle;
100 	int         depth;
101 	int         base;
102 	int         tiles, faces, tileFaces;
103 	XPoint      offset, tileSize, faceSize, puzzleSize;
104 	XPoint      delta, puzzleOffset, digitOffset;
105 	GC          puzzleGC;
106 	GC          tileGC;
107 	GC          borderGC;
108 	GC          faceGC[MAXFACES];
109 	GC          inverseGC;
110 	String      faceName[MAXFACES];
111 	char       *username;
112 	XtCallbackList select;
113 } MlinkPart;
114 
115 typedef struct _MlinkRec {
116 	CorePart    core;
117 	MlinkPart   mlink;
118 } MlinkRec;
119 
120 /* This gets around C's inability to do inheritance */
121 typedef struct _MlinkClassPart {
122 	int         ignore;
123 } MlinkClassPart;
124 
125 typedef struct _MlinkClassRec {
126 	CoreClassPart core_class;
127 	MlinkClassPart mlink_class;
128 } MlinkClassRec;
129 
130 extern MlinkClassRec mlinkClassRec;
131 extern int *startPosition;
132 
133 extern Boolean MoveMlink(MlinkWidget w, int direction, int tile, int shift);
134 
135 #if 0
136 extern void SolveTiles();	/* For future auto-solver */
137 
138 #endif
139 extern void DrawAllTiles(MlinkWidget w);
140 extern Boolean CheckSolved(MlinkWidget w);
141 extern void InitMoves(void);
142 extern void PutMove(int direction, int tile, int control);
143 extern void GetMove(int *direction, int *tile, int *control);
144 extern int  MadeMoves(void);
145 extern void FlushMoves(MlinkWidget w);
146 extern int  NumMoves(void);
147 extern void ScanMoves(FILE * fp, MlinkWidget w, int moves);
148 extern void PrintMoves(FILE * fp);
149 extern void ScanStartPosition(FILE * fp, MlinkWidget w);
150 extern void PrintStartPosition(FILE * fp, MlinkWidget w);
151 extern void SetStartPosition(MlinkWidget w);
152 
153 #endif /* _MlinkP_h */
154