1 /* This program was written by Alexander Siegel in September of 1989   */
2 /* at Cornell University.  It may may copied freely for private use or */
3 /* public dispersion provided that this comment is not removed.  This  */
4 /* program, any portion of this program, or any derivative of this     */
5 /* program may not be sold or traded for financial gain.               */
6 
7 /* Start up default values */
8 #define DEFWORLD "goldlev"  /* Default world name */
9 #define SCOREFONT "*times-bold-r-normal-*-18*"
10 
11 #ifdef VMS
12 #define LIB "GOLDDIG$:" /* Default path name */
13 #endif
14 
15 #ifndef GOLDDIG_EXTERN
16 #define GOLDDIG_EXTERN extern
17 #endif
18 
19 GOLDDIG_EXTERN int xsize,ysize;        /* Current level width and height */
20 GOLDDIG_EXTERN int levelstart;         /* Level that player started at */
21 GOLDDIG_EXTERN int levelnum;           /* Current level number */
22 GOLDDIG_EXTERN int score;              /* Total score */
23 GOLDDIG_EXTERN int speed;              /* Speed of game.  1 is slowest, 5 is default */
24 extern int lives;       /* How many player lives left */
25 extern int angelleft;   /* How many movement on angelhood are left */
26 GOLDDIG_EXTERN int goldleft;           /* Total number of treasure blocks left */
27 GOLDDIG_EXTERN char *worldname;        /* Name of world (set of levels) */
28 GOLDDIG_EXTERN int curtick;            /* Current clock tick number */
29 extern int newlevel;    /* Non-zero if a new level was just drawn */
30 GOLDDIG_EXTERN int savehighscore; /* only save highscores if only default levels */
31 			  /* were used */
32 
33 /* Variables from controlling input and output scripts */
34 GOLDDIG_EXTERN FILE *inscr,*outscr;    /* Incoming and outgoing script file */
35 GOLDDIG_EXTERN int incount,outcount;   /* Current script input and */
36                         /* output order count */
37 
38 GOLDDIG_EXTERN Display *disp;          /* X11 display of client */
39 GOLDDIG_EXTERN Window wind;            /* X11 window where game is displayed */
40 GOLDDIG_EXTERN int scrn;               /* Which screen is in use */
41 GOLDDIG_EXTERN unsigned long background; /* background color (color displays) */
42 GOLDDIG_EXTERN char *geom;             /* Display geometry description string */
43 
44 /* Enumerated type to described direction or activity */
45 enum directs {
46   UNMOVE = 0,STAND = 1,UP = 2,DOWN = 3,LEFT = 4,RIGHT = 5,
47   DIGLEFT = 6,DIGRIGHT = 7,PUTDOWN = 8
48 };
49 GOLDDIG_EXTERN enum directs curorder;  /* Current order which player has */
50                         /* typed at the keyboard. */
51 GOLDDIG_EXTERN enum directs inorder,outorder;  /* Current script input and */
52                                 /* output order */
53 /* Structure describing all stats of thing */
54 GOLDDIG_EXTERN struct thing_s {
55   int xstart,ystart;        /* Starting position of thing.  For both */
56                             /* this pair and (xpos,ypos), the value is */
57                             /* actually 2 times the expected value. */
58                             /* This allows for describing when a thing */
59                             /* is half way between one block and another. */
60   int xpos,ypos;            /* Current position of thing */
61   int xold,yold;            /* Previous position before last movement */
62   int redraw;               /* Non-zero if thing should be redrawn */
63   enum directs dir;         /* Current movement direction or action */
64   unsigned char hold;       /* What is it carrying */
65 } player;   /* The player is a thing too */
66 
67 /* These are used in the bit pattern for the generalized block */
68 /* description data structure which is in shared.c.  New bit */
69 /* descriptor can be added without modifying anything else. */
70 #define UPLEVEL 0x2         /* Jump to next level on contact */
71 #define ULEAVE  0x4         /* Can you leave this block upwards */
72 #define DLEAVE  0x8         /* Can you leave this block downwards */
73 #define LLEAVE  0x10        /* Can you leave this block to the left */
74 #define RLEAVE  0x20        /* Can you leave this block to the right */
75 #define HENTER  0x40        /* Can you enter this block horizontally */
76 #define VENTER  0x80        /* Can you enter this block vertically */
77 #define STOPBAD 0x100       /* Stops badguys from passing through. */
78                             /* They must climb out. */
79 #define CANDIG  0x200       /* Can this block be dug */
80 #define INACTIVE 0x400      /* Does this block activate after treasure */
81                             /* is gone, space is used otherwise */
82 #define TREASURE 0x800      /* Get points for contact, then turned */
83                             /* into space */
84 #define KILLIN  0x1000      /* Kills anyone standing in it */
85 #define NODRAW  0x2000      /* Can not draw it in editor */
86 #define DIGUND  0x4000      /* Can dig out underneath this block */
87 #define PICKUP  0x8000      /* Can pickup block and replace it with space */
88 #define TELEPORT 0x10000    /* Does this cause teleportation on contact */
89 #define ARMOR   0x20000     /* Grants invulnerability to player if held */
90 #define STOPFALL 0x40000    /* Prevent holder from falling */
91 #define NSHOVEL 0x80000     /* Holder can dig much bigger holes */
92 #define TIMESTOP 0x100000   /* Stop time for all except player if held */
93 #define REVERSE 0x200000    /* Reverse bad guy direction if player holds */
94 #define UPTWO   0x400000    /* Causes jump up two spaces on contact */
95 #define ANCHOR  0x800000    /* Slows movement to one half if held, and */
96                             /* prevents jumps or teleports */
97 #define UPALL  0x1000000    /* Jump to the top of screen on contact */
98 #define SPEED  0x2000000    /* Allow player double movement if held */
99 #define PSHOVEL 0x4000000   /* Makes holes permanent when dug */
100 #define RSHOVEL 0x8000000   /* Make bricks out of space */
101 #define DFALL   0x10000000  /* Fall downwards out of this space */
102 #define UFALL   0x20000000  /* Fall upwards out of this space */
103 #define LFALL   0x40000000  /* Fall to the left out of this space */
104 #define RFALL   0x80000000  /* Fall to the right out of this space */
105 #define CANFALL (DFALL | UFALL | LFALL | RFALL) /* Bitmask for */
106                                                 /* detecting gravity */
107 
108 /* Predefined important block types.  Other types can be added WITHOUT */
109 /* adding to this list. */
110 #define SPACE ' '
111 #define BRICK '#'
112 #define STONE '@'
113 #define HOLE1 '1'
114 #define PLAYER 'p'
115 #define BADGUY 'b'
116 
117 #define MAXLEVEL 5000     /* Maximum size of a level */
118 GOLDDIG_EXTERN unsigned char level[MAXLEVEL];     /* Array describing level using */
119 				   /* characters  from above */
120 GOLDDIG_EXTERN unsigned char moveallow[MAXLEVEL]; /* Array describing which directions can */
121 				   /* be moved out of any position in level */
122 /* Bit patterns for moveallow array */
123 #define MOVEUP    0x1   /* Upward movement is allowed */
124 #define MOVEDOWN  0x2   /* Downward movement is allowed */
125 #define MOVELEFT  0x4   /* Left movement is allowed */
126 #define MOVERIGHT 0x8   /* Right movement is allowed */
127 #define FORCEUP    0x10 /* Upward movement is forced */
128 #define FORCEDOWN  0x20 /* Downward movement is forced */
129 #define FORCELEFT  0x40 /* Left movement is forced */
130 #define FORCERIGHT 0x80 /* Right movement is forced */
131 #define FORCEALL   0xf0 /* Movement is forced in some direction */
132 
133 #define STARTLIVES  2   /* Number of starting lives */
134 #define ANGELTIME  10   /* Number of movements till angel power runs */
135                         /* out after death */
136 
137 /* Array of block type descriptors.  The actual values for this array */
138 /* are in shared.c. */
139 struct symbs_s {
140   unsigned char symb;   /* Character symbol representing block */
141   unsigned char inplay; /* Character describing what this block looks like */
142                 /* during actual play.  It is the symbol character */
143                 /* for this or another block type. */
144   char *name;   /* Symbol name in English */
145   char *bits;   /* Bitmap defined by a X11 bitmap file. */
146   long code;    /* Bit code describing properties of block */
147   KeySym xkey1,xkey2;   /* One or two X11 keyboard symbols for symbol */
148   char *dcolor;  /* default color */
149 };
150 
151 /* Array for fast lookup of block types.  This array is index by the */
152 /* actual block character. */
153 GOLDDIG_EXTERN struct fast_s {
154   GC gc;        /* Graphics cursor used for drawing block */
155   long code;    /* Code describing block properties */
156 } fast_lookup[256];
157 
158 /* Global declarations of some functions */
159 void xstart();
160 void xend();
161 void setchar();
162 void draw_block();
163 void draw_level();
164 void load_level();
165 void save_level();
166 int overlap_badguy();
167 void move_badguy();
168 void start_badguy();
169 void move_badguys();
170 void draw_badguys();
171 int in_hole();
172 int movething();
173 int movedead();
174 void fill_hole();
175 void regen_tree();
176 void regen_allow();
177 void add_score();
178 void draw_score();
179 void change_holes();
180 void redrawall();
181 void moveall();
182 void init_level();
183 void drawmove_badguys();
184 void died();
185