minor comments changes
[rocksndiamonds.git] / src / game_em / emerald.h
1 /*
2
3 This program "Emerald Mine for X11"
4 is copyright © 2009 David Tritscher.  All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 1. Redistributions of source code must retain the above copyright
11    notice, this list of conditions and the following disclaimer.
12
13 2. The origin of this software must not be misrepresented; you must
14    not claim that you wrote the original software.  If you use this
15    software in a product, an acknowledgment in the product
16    documentation would be appreciated but is not required.
17
18 3. Altered source versions must be plainly marked as such, and must
19    not be misrepresented as being the original software.
20
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 */
34 /* 2007-03-31 06:22:47
35  *
36  * emerald mine game engine defines
37  */
38
39 // ----------------------------------------------------------------------------
40 // EM game engine source code was altered for integration in Rocks'n'Diamonds
41 // ----------------------------------------------------------------------------
42
43 #ifndef EMERALD_H
44 #define EMERALD_H
45
46
47 // ----------------------------------------------------------------------------
48 // constant definitions
49 // ----------------------------------------------------------------------------
50
51 #define CAVE_WIDTH                      MAX_PLAYFIELD_WIDTH
52 #define CAVE_HEIGHT                     MAX_PLAYFIELD_HEIGHT
53
54 /* additional padding for Zborder elements and linked cave buffer columns */
55 #define CAVE_BUFFER_XOFFSET             4
56 #define CAVE_BUFFER_YOFFSET             2
57 #define CAVE_BUFFER_WIDTH               (CAVE_WIDTH  + 2 * CAVE_BUFFER_XOFFSET)
58 #define CAVE_BUFFER_HEIGHT              (CAVE_HEIGHT + 2 * CAVE_BUFFER_YOFFSET)
59
60 /*
61   -----------------------------------------------------------------------------
62   definition of elements used in the Emerald Mine Club engine;
63   the element names (mostly) have the following properties:
64   - elements that start with 'X' can be stored in a level file
65   - elements that start with 'Y' indicate moving or active elements
66   - elements that start with 'Z' are internal elements without graphics
67   - elements that end with 'B' are the "backside" of moving elements
68   -----------------------------------------------------------------------------
69 */
70
71 enum
72 {
73   Xblank = 0,
74
75   Xsplash_e,
76   Xsplash_w,
77
78   Xplant,
79   Yplant,
80
81   Xacid_1,
82   Xacid_2,
83   Xacid_3,
84   Xacid_4,
85   Xacid_5,
86   Xacid_6,
87   Xacid_7,
88   Xacid_8,
89
90   Xfake_acid_1,                 /* newly added to EM engine */
91   Xfake_acid_2,
92   Xfake_acid_3,
93   Xfake_acid_4,
94   Xfake_acid_5,
95   Xfake_acid_6,
96   Xfake_acid_7,
97   Xfake_acid_8,
98
99   Xgrass,
100   Ygrass_nB,
101   Ygrass_eB,
102   Ygrass_sB,
103   Ygrass_wB,
104
105   Xdirt,
106   Ydirt_nB,
107   Ydirt_eB,
108   Ydirt_sB,
109   Ydirt_wB,
110
111   Xandroid,
112   Xandroid_1_n,
113   Xandroid_2_n,
114   Xandroid_1_e,
115   Xandroid_2_e,
116   Xandroid_1_w,
117   Xandroid_2_w,
118   Xandroid_1_s,
119   Xandroid_2_s,
120   Yandroid_n,
121   Yandroid_nB,
122   Yandroid_ne,
123   Yandroid_neB,
124   Yandroid_e,
125   Yandroid_eB,
126   Yandroid_se,
127   Yandroid_seB,
128   Yandroid_s,
129   Yandroid_sB,
130   Yandroid_sw,
131   Yandroid_swB,
132   Yandroid_w,
133   Yandroid_wB,
134   Yandroid_nw,
135   Yandroid_nwB,
136
137   Xeater_n,
138   Xeater_e,
139   Xeater_w,
140   Xeater_s,
141   Yeater_n,
142   Yeater_nB,
143   Yeater_e,
144   Yeater_eB,
145   Yeater_s,
146   Yeater_sB,
147   Yeater_w,
148   Yeater_wB,
149   Yeater_stone,
150   Yeater_spring,
151
152   Xalien,
153   Xalien_pause,
154   Yalien_n,
155   Yalien_nB,
156   Yalien_e,
157   Yalien_eB,
158   Yalien_s,
159   Yalien_sB,
160   Yalien_w,
161   Yalien_wB,
162   Yalien_stone,
163   Yalien_spring,
164
165   Xbug_1_n,
166   Xbug_1_e,
167   Xbug_1_s,
168   Xbug_1_w,
169   Xbug_2_n,
170   Xbug_2_e,
171   Xbug_2_s,
172   Xbug_2_w,
173   Ybug_n,
174   Ybug_nB,
175   Ybug_e,
176   Ybug_eB,
177   Ybug_s,
178   Ybug_sB,
179   Ybug_w,
180   Ybug_wB,
181   Ybug_w_n,
182   Ybug_n_e,
183   Ybug_e_s,
184   Ybug_s_w,
185   Ybug_e_n,
186   Ybug_s_e,
187   Ybug_w_s,
188   Ybug_n_w,
189   Ybug_stone,
190   Ybug_spring,
191
192   Xtank_1_n,
193   Xtank_1_e,
194   Xtank_1_s,
195   Xtank_1_w,
196   Xtank_2_n,
197   Xtank_2_e,
198   Xtank_2_s,
199   Xtank_2_w,
200   Ytank_n,
201   Ytank_nB,
202   Ytank_e,
203   Ytank_eB,
204   Ytank_s,
205   Ytank_sB,
206   Ytank_w,
207   Ytank_wB,
208   Ytank_w_n,
209   Ytank_n_e,
210   Ytank_e_s,
211   Ytank_s_w,
212   Ytank_e_n,
213   Ytank_s_e,
214   Ytank_w_s,
215   Ytank_n_w,
216   Ytank_stone,
217   Ytank_spring,
218
219   Xemerald,
220   Xemerald_pause,
221   Xemerald_fall,
222   Xemerald_shine,
223   Yemerald_s,
224   Yemerald_sB,
225   Yemerald_e,
226   Yemerald_eB,
227   Yemerald_w,
228   Yemerald_wB,
229   Yemerald_blank,
230
231   Xdiamond,
232   Xdiamond_pause,
233   Xdiamond_fall,
234   Xdiamond_shine,
235   Ydiamond_s,
236   Ydiamond_sB,
237   Ydiamond_e,
238   Ydiamond_eB,
239   Ydiamond_w,
240   Ydiamond_wB,
241   Ydiamond_blank,
242   Ydiamond_stone,
243
244   Xstone,
245   Xstone_pause,
246   Xstone_fall,
247   Ystone_s,
248   Ystone_sB,
249   Ystone_e,
250   Ystone_eB,
251   Ystone_w,
252   Ystone_wB,
253
254   Xbomb,
255   Xbomb_pause,
256   Xbomb_fall,
257   Ybomb_s,
258   Ybomb_sB,
259   Ybomb_e,
260   Ybomb_eB,
261   Ybomb_w,
262   Ybomb_wB,
263   Ybomb_blank,
264
265   Xnut,
266   Xnut_pause,
267   Xnut_fall,
268   Ynut_s,
269   Ynut_sB,
270   Ynut_e,
271   Ynut_eB,
272   Ynut_w,
273   Ynut_wB,
274   Ynut_stone,
275
276   Xspring,
277   Xspring_pause,
278   Xspring_e,
279   Xspring_w,
280   Xspring_fall,
281   Yspring_s,
282   Yspring_sB,
283   Yspring_e,
284   Yspring_eB,
285   Yspring_w,
286   Yspring_wB,
287   Yspring_alien_e,
288   Yspring_alien_eB,
289   Yspring_alien_w,
290   Yspring_alien_wB,
291
292   Xpush_emerald_e,
293   Xpush_emerald_w,
294   Xpush_diamond_e,
295   Xpush_diamond_w,
296   Xpush_stone_e,
297   Xpush_stone_w,
298   Xpush_bomb_e,
299   Xpush_bomb_w,
300   Xpush_nut_e,
301   Xpush_nut_w,
302   Xpush_spring_e,
303   Xpush_spring_w,
304
305   Xdynamite,
306   Ydynamite_blank,
307   Xdynamite_1,
308   Xdynamite_2,
309   Xdynamite_3,
310   Xdynamite_4,
311
312   Xkey_1,
313   Xkey_2,
314   Xkey_3,
315   Xkey_4,
316   Xkey_5,
317   Xkey_6,
318   Xkey_7,
319   Xkey_8,
320
321   Xdoor_1,
322   Xdoor_2,
323   Xdoor_3,
324   Xdoor_4,
325   Xdoor_5,
326   Xdoor_6,
327   Xdoor_7,
328   Xdoor_8,
329
330   Xfake_door_1,
331   Xfake_door_2,
332   Xfake_door_3,
333   Xfake_door_4,
334   Xfake_door_5,
335   Xfake_door_6,
336   Xfake_door_7,
337   Xfake_door_8,
338
339   Xballoon,
340   Yballoon_n,
341   Yballoon_nB,
342   Yballoon_e,
343   Yballoon_eB,
344   Yballoon_s,
345   Yballoon_sB,
346   Yballoon_w,
347   Yballoon_wB,
348
349   Xball_1,
350   Yball_1,
351   Xball_2,
352   Yball_2,
353   Yball_blank,
354
355   Xamoeba_1,
356   Xamoeba_2,
357   Xamoeba_3,
358   Xamoeba_4,
359   Xamoeba_5,
360   Xamoeba_6,
361   Xamoeba_7,
362   Xamoeba_8,
363
364   Xdrip,
365   Xdrip_fall,
366   Xdrip_stretch,
367   Xdrip_stretchB,
368   Ydrip_1_s,
369   Ydrip_1_sB,
370   Ydrip_2_s,
371   Ydrip_2_sB,
372
373   Xwonderwall,
374   Ywonderwall,
375
376   Xwheel,
377   Ywheel,
378
379   Xswitch,
380   Yswitch,
381
382   Xbumper,
383   Ybumper,
384
385   Xacid_nw,
386   Xacid_ne,
387   Xacid_sw,
388   Xacid_s,
389   Xacid_se,
390
391   Xfake_blank,
392   Yfake_blank,
393
394   Xfake_grass,
395   Yfake_grass,
396
397   Xfake_amoeba,                 /* dripper */
398   Yfake_amoeba,
399
400   Xlenses,
401
402   Xmagnify,
403
404   Xsand,
405   Xsand_stone,
406   Xsand_stonein_1,
407   Xsand_stonein_2,
408   Xsand_stonein_3,
409   Xsand_stonein_4,
410   Xsand_sandstone_1,
411   Xsand_sandstone_2,
412   Xsand_sandstone_3,
413   Xsand_sandstone_4,
414   Xsand_stonesand_1,
415   Xsand_stonesand_2,
416   Xsand_stonesand_3,
417   Xsand_stonesand_4,
418   Xsand_stoneout_1,
419   Xsand_stoneout_2,
420   Xsand_stonesand_quickout_1,   /* newly added to EM engine */
421   Xsand_stonesand_quickout_2,
422
423   Xslide_ns,                    /* growing wall */
424   Yslide_ns_blank,
425   Xslide_ew,
426   Yslide_ew_blank,
427
428   Xwind_n,
429   Xwind_e,
430   Xwind_s,
431   Xwind_w,
432   Xwind_any,
433   Xwind_stop,
434
435   Xexit,
436   Xexit_1,
437   Xexit_2,
438   Xexit_3,
439
440   Xpause,
441
442   Xwall_1,
443   Xwall_2,
444   Xwall_3,
445   Xwall_4,
446
447   Xroundwall_1,
448   Xroundwall_2,
449   Xroundwall_3,
450   Xroundwall_4,
451
452   Xsteel_1,
453   Xsteel_2,
454   Xsteel_3,
455   Xsteel_4,
456
457   Xdecor_1,
458   Xdecor_2,
459   Xdecor_3,
460   Xdecor_4,
461   Xdecor_5,
462   Xdecor_6,
463   Xdecor_7,
464   Xdecor_8,
465   Xdecor_9,
466   Xdecor_10,
467   Xdecor_11,
468   Xdecor_12,
469
470   Xalpha_0,
471   Xalpha_1,
472   Xalpha_2,
473   Xalpha_3,
474   Xalpha_4,
475   Xalpha_5,
476   Xalpha_6,
477   Xalpha_7,
478   Xalpha_8,
479   Xalpha_9,
480   Xalpha_excla,
481   Xalpha_quote,
482   Xalpha_comma,
483   Xalpha_minus,
484   Xalpha_perio,
485   Xalpha_colon,
486   Xalpha_quest,
487   Xalpha_a,
488   Xalpha_b,
489   Xalpha_c,
490   Xalpha_d,
491   Xalpha_e,
492   Xalpha_f,
493   Xalpha_g,
494   Xalpha_h,
495   Xalpha_i,
496   Xalpha_j,
497   Xalpha_k,
498   Xalpha_l,
499   Xalpha_m,
500   Xalpha_n,
501   Xalpha_o,
502   Xalpha_p,
503   Xalpha_q,
504   Xalpha_r,
505   Xalpha_s,
506   Xalpha_t,
507   Xalpha_u,
508   Xalpha_v,
509   Xalpha_w,
510   Xalpha_x,
511   Xalpha_y,
512   Xalpha_z,
513   Xalpha_arrow_e,
514   Xalpha_arrow_w,
515   Xalpha_copyr,
516
517   Ykey_1_blank,                 /* newly added to EM engine */
518   Ykey_2_blank,
519   Ykey_3_blank,
520   Ykey_4_blank,
521   Ykey_5_blank,
522   Ykey_6_blank,
523   Ykey_7_blank,
524   Ykey_8_blank,
525   Ylenses_blank,
526   Ymagnify_blank,
527   Ygrass_blank,
528   Ydirt_blank,
529
530   Xboom_bug,            /* bug explosion; transition to Zbug */
531   Xboom_bomb,           /* tank/alien/bomb explosion; transition to Ztank */
532   Xboom_android,        /* android explosion; transition to Xboom_2 */
533   Xboom_1,              /* tile explosion; transition to Xboom_2 */
534   Xboom_2,              /* transition to boom[] */
535
536   Zbug,                 /* internal bug explosion */
537   Ztank,                /* internal tank/alien/bomb explosion */
538   Zeater,               /* internal eater explosion */
539   Zdynamite,            /* internal dynamite explosion */
540   Zplayer,              /* special code to indicate player */
541   Zborder,              /* special code to indicate border */
542
543   TILE_MAX
544 };
545
546 /* other definitions */
547
548 enum
549 {
550   PLY_still = 0,
551
552   PLY_walk_n,
553   PLY_walk_e,
554   PLY_walk_s,
555   PLY_walk_w,
556
557   PLY_push_n,
558   PLY_push_e,
559   PLY_push_s,
560   PLY_push_w,
561
562   PLY_shoot_n,
563   PLY_shoot_e,
564   PLY_shoot_s,
565   PLY_shoot_w,
566
567   PLY_MAX
568 };
569
570 enum
571 {
572   SOUND_blank = 0,      /* player walks on blank */
573   SOUND_roll,           /* player pushes stone/bomb/nut/spring */
574   SOUND_stone,          /* stone hits ground */
575   SOUND_nut,            /* nut hits ground */
576   SOUND_crack,          /* stone hits nut */
577   SOUND_bug,            /* bug moves */
578   SOUND_tank,           /* tank moves */
579   SOUND_android_clone,  /* android places something */
580   SOUND_android_move,   /* android moves */
581   SOUND_spring,         /* spring hits ground/wall/bumper, stone hits spring */
582   SOUND_slurp,          /* spring kills alien */
583   SOUND_eater,          /* eater sits */
584   SOUND_eater_eat,      /* eater eats diamond */
585   SOUND_alien,          /* alien moves */
586   SOUND_collect,        /* player collects object */
587   SOUND_diamond,        /* diamond/emerald hits ground */
588   SOUND_squash,         /* stone squashes diamond */
589   SOUND_wonderfall,     /* object falls thru wonderwall */
590   SOUND_drip,           /* drip hits ground */
591   SOUND_push,           /* player pushes spring/balloon/android */
592   SOUND_dirt,           /* player digs into dirt */
593   SOUND_acid,           /* acid splashes */
594   SOUND_ball,           /* ball places something */
595   SOUND_slide,          /* slide wall grows */
596   SOUND_wonder,         /* wonderwall is active */
597   SOUND_door,           /* player goes thru door (gate) */
598   SOUND_exit_open,      /* exit opens */
599   SOUND_exit_leave,     /* player goes into exit */
600   SOUND_dynamite,       /* player places dynamite */
601   SOUND_tick,           /* dynamite ticks */
602   SOUND_press,          /* player presses wheel/wind/switch */
603   SOUND_wheel,          /* wheel moves */
604   SOUND_boom,           /* explosion */
605   SOUND_time,           /* time runs out */
606   SOUND_die,            /* player dies */
607
608   SOUND_MAX
609 };
610
611
612 // ----------------------------------------------------------------------------
613 // data structure definitions
614 // ----------------------------------------------------------------------------
615
616 struct LOGIC
617 {
618   int width;                    /* cave width */
619   int height;                   /* cave height */
620
621   int left;                     /* cave left edge */
622   int top;                      /* cave top edge */
623   int right;                    /* cave right edge */
624   int bottom;                   /* cave bottom edge */
625
626   int time;                     /* time remaining */
627   int gems_needed;              /* emeralds needed */
628   int score;                    /* score */
629
630   int eater_score;              /* score for killing eater */
631   int alien_score;              /* score for killing alien */
632   int bug_score;                /* score for killing bug */
633   int tank_score;               /* score for killing tank */
634   int slurp_score;              /* score for slurping alien with spring */
635   int nut_score;                /* score for cracking nut to emerald */
636   int emerald_score;            /* score for collecting emerald */
637   int diamond_score;            /* score for collecting diamond */
638   int dynamite_score;           /* score for collecting dynamite */
639   int key_score;                /* score for colleting key */
640   int lenses_score;             /* score for collecting lenses */
641   int magnify_score;            /* score for collecting magnifier */
642   int exit_score;               /* score for entering exit */
643
644   int android_move_time;        /* android move reset time */
645   int android_clone_time;       /* android clone reset time */
646   int ball_time;                /* ball reset time */
647   int amoeba_time;              /* amoeba speed */
648   int wonderwall_time;          /* wonderwall time */
649   int wheel_time;               /* wheel reset time */
650   int wheel_x;                  /* wheel x pos */
651   int wheel_y;                  /* wheel y pos */
652   int lenses_time;              /* lenses reset time */
653   int magnify_time;             /* magnify reset time */
654   int wind_time;                /* wind reset time */
655   int wind_direction;           /* wind direction */
656
657   int ball_random;              /* ball is random flag */
658   int ball_state;               /* ball active flag */
659   int wonderwall_state;         /* wonderwall active flag */
660   int wheel_cnt;                /* wheel counter */
661   int lenses_cnt;               /* lenses counter */
662   int magnify_cnt;              /* magnify counter */
663   int wind_cnt;                 /* wind time counter */
664
665   int android_move_cnt;         /* android move counter */
666   int android_clone_cnt;        /* android clone counter */
667   int ball_cnt;                 /* ball counter */
668   int ball_pos;                 /* ball array pos counter */
669   int eater_pos;                /* eater array pos */
670   int shine_cnt;                /* shine counter for emerald/diamond */
671
672   int num_ball_arrays;          /* number of ball data arrays used */
673
674   int home_initial;             /* number of players (initial) */
675   int home;                     /* number of players not yet at home */
676                                 /* 0 == all players at home */
677
678   boolean killed_out_of_time;   /* kill player due to time out */
679
680   int exit_x, exit_y;           /* kludge for playing player exit sound */
681
682   short eater_array[8][9];              /* eater data */
683   short ball_array[8][8];               /* ball data */
684   short android_array[TILE_MAX];        /* android clone data */
685
686   short cavebuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT];
687   short nextbuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT];
688   short drawbuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT];
689   short boombuf[CAVE_BUFFER_WIDTH][CAVE_BUFFER_HEIGHT];
690
691   short *cavecol[CAVE_BUFFER_WIDTH];
692   short *nextcol[CAVE_BUFFER_WIDTH];
693   short *drawcol[CAVE_BUFFER_WIDTH];
694   short *boomcol[CAVE_BUFFER_WIDTH];
695
696   short **cave;
697   short **next;
698   short **draw;
699   short **boom;
700 };
701
702 struct PLAYER
703 {
704   int num;
705   int exists;
706   int alive_initial;
707   int alive;
708
709   int dynamite;
710   int dynamite_cnt;
711   int keys;
712   int anim;
713
714   int x;
715   int y;
716   int oldx;
717   int oldy;
718
719   int last_move_dir;
720
721   int joy_n:1;
722   int joy_e:1;
723   int joy_s:1;
724   int joy_w:1;
725   int joy_snap:1;
726   int joy_drop:1;
727   int joy_stick:1;
728   int joy_spin:1;
729 };
730
731 #endif  // EMERALD_H