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