1 /*-
2 # X-BASED DINOSAUR CUBE
3 #
4 #  DinoP.h
5 #
6 ###
7 #
8 #  Copyright (c) 1995 - 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 Dino */
27 
28 #ifndef _DinoP_h
29 #define _DinoP_h
30 
31 #include "Dino.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 IGNORE (-1)
75 #define TR 0
76 #define BR 1
77 #define BL 2
78 #define TL 3
79 #define STRT 4
80 #define CW 5
81 #define HALF 6
82 #define CCW 7
83 #define TOP 8
84 #define RIGHT 9
85 #define BOTTOM 10
86 #define LEFT 11
87 #define MAXORIENT 4
88 #define MAXROTATE 3
89 #define CORNER 0
90 #define MIDDLE 1
91 #define EDGE 2
92 #define FACE 3
93 
94 /* The following are in xdino.c also */
95 #define PERIOD2 2
96 #define PERIOD3 3
97 #define BOTH 4
98 #define MAXMODES 3
99 #define MAXFACES 6
100 
101 #define DEFAULTMODE PERIOD3
102 
103 #define MIN(a,b) (((int)(a)<(int)(b))?(int)(a):(int)(b))
104 #define MAX(a,b) (((int)(a)>(int)(b))?(int)(a):(int)(b))
105 
106 typedef struct _DinoLoc {
107 	int         face, side, dir;
108 } DinoLoc;
109 
110 typedef struct _DinoCornerLoc {
111 	int         face, rotation;
112 } DinoCornerLoc;
113 
114 typedef struct _DinoPart {
115 	Pixel       foreground;
116 	Pixel       borderColor;
117 	Pixel       faceColor[MAXFACES];
118 	DinoCornerLoc cubeLoc[MAXFACES][MAXORIENT];
119 	DinoCornerLoc faceLoc[MAXORIENT];
120 	DinoCornerLoc rowLoc[MAXORIENT][MAXORIENT];
121 	DinoCornerLoc spindleLoc[MAXROTATE][2];
122 	int         currentFace, currentPosition, currentDirection;
123 	Boolean     started, practice, orient, vertical, mono, reverse;
124 	int         dim;	/* This allows us to reuse code between 2d and 3d */
125 	int         mode, depth, style;
126 	Position    delta;
127 	Position    orientLineLength;
128 	XPoint      puzzleSize;
129 	XPoint      puzzleOffset, letterOffset;
130 	GC          puzzleGC;
131 	GC          borderGC;
132 	GC          faceGC[MAXFACES];
133 	GC          inverseGC;
134 	String      faceName[MAXFACES];
135 	char       *username;
136 	XtCallbackList select;
137 } DinoPart;
138 
139 typedef struct _DinoRec {
140 	CorePart    core;
141 	DinoPart    dino;
142 } DinoRec;
143 
144 /* This gets around C's inability to do inheritance */
145 typedef struct _DinoClassPart {
146 	int         ignore;
147 } DinoClassPart;
148 
149 typedef struct _DinoClassRec {
150 	CoreClassPart core_class;
151 	DinoClassPart dino_class;
152 } DinoClassRec;
153 
154 typedef struct _RowNext {
155 	int         face, direction, side_face;
156 } RowNext;
157 
158 extern DinoClassRec dinoClassRec;
159 
160 extern void QuitDino(DinoWidget w, XEvent * event, char **args, int nArgs);
161 extern void PracticeDino(DinoWidget w, XEvent * event, char **args, int nArgs);
162 extern void PracticeDinoMaybe(DinoWidget w, XEvent * event, char **args, int nArgs);
163 extern void RandomizeDino(DinoWidget w, XEvent * event, char **args, int nArgs);
164 extern void RandomizeDinoMaybe(DinoWidget w, XEvent * event, char **args, int nArgs);
165 extern void GetDino(DinoWidget w, XEvent * event, char **args, int nArgs);
166 extern void WriteDino(DinoWidget w, XEvent * event, char **args, int nArgs);
167 extern void UndoDino(DinoWidget w, XEvent * event, char **args, int nArgs);
168 extern void SolveDino(DinoWidget w, XEvent * event, char **args, int nArgs);
169 extern void OrientizeDino(DinoWidget w, XEvent * event, char **args, int nArgs);
170 extern void Period2ModeDino(DinoWidget w, XEvent * event, char **args, int nArgs);
171 extern void Period3ModeDino(DinoWidget w, XEvent * event, char **args, int nArgs);
172 extern void BothModeDino(DinoWidget w, XEvent * event, char **args, int nArgs);
173 extern void MoveDinoInput(DinoWidget w, int x, int y, int direction, int shift, int control, int alt);
174 extern void MoveDino(DinoWidget w, int face, int position, int direction, int style, int control);
175 extern void SelectDino(DinoWidget w, XEvent * event, char **args, int nArgs);
176 extern void ReleaseDino(DinoWidget w, XEvent * event, char **args, int nArgs);
177 
178 
179 #if 0
180 extern void SolvePolyhedrons();	/* For future auto-solver */
181 
182 #endif
183 extern void DrawAllPolyhedrons(DinoWidget w);
184 extern Boolean CheckSolved(DinoWidget w);
185 extern void InitMoves(void);
186 extern void PutMove(int face, int position, int direction, int style, int control);
187 extern void GetMove(int *face, int *position, int *direction, int *style, int *control);
188 extern int  MadeMoves(void);
189 extern void FlushMoves(DinoWidget w);
190 extern int  NumMoves(void);
191 extern void ScanMoves(FILE * fp, DinoWidget w, int moves);
192 extern void PrintMoves(FILE * fp);
193 extern void ScanStartPosition(FILE * fp, DinoWidget w);
194 extern void PrintStartPosition(FILE * fp, DinoWidget w);
195 extern void SetStartPosition(DinoWidget w);
196 
197 #ifdef DEBUG
198 extern void PrintCube(DinoWidget w);
199 
200 #endif
201 
202 #endif /* _DinoP_h */
203