Virtuelle Zockhalle 0.05 beta

elements.h

gehe zur Dokumentation dieser Datei
00001 /* -*- coding: utf-8 -*- */
00002 /***********************************************************************
00003  *
00004  * $Id: elements.h,v 1.36 2011/05/10 19:11:39 elias Exp $
00005  * Diese Datei gehört zur Virtuellen Zockhalle
00006  *
00007  * Virtuelle Zockhalle 
00008  * (c) 2010 Elias Schwerdtfeger
00009  * http://www.tamagothi.de/
00010  *
00011  * Dieses Programm ist freie Software, lizenziert unter den sinngemäß
00012  * anzuwendenden Bedingungen meiner Lizenz für freie Musik,
00013  * http://www.tamagothi.de/alben/lizenz.html
00014  *
00015  ***********************************************************************/
00016 
00017 
00018 #ifndef _ELEMENTS_H
00019 #define _ELEMENTS_H
00020 
00030 #include "alhelper.h"
00031 #include "dirtrect.h"
00032 
00033 #include <time.h>
00034 
00035 /***********************************************************************
00036  *
00037  * GLOBALE VARIABLEN
00038  *
00039  ***********************************************************************/
00040 
00046 extern short int elements_offset_x;
00048 extern short int elements_offset_y;
00050 #define XOF (elements_offset_x)
00051 
00052 #define YOF (elements_offset_y)
00053 
00061 extern short int cheat_allowed;
00062 
00063 
00064 
00065 /***********************************************************************
00066  *
00067  * HILFSFUNKTIONEN FÜR DAS RENDERING
00068  * 
00069  ***********************************************************************/
00083 void draw_backdrop (BITMAP *bm);
00089 #define clear_screen(COLOR)                     \
00090   drect_cls ((COLOR))
00091 
00105 void draw_machine_front (BITMAP *bm);
00108 /***********************************************************************
00109  *
00110  * TIMER
00111  *
00112  ***********************************************************************/
00113 
00123 extern volatile unsigned hundreds;
00124 
00133 #define timer_get()                             \
00134   (hundreds)
00135 
00136 void timer_reset (void);
00142 void timer_set (unsigned value);
00144 void timer_start (void);
00146 void timer_pause (void);
00152 int timer_is_running (void);
00159 #define random_future(MINTIME, MAXTIME)         \
00160   (timer_get () + (MINTIME) + mt_range ((MAXTIME) - (MINTIME) + 1))
00161 
00167 #define random_time(MINTIME, MAXTIME)           \
00168   ((MINTIME) + mt_range ((MAXTIME) - (MINTIME) + 1))
00169 
00171 /***********************************************************************
00172  *
00173  * VARIABLE BITMAP
00174  *
00175  ***********************************************************************/
00176 
00188 typedef
00189 struct variable_bitmap
00190 {
00191   short int x;             
00192   short int y;             
00193   unsigned short int akt;  
00194   unsigned short int max;  
00195   unsigned short int disp; 
00196   BITMAP **bm;             
00197   short int assprite;      
00198 } *vbitmap_t;
00199 
00210 void vbm_set (vbitmap_t vbm, unsigned short int newval);
00225 void vbm_sound (vbitmap_t vbm, unsigned short int newval,
00226                 SAMPLE *smp, int vol, int pan);
00233 #define vbm_get(VBM)                            \
00234   ((VBM)->akt)
00235 
00241 #define vbm_getmax(VBM)                         \
00242   (assert ((VBM)), (VBM)->max)
00243 
00245 /***********************************************************************
00246  *
00247  * ZÄHLWERK
00248  *
00249  ***********************************************************************/
00250 
00273 struct counter 
00274 {
00281   const char *uniq_id;
00283   int value;
00285   int min;
00287   int max;
00297   void (*gfx_init_cb) (remember_t rmb, struct counter *c);
00304   void (*render_cb) (struct counter *, int force);
00306   SAMPLE *smp_up;
00308   SAMPLE *smp_down;
00310   int smp_volume;
00312   int smp_pan;
00314   void *uptr1;
00316   void *uptr2;
00318   void *uprt3;
00320   int user_int;
00322   long user_long;
00336   int (*before_add_f) (struct counter *c, int toadd);
00343   int (*is_counting_f) (struct counter *c);
00345   void *iptr1;
00347   void *iptr2;
00349   void *iptr3;
00351   int impl_int;
00353   long impl_long;
00354 };
00355 
00367 void cnt_add (struct counter *c, int toadd);
00375 int cnt_is_counting (struct counter *c);
00381 void cnt_up_sound (struct counter *c);
00387 void cnt_down_sound (struct counter *c);
00393 #define cnt_get(CNTPTR)                         \
00394   ((CNTPTR)->value)
00395 
00402 #define cnt_set(CNTPTR, VAL)                    \
00403   (cnt_add ((CNTPTR), (VAL) - cnt_get ((CNTPTR))))
00404 
00411 #define cnt_sub(CNTPTR, TOSUB)                  \
00412   (cnt_add ((CNTPTR), -(TOSUB)))
00413 
00419 #define cnt_get_max(CNTPTR)                     \
00420   ((CNTPTR)->max)
00421 
00423 /***********************************************************************
00424  *
00425  * WALZE 
00426  *
00427  ***********************************************************************/
00428 
00433 enum
00434   {
00445     REELF_WEIGHTED = (1UL << 0),
00461     REELF_OWNRAND = (1UL << 1),
00462     REELF_INITED = (1UL << 7),  
00467     REELF_IMPL = (1UL << 8),
00472     REELF_USER = (1UL << 16)
00473   };
00474 
00479 enum 
00480   {
00481     REEL_STOPPED = 0,    
00482     REEL_STARTING = 1,   
00483     REEL_RUNNING = 2,    
00484     REEL_STOPPING = 3,   
00495     REEL_HOLDED = 4,
00503     REEL_SPECIAL = 5, 
00505     REEL_IMPL = 16,
00507     REEL_USER = 256
00508   };
00509 
00528 struct reel
00529 {
00536   const char *uniq_id;
00538   unsigned pos;
00540   unsigned size;
00546   unsigned long flags;
00556   void (*gfx_init_cb) (remember_t rmb, struct reel *r);
00563   void (*render_cb) (struct reel *r, int force);
00565   SAMPLE *smp_start;
00567   SAMPLE *smp_running;
00569   SAMPLE *smp_stop;
00571   int smp_volume;
00573   int smp_pan;
00584   void (*reelstart_cb) (struct reel *r);
00597   void (*reelstop_cb) (struct reel *r);
00599   void *uptr1;
00601   void *uptr2;
00603   void *uptr3;
00605   int user_int;
00607   long user_long;
00620   unsigned short *weights;
00629   void (*reelinit_cb) (struct reel *r);
00631   int state;
00637   unsigned (*randompos_cb) (struct reel *r);
00639   unsigned long weight_sum;
00641   void *iptr1;
00643   void *iptr2;
00645   void *iptr3;
00647   int impl_int;
00649   long impl_long;
00650 };
00651 
00660 void reel_set_random (struct reel *r);
00670 void reel_start (struct reel *r);
00682 void reel_stop_ex (struct reel *r, int force);
00689 unsigned reel_pos (const struct reel *r);
00698 void reel_start_sound (struct reel *r);
00707 void reel_stop_sound (struct reel *r);
00713 void reel_stop (struct reel *r);
00725 void reel_invisible_render_cb (struct reel *r, int force);
00728 /***********************************************************************
00729  * 
00730  * PERSISTENZEN
00731  *
00732  ***********************************************************************/
00733 
00742 struct invisible_persistent
00743 {
00749   const char *uniq_id;
00751   int *value;
00752 };
00753 
00754 /***********************************************************************
00755  * 
00756  * STATISTIK
00757  * 
00758  ***********************************************************************/
00759 
00761 #define BIGWIN_BUFSZ (40)
00762 
00763 #define BIGWIN_STORE (40)
00764 
00781 struct stat_bigwin
00782 {
00784   time_t when;
00786   char text[BIGWIN_BUFSZ];
00787 };
00788 
00797 struct stat_part
00798 {
00800   int games;
00802   int games_won;
00804   int bet;
00806   int won;
00807 };
00808 
00812 struct machine_stat
00813 {
00815   struct stat_part overall;
00817   struct stat_part session;
00819   int played;
00821   struct stat_bigwin bigwin[BIGWIN_STORE];
00822 };
00823 
00833 void register_bigwin (const char *fmt, ...);
00834 
00835 /***********************************************************************
00836  *
00837  * SIMULATION
00838  *
00839  ***********************************************************************/
00840 
00844 typedef struct machine *machine_t;
00845 
00857 struct simstrat
00858 {
00860   const char *name;
00862   const char *description;
00873   int (*bet_f) (machine_t md);
00886   void (*before_start_f) (machine_t md, int *hold_reel_flags);
00899   void (*after_stop_f) (machine_t md, int *start_again_flags); 
00900 };
00901 
00908 extern struct simstrat default_sim;
00909 
00910 /***********************************************************************
00911  *
00912  * SPIELGERÄT
00913  *
00914  ***********************************************************************/
00915 
00920 enum
00921   {
00923     MFL_PLAYABLE = (1UL << 0),
00925     MFL_DEBUG = (1UL << 1),
00927     MFL_WANTPAYOUT = (1UL << 2),
00929     MFL_WANTQUIT = (1UL << 3),
00931     MFL_DONE = (1UL << 4),
00941     MFL_SIMULATED = (1UL << 5),
00943     MFL_CHEATED = (1UL << 6),
00945     MFL_FILEMISS = (1UL << 7),
00947     MFL_INITCHECK = (1UL << 8),
00955     MFL_USER = (1UL << 12)
00956   };
00957 
00962 enum 
00963   {
00964     A_001 = (1UL << 1),  
00965     A_002 = (1UL << 2),  
00966     A_005 = (1UL << 3),  
00967     A_010 = (1UL << 4),  
00968     A_020 = (1UL << 5),  
00969     A_050 = (1UL << 6),  
00970     A_100 = (1UL << 7),  
00971     A_200 = (1UL << 8),  
00972     A_500 = (1UL << 9),  
00974     A_EURO = (A_010 | A_020 | A_050 | A_100 | A_200),
00976     A_DEM = (A_010 | A_050 | A_100 | A_200 | A_500),
00978     A_NULL = 0
00979   };
00980 
00984 enum 
00985   {
00986     PREVIEW_W = 210, 
00987     PREVIEW_H = 300  
00988   };
00989 
01020 struct machine
01021 {
01027   const char *uniq_id;
01029   const char *name;
01031   const char *desc;
01033   const char *version;
01044   const char *version_id;
01060   void (*format_money_f) (unsigned bufsz, char *buf, int value);
01067   unsigned bet;
01069   unsigned default_bet;
01071   BITMAP *preview_image; 
01073   unsigned long flags;
01075   unsigned long coinaccept;
01082   int n_files;
01093   char **filenames;
01102   unsigned n_vbms;
01104   struct variable_bitmap *v_vbms;
01113   unsigned n_counters;
01117   struct counter *v_counters;
01126   unsigned n_reels;
01128   struct reel *v_reels;
01136   unsigned n_strategies;
01138   struct simstrat *v_strategies;
01155   int (*initcheck_f) (void);
01184   int (*wincheck_f) (machine_t md);
01198   void (*init_f) (machine_t md, remember_t rmb);
01213   void (*startaction_f) (machine_t md);
01229   void (*endaction_f) (machine_t md);
01247   void (*graphic_init_f) (machine_t md, remember_t rmb);
01261   void (*cleanup_f) (machine_t md, remember_t rmb);
01270   void (*before_render_f) (machine_t md);
01279   void (*after_render_f) (machine_t md);
01295   void (*timer_f) (machine_t md, unsigned timer);
01317   void (*key_f) (machine_t md, int keycode, int scancode);
01342   void (*wantquit_f) (machine_t md);
01358   void (*winhandler_f) (machine_t md, int win);
01369   struct counter *credit_counter;
01371   unsigned n_invisibles;
01373   struct invisible_persistent *v_invisibles;
01374 };
01375 
01384 #define machine_is_debug(MD)                    \
01385   (((MD)->flags & MFL_DEBUG) != 0)
01386 
01392 #define machine_is_simulated(MD)                \
01393   (((MD)->flags & MFL_SIMULATED) != 0)
01394 
01413 #define machine_plays_for_real(MD)              \
01414   (((MD)->flags & MFL_SIMULATED) == 0)
01415 
01421 #define machine_is_cheated(MD)                  \
01422   (((MD)->flags & MFL_CHEATED) != 0)
01423 
01430 #define machine_want_payout(MD)                 \
01431   (((MD)->flags & MFL_WANTPAYOUT) != 0)
01432 
01441 void machine_precheck (machine_t md);
01447 struct machine_stat *machine_play (machine_t md);
01460 struct stat_part *machine_simulate (machine_t md, 
01461                                     struct simstrat *strat,
01462                                     unsigned n,
01463                                     int (*sim_cb) (unsigned n, int win));
01472 void machine_bet (machine_t md, unsigned bet);
01485 void machine_wincheck (machine_t md);
01499 void machine_quit_check (machine_t md);
01508 #define machine_is_quitting(MD)         \
01509   (((MD)->flags & (MFL_WANTQUIT | MFL_DONE)) != 0)
01510 
01516 void machine_start_action (machine_t md);
01523 void machine_end_action (machine_t md);
01530 #define machine_credit_add(M, ADD)              \
01531   (cnt_add ((M)->credit_counter, (ADD)))
01532 
01538 #define machine_credit_sub(M, SUB)              \
01539   (machine_credit_add ((M), -(SUB)))
01540 
01546 #define machine_coinin(M, CIN)                  \
01547   (cnt_add ((M)->credit_counter, (CIN)))
01548 
01554 #define machine_credit(M)                       \
01555   ((M)->credit_counter->value)
01556 
01562 void machine_payout_ex (machine_t md, int amount);
01568 #define machine_payout(M)                       \
01569   (machine_payout_ex ((M), machine_credit (M)))
01570 
01580 #define machine_payout_remain(M, REMAIN)                \
01581   do {                                                  \
01582     int amount = machine_credit ((M)) - (REMAIN);       \
01583     if (amount > 0)                                     \
01584       machine_payout_ex ((M), amount);                  \
01585   } while (0);
01586 
01599 int m_all_files_exist (unsigned n, char **filenames);
01616 DATAFILE * _internal_load_datafile (const char *filename);
01624 DATAFILE *m_load_datafile (remember_t rmb, const char *filename);
01631 struct stat_bigwin *m_bigwin_stats (const char *uniq_id);
01638 struct stat_part *m_overall_stats (const char *uniq_id);
01645 int m_machine_started (const char *uniq_id);
01652 void m_cb_wantquit_setflag (machine_t md);
01664 void m_cb_format_dem (unsigned bufsz, char *buf, int value);
01676 void m_cb_format_eur (unsigned bufsz, char *buf, int value);
01685 void m_cb_format_generic (unsigned bufsz, char *buf, int value);
01692 void m_reel_positions (machine_t md, ...);
01703 
01711 #define m_saverect(BM, X, Y)                    \
01712   drect_saverect ((BM), (X) + XOF, (Y) + YOF)
01713 
01720 #define m_blitfull(BM, X, Y)                    \
01721   drect_blitfull ((BM), (X) + XOF, (Y) + YOF)
01722 
01733 #define m_blit(BM, SX, SY, DX, DY, W, H)        \
01734   drect_blit ((BM), (SX), (SY), (DX) + XOF, (DY) + YOF, (W), (H))
01735 
01742 #define m_sprite(BM, X, Y)                      \
01743   drect_sprite ((BM), (X) + XOF, (Y) + YOF)
01744 
01753 #define m_stretch_sprite(BM, X, Y, W, H)        \
01754   drect_sprite ((BM), (X) + XOF, (Y) + YOF, (W), (H))
01755 
01762 #define m_rle_sprite(RLE, X, Y)                 \
01763   drect_rle_sprite ((RLE), (X) + XOF, (Y) + YOF)
01764 
01771 #define m_trans_rle_sprite(RLE, X, Y)           \
01772   drect_trans_rle_sprite ((RLE), (X) + XOF, (Y) + YOF)
01773 
01783 #define m_text(FNT, STR, X, Y, FG, BG)          \
01784   drect_text ((FNT), (STR), (X) + XOF, (Y) + YOF, FG, BG)
01785 
01795 #define m_ctext(FNT, STR, X, Y, FG, BG)         \
01796   drect_ctext ((FNT), (STR), (X) + XOF, (Y) + YOF, FG, BG)
01797 
01807 #define m_rtext(FNT, STR, X, Y, FG, BG)         \
01808   drect_rtext ((FNT), (STR), (X) + XOF, (Y) + YOF, FG, BG)
01809 
01818 #define m_drawbox(X, Y, W, H, C)                \
01819   drect_drawbox ((X) + XOF, (Y) + YOF, W, H, C)
01820 
01829 #define m_fillbox(X, Y, W, H, C)                \
01830   drect_fillbox ((X) + XOF, (Y) + YOF, W, H, C)
01831 
01833 /***********************************************************************
01834  *
01835  * SAMPLE-LOOP
01836  *
01837  ***********************************************************************/
01838 
01842 struct sample_loop
01843 {
01845   SAMPLE *smp;
01847   int vol;
01849   int pan;
01851   int freq;
01861   int playing;
01862 };
01863 
01868 void smploop_start (struct sample_loop *sl);
01873 void smploop_stop (struct sample_loop *sl);
01874 
01875 
01876 /***********************************************************************
01877  *
01878  * PROGRAMMSTEUERUNG
01879  *
01880  ***********************************************************************/
01881 
01887 typedef void (*prg_p0cb_t) (void);
01893 typedef void (*prg_p1cb_t) (void *p1);
01900 typedef void (*prg_p2cb_t) (void *p1, void *p2);
01907 typedef void (*prg_picb_t) (void *ptr, int i);
01934 void prg_clear (void);
01941 void prg_add (unsigned time_when, prg_p0cb_t cb);
01949 void prg_add_1param (unsigned time_when, prg_p1cb_t cb, void *p1);
01958 void prg_add_2param (unsigned time_when, prg_p2cb_t cb, void *p1, void *p2);
01967 void prg_add_piparam (unsigned time_when, prg_picb_t cb, void *ptr, int i);
01973 #define prg_reset_timer(WHEN)                   \
01974   prg_add ((WHEN), reset_timer)
01975 
01981 #define prg_start_reel(WHEN, REEL)                              \
01982   prg_add_1param ((WHEN), (prg_p1cb_t) reel_start, (REEL))
01983 
01989 #define prg_stop_reel(WHEN, REEL)                                       \
01990   prg_add_1param ((WHEN), (prg_p1cb_t) reel_stop, (REEL))
01991 
01998 #define prg_vbm_set(WHEN, VBM, NEWVAL)                                  \
01999   prg_add_piparam ((WHEN), (prg_picb_t) vbm_set, (VBM), (NEWVAL))
02000 
02006 #define prg_smploop_start(WHEN, SMPLOOP)                                \
02007   prg_add_1param ((WHEN), (prg_p1cb_t) smploop_start, (SMPLOOP))
02008 
02014 #define prg_smploop_stop(WHEN, SMPLOOP)                         \
02015   prg_add_1param ((WHEN), (prg_p1cb_t) smploop_stop, (SMPLOOP))
02016 
02025 void prg_endgame_action (unsigned when, machine_t md);
02032 void prg_default_bet (unsigned when, machine_t md);
02040 void prg_bet (unsigned when, machine_t md, int amount);
02047 void prg_startgame_action (unsigned when, machine_t md);
02059 #define prg_startgame_loop(WHEN, MD)            \
02060   do {                                          \
02061     timer_reset ();                             \
02062     prg_startgame_action ((WHEN), (MD));        \
02063   } while (0)                                   \
02064 
02070 #define prg_quitcheck(WHEN, MD)                                 \
02071   prg_add_1param ((WHEN), (prg_p1cb_t) machine_quitcheck, (MD))
02072 
02078 #define prg_wincheck(WHEN, MD)                                  \
02079   prg_add_1param ((WHEN), (prg_p1cb_t) machine_wincheck, (MD))
02080 
02085 #endif /* _ELEMENTS_H */