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