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

  1. #include "top.h"
  2.  
  3. void poker_core(XINT msggam, byte *msgstr)
  4.     {
  5.     poker_game_typ cgame;
  6.     XINT cpl = -1;
  7.     char pproc = 0;
  8.     XINT cd, cfin = 0;
  9.     unsigned XINT numwin;
  10.  
  11.     msgextradata = 0;
  12.  
  13.     if (!stricmp(msgstr, "GameOver"))
  14.         {
  15.         poker_lockgame(msggam);
  16.         poker_loadgame(msggam, &cgame);
  17.  
  18.         cpl = poker_getplayernum(POKPL_JOINED, od_control.od_node, &cgame);
  19.         if (cpl == -1)
  20.             {
  21.             poker_unlockgame(msggam);
  22.             itoa(msggam, outnum[0], 10);
  23.             top_output(OUT_SCREEN, getlang("PokerBadGameOver"), outnum[0]);
  24.             return;
  25.             }
  26.  
  27.         cpl = poker_getplayernum(POKPL_PLAYING, od_control.od_node, &cgame);
  28.         if (cpl >= 0)
  29.             {
  30.             cgame.player[cpl].winchksum =
  31.                 poker_findwinners(od_control.od_node, &numwin, &cgame);
  32.  
  33.             cgame.finished[cpl] = 1;
  34.  
  35.             for (cd = 0; cd < cgame.maxpl; cd++)
  36.                 {
  37.                 if (cgame.finished[cd])
  38.                     {
  39.                     cfin++;
  40.                     }
  41.                 }
  42.  
  43.             if (cfin == cgame.plcount)
  44.                 {
  45.                 pproc = 1;
  46.                 }
  47.  
  48.             poker_savegame(msggam, &cgame);
  49.             }
  50.  
  51.         poker_unlockgame(msggam);
  52.  
  53.         if (pproc)
  54.             {
  55.             msgextradata = 1;
  56.             }
  57.  
  58.         return;
  59.         }
  60.     if (!stricmp(msgstr, "Finished"))
  61.         {
  62.         unsigned long tpot = 0;
  63.  
  64.         poker_lockgame(msggam);
  65.         poker_loadgame(msggam, &cgame);
  66.  
  67.         cpl = poker_getplayernum(POKPL_JOINED, od_control.od_node, &cgame);
  68.         if (cpl < 0)
  69.             { // Chg this section to let folded/broke plyrs watch
  70.             poker_unlockgame(msggam);
  71.             itoa(msggam, outnum[0], 10);
  72.             top_output(OUT_SCREEN, getlang("PokerBadFinish"), outnum[0]);
  73.             return;
  74.             }
  75.  
  76.         cpl = poker_getplayernum(POKPL_PLAYING, od_control.od_node, &cgame);
  77.         if (cpl >= 0)
  78.             {
  79. //            unsigned long xtrachk = 0; (chksum check for later)
  80.  
  81.             tpot = cgame.pot;
  82.             if (cpl >= 0)
  83.                 {
  84.                 // Compare all checksums (func)
  85.                 // if problem, restore cash & wipe game.  Display error too.
  86.  
  87.                 cgame.finished[cpl] = 2;
  88.  
  89.                 for (cd = 0; cd < cgame.maxpl; cd++)
  90.                     {
  91.                     if (cgame.finished[cd] == 2)
  92.                         {
  93.                         cfin++;
  94.                         }
  95.                     }
  96.  
  97.                 if (cfin == cgame.plcount)
  98.                     {
  99.                     cgame.eventtime = time(NULL);
  100.                     poker_resetgame(&cgame);
  101.                     poker_sendmessage(MSG_POKER, 0, msggam, 0, "DoRescan",
  102.                                       &cgame);
  103.                     }
  104.  
  105.                 poker_savegame(msggam, &cgame);
  106.                 }
  107.             }
  108.         poker_unlockgame(msggam);
  109.  
  110.         // Match checksums with winner check below too if playing.
  111.  
  112.            poker_findwinners(od_control.od_node, &numwin, &cgame);
  113.         if (poker_getplayernum(POKPL_PLAYING, od_control.od_node,
  114.                                &cgame) < 0)
  115.             {
  116.             numwin = 0;
  117.             }
  118.  
  119.         // Abort & wipe like above if chk from above doesn't match.
  120.  
  121.         itoa(msggam, outnum[0], 10);
  122.         top_output(OUT_SCREEN, getlang("PokerGameEnded"), outnum[0]);
  123.         poker_endgamedisplay(&cgame);
  124.         ultoa(tpot, outnum[0], 10);
  125.         top_output(OUT_SCREEN, getlang("PokerPotWas"), outnum[0],
  126.                    tpot == 1 ?
  127.                    getlang("CDSingular") : getlang("CDPlural"));
  128.         if (pokeringame[msggam] &&
  129.             poker_getplayernum(POKPL_PLAYING, od_control.od_node,
  130.                                &cgame) >= 0)
  131.             {
  132.             if (numwin & 0x0100)
  133.                 {
  134.                 unsigned long wintmp;
  135.  
  136.                 wintmp = (tpot / ((unsigned long) numwin - 0x0100UL));
  137.                 ultoa(wintmp, outnum[0], 10);
  138.                 top_output(OUT_SCREEN, getlang("PokerWinAmount"), outnum[0],
  139.                            getlang(wintmp == 1 ? "CDSingular" : "CDPlural"));
  140.                 user.cybercash += wintmp;
  141.  
  142.                 save_user_data(user_rec_num, &user);
  143.                 }
  144.             else
  145.                 {
  146.                 top_output(OUT_SCREEN, getlang("PokerYouLose"));
  147.                 }
  148.             }
  149.  
  150.         return;
  151.         }
  152.     if (!stricmp(msgstr, "DoRescan"))
  153.         {
  154.         poker_lockgame(msggam);
  155.         poker_loadgame(msggam, &cgame);
  156.         poker_unlockgame(msggam);
  157.         }
  158.  
  159.     }
  160.