home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / GAMES.ZIP / POKEREVT.C < prev    next >
C/C++ Source or Header  |  1995-05-22  |  4KB  |  106 lines

  1. #include "top.h"
  2.  
  3. void poker_eventkernel(XINT gamenum)
  4.     {
  5.     time_t timediff;
  6.     poker_game_typ egame;
  7.     XINT ekd, ekc;
  8.     XINT plnum = -1;
  9.     XINT highpl;
  10.  
  11.     timediff = difftime(time(NULL), pokeretimes[gamenum]);
  12.  
  13.     if (pokeringame[gamenum] &&
  14.         timediff >= (time_t) pokerdtimes[gamenum])
  15.         { // This may be a little too disk intensive...
  16.         poker_lockgame(gamenum);
  17.         poker_loadgame(gamenum, &egame);
  18.         if (egame.cycle == -1)
  19.             {
  20.             assert(egame.inuse); // DANGEROUS - no unlock!
  21.             for (ekd = 0; ekd < egame.maxpl; ekd++)
  22.                 {
  23.                 if (egame.wanttoplay[ekd] == od_control.od_node)
  24.                     {
  25.                     plnum = ekd;
  26.                     break;
  27.                     }
  28.                 }
  29.             assert(plnum > -1); // DANGEROUS - no unlock!
  30.             if (!egame.started[plnum])
  31.                 {
  32.                 memset(&egame.player[plnum], 0, sizeof(poker_plyr_typ));
  33.                 egame.player[plnum].node = od_control.od_node;
  34.                 if (user.cybercash >= egame.ante)
  35.                     {
  36.                     poker_dealhand(&egame, egame.player[plnum].cards);
  37.                     egame.player[plnum].origcash = user.cybercash;
  38.                     }
  39.                 highpl = poker_gethighplayer(POKPL_WAITING, &egame);
  40.                 egame.started[plnum] = 1;
  41.                 for (ekd = 0, ekc = 0; ekd <= highpl; ekd++)
  42.                     {
  43.                     if (egame.started[ekd])
  44.                         {
  45.                         ekc++;
  46.                         }
  47.                     }
  48.                 if (ekc == egame.wtpcount)
  49.                     {
  50.                     egame.plcount = egame.wtpcount;
  51.                     egame.eventtime = time(NULL);
  52.                     memcpy(egame.cardvals, pokerdefcardvals, POKERMAXDECK);
  53.                     memcpy(egame.cardsuits, pokerdefcardsuits, POKERMAXDECK);
  54.                     if (egame.rules & POKRULE_ACELOW)
  55.                         {
  56.                         egame.cardvals[0]  = 1;
  57.                         egame.cardvals[13] = 1;
  58.                         egame.cardvals[26] = 1;
  59.                         egame.cardvals[39] = 1;
  60.                         }
  61.                     }
  62.                 if (user.cybercash < egame.ante)
  63.                     {
  64.                     egame.plcount--;
  65.                     egame.player[plnum].node = -1;
  66.                     }
  67.                 else
  68.                     {
  69.                     egame.pot += egame.ante;
  70.                     }
  71.  
  72.                 if (ekc == egame.wtpcount)
  73.                     {
  74.                     poker_advanceturn(gamenum, &egame);
  75.                     }
  76.  
  77.                 poker_savegame(gamenum, &egame);
  78.                 poker_unlockgame(gamenum);
  79.                 itoa(gamenum, outnum[0], 10);
  80.                 if (user.cybercash >= egame.ante)
  81.                     {
  82.                     user.cybercash -= egame.ante;
  83.                     save_user_data(user_rec_num, &user);
  84.                     }
  85.                 else
  86.                     {
  87.                     top_output(OUT_SCREEN, getlang("PokerTooBroke"),
  88.                                outnum[0]);
  89.                     }
  90.  
  91.                 dispatch_message(MSG_GENERIC,
  92.                                  top_output(OUT_STRINGNF,
  93.                                             getlang("PokerGameStarted"),
  94.                                                     outnum[0]),
  95.                                  od_control.od_node, 1, 0);
  96.                 return;
  97.                 }
  98.             }
  99.         poker_unlockgame(gamenum);
  100.         }
  101.  
  102.     // Wait & Toss checks
  103.  
  104.     }
  105.  
  106.