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