home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / BJ4TOP.ZIP / BJ4TOP.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-16  |  62KB  |  1,791 lines

  1. {$M 16384,0,0}
  2. {$V-}
  3. Program Blackjack4TOP;
  4. Uses DOS, Crt, BJSupp;
  5.  
  6. Type
  7.   IDXRec = Record
  8.              StructLength : Word;
  9.              Alias : String[30];
  10.              RealName : String[40];
  11.              Baud : Word;
  12.              Location : String[30];
  13.              Gender : Integer;
  14.              Quiet : Boolean;
  15.              Task : Word;
  16.              LastAccess : LongInt;
  17.              Channel : LongInt;
  18.              ChannelListed : Boolean;
  19.              Security : Word;
  20.              Actions : Byte;
  21.            end;
  22.  
  23.   Str30 = String[30];
  24.   Str255 = String[255];
  25.  
  26.   NodeRec = Record
  27.              StructLength : Word;
  28.              Kind : Integer;
  29.              From : Integer;
  30.              DoneTo : Integer;
  31.              Gender : Integer;
  32.              Alias : Str30;
  33.              Data : Str255;
  34.              Channel : LongInt;
  35.              MinSec : Word;
  36.              MaxSec : Word;
  37.              Data1 : LongInt;
  38.            end;
  39.  
  40.   ConfigRec = Record
  41.                 StartCD : Word;
  42.                 BetCD : Byte;
  43.                 MaxBet : Byte;
  44.                 MinBet : Byte;
  45.                 TimeBetweenGames : Byte;
  46.                 FirstWarn : Byte;
  47.                 SecondWarn : Byte;
  48.                 BootFromBJ : Byte;
  49.               end;
  50.  
  51. Type
  52.   RegisterRec = record
  53.                   TheReg : string;
  54.                   TheName : string;
  55.                 end;
  56. Const
  57.   RegisterData : RegisterRec
  58.                = ( TheReg : '00000000000';
  59.                    TheName : '[UNREGISTERED]');
  60.  
  61.   ProgVerStr = ' v2.00';
  62.  
  63.   fmReadOnly  = $00;
  64.   fmWriteOnly = $01;
  65.   fmReadWrite = $02;
  66.  
  67.   fmDenyAll   = $10;
  68.   fmDenyWrite = $20;
  69.   fmDenyRead  = $30;
  70.   fmDenyNone  = $40;
  71.  
  72.   ConfigData : ConfigRec
  73.                = ( StartCD : 1000;
  74.                    BetCD : 10;
  75.                    MaxBet : 100;
  76.                    MinBet : 10;
  77.                    TimeBetweenGames : 19;
  78.                    FirstWarn : 60;
  79.                    SecondWarn : 90;
  80.                    BootFromBJ : 125
  81.                   );
  82.  
  83.   HelpData : Array[1..14] of String = (
  84.   #13#10'^A^oEnter ^A^n/BJ BET ^A^m<amount> ^A^oto change your bet (cannot be done during a game).',
  85.   '^A^oEnter ^A^n/BJ CD ^A^oor ^A^n/BJ $ ^A^ofor your current number of Cyberdollars.',
  86.   '^A^oEnter ^A^n/BJ DOUBLE x ^A^oto double down hand x.',
  87.   '^A^oEnter ^A^n/BJ HAND ^A^oto view the dealer''s and your own cards.',
  88.   '^A^oEnter ^A^n/BJ HELP ^A^ofor this commands list.',
  89.   '^A^oEnter ^A^n/BJ HIT x ^A^oto get another card for hand x.',
  90.   '^A^oEnter ^A^n/BJ INSURE ^A^oto make an insurance bet against a blackjack.',
  91.   '^A^oEnter ^A^n/BJ OFF ^A^oto be dealt out of blackjack.',
  92.   '^A^oEnter ^A^n/BJ ON ^A^oto join in the next game of blackjack.',
  93.   '^A^oEnter ^A^n/BJ SCAN ^A^oto see who''s playing blackjack.',
  94.   '^A^oEnter ^A^n/BJ SPLIT x ^A^oto split hand x.',
  95.   '^A^oEnter ^A^n/BJ STAY ^A^oto end your turn.',
  96.   '^A^oEnter ^A^n/BJ TURN ^A^oto see who''s turn it is.'#13#10,
  97.   '^A^mIf ^lx^m is left off commands that need it, hand #^l1^m is assumed.'#13#10);
  98.  
  99.   ComList : Array[1..16] of String = ('BJ BET', 'BJ $',
  100.   'BJ CD', 'BJ DOUBLE', 'BJ DOUBLE2', 'BJ HAND', 'BJ HELP', 'BJ HIT',
  101.   'BJ HIT 2', 'BJ INSURE', 'BJ OFF', 'BJ ON', 'BJ SCAN', 'BJ SPLIT',
  102.   'BJ STAY', 'BJ TURN');
  103.  
  104.  
  105. Var
  106.   IPCDir : String;
  107.   Node : Byte;
  108.   NodeStr : String;
  109.   NodeData : NodeRec;
  110.   NodeData2 : NodeRec;
  111.   GamePlaying : Boolean;
  112.   L : Word;
  113.   Sec : Word;
  114.   OldSec : Word;
  115.   SecPassed : Word;
  116.   NodeTurn : Integer;
  117.   NodeStat : Array [1..255] of Byte; { 0 = Not in game }
  118.                                      { 1 = Waiting }
  119.                                      { 2 = In game }
  120.   NodeCD : Array [1..255] of LongInt;
  121.   NodeInsure : Array [1..255] of Boolean;
  122.   NodeHand : Array [1..6, 1..255] of String[24];
  123.   NodeDoneH : Array [1..6, 1..255] of Boolean;
  124.   NodeBet : Array [1..255] of byte;
  125.   NodeDD : Array [1..6, 1..255] of byte;
  126.   NodeNumHands : Array [1..255] of byte;
  127.   UsedCards : Array [1..6] of String[104];
  128.   DealerHand : String[40];
  129.  
  130. Procedure InitScr;
  131. Var
  132.   Loop : Word;
  133. begin
  134.   TextAttr := $71;
  135.   ClrScr;
  136.   GotoXY (1,2);
  137.   For loop := 1 to 1920 do Write ('░');
  138.   Textbackground (blue);
  139.   GotoXY (1,1);
  140.   Textbackground (7);
  141.   Textcolor (red);
  142.   Write (' Blackjack for TOP'+ProgVerStr);
  143.   Textcolor (0);
  144.   Write (' Configuration (c) 1994 by David Ong, OmniWare(tm)');
  145.   ClrEol;
  146.   GotoXY (1,25);
  147.   Textcolor (Red);
  148.   Write (' Help: ');
  149.   Textcolor (0);
  150.   Write ('Use cursor keys to select a choice.');
  151.   ClrEol;
  152.   WindowBorder (4,3,60,13,White,7);
  153.   TextAttr := $7F;
  154.   GotoXY (27,3);
  155.   Write ('┤ Config ├');
  156.   GotoXY (6,4);
  157.   Textcolor (0);
  158.   Writeln ('Starting Cyberdollars:');
  159.   GotoXY (6,5);
  160.   Writeln ('Minimum bet:');
  161.   GotoXY (6,6);
  162.   Writeln ('Maximum bet: ');
  163.   GotoXY (6,7);
  164.   Writeln ('Time between games:');
  165.   GotoXY (6,8);
  166. {  For Loop := 1 to 9 do WriteField (Loop);}
  167. end;
  168.  
  169. Procedure ConfigureBJ;
  170. begin
  171.   InitScr;
  172.   Halt;
  173. end;
  174.  
  175. Procedure SaveReg;
  176. Var
  177.   ExeFile    : file;
  178.   HeaderSize : word;
  179.   FileName : String;
  180.  
  181. begin
  182.   FileName := ParamStr (0);
  183.   Writeln ('Writing registration codes to ', FileName);
  184.   Assign (ExeFile, FileName);
  185.   Reset (ExeFile, 1);
  186.   Seek      (ExeFile, 8);
  187.   Blockread (ExeFile, HeaderSize, Sizeof (HeaderSize));
  188.   Seek      (ExeFile, Longint(16) * (seg(RegisterData)
  189.             - PrefixSeg + HeaderSize) + ofs (RegisterData) - 256);
  190.   Blockwrite (ExeFile, RegisterData, sizeof (RegisterData));
  191.   Close      (ExeFile);
  192. end;
  193.  
  194. Procedure Enter_Reg;
  195. begin
  196.   Writeln;
  197.   Writeln ('BJ4TOP Registration--Your registration code and named will be saved to');
  198.   Writeln ('  the ', ParamStr(0), ' file.');
  199.   Writeln;
  200.   Write ('Your Name (Please note it is case sensitive): ');
  201.   Readln (RegisterData.TheName);
  202.   Write ('Registration Number:');
  203.   Readln (RegisterData.TheReg);
  204.   Writeln;
  205. {  UserName := RegisterData.TheName;}
  206. {  RegisterNum := RegisterData.TheReg;}
  207. {  Check_Register;}
  208. {  If Registered then Writeln ('The registration number checks out, thank you
  209. for registering')}
  210. {  else}
  211.   begin
  212.     Writeln ('The registration number doesn''t check out, make sure you''ve entered');
  213.     Writeln ('everything correctly!'+#7);
  214.     Writeln;
  215.     Writeln ('Name and registration number not saved.');
  216.     Halt (1);
  217.   end;
  218.   Writeln;
  219.   If Not FExists (ParamStr (0)) then Writeln ('Error: The file '+ParamStr(0)+' could not be written to.'+#7)
  220.   else SaveReg;
  221. end;
  222.  
  223. Procedure InitProgram;
  224. begin
  225.   Randomize;
  226.   Writeln;
  227.   Writeln ('Blackjack for TOP'+ProgVerStr);
  228.   Writeln ('Original BJ4RAP program Copyright 1995 David Ong, OmniWare(tm)');
  229.   Writeln ('TOP modifications Copyright 1996 Paul Sidorsky, ISMWare, All Rights Reserved.');
  230.   Writeln;
  231.   If ParamCount < 1 then
  232.   begin
  233.     Writeln ('Command line parameter(s) missing!');
  234.     Writeln;
  235.     Writeln ('Usage: BJ4TOP <work path> [<node>]');
  236.     Writeln;
  237.     Writeln ('<work path>  Is the path to TOP''s work directory.');
  238.     Writeln ('<node>       Is optional and if given will force BJ4TOP to use the node even');
  239.     Writeln ('             if it is already taken.');
  240.     Writeln;
  241.     Writeln ('Eg: BJ4TOP d:\top\workdir');
  242.     Writeln ('For further help refer to BJ4TOP.DOC');
  243.     Halt;
  244.   end;
  245. {  RegisterKey := '#####';}
  246. {  UserName := RegisterData.TheName;}
  247. {  RegisterNum := RegisterData.TheReg;}
  248. {  Check_Register;}
  249.   If UpStr(ParamStr (1)) = '/REGISTER' then
  250.   begin
  251.     Enter_Reg;
  252.     Halt;
  253.   end;
  254. { If UpStr(ParamStr(1)) = '/CONFIG' then ConfigureBJ;}
  255.   IPCDir := ParamStr(1);
  256.   If IPCDir[Length(IPCDir)] <> '\' then IPCDir := IPCDir + '\';
  257.   FileMode:=fmReadWrite+FmDenyNone;
  258.   If not FExists (IPCDir + 'NODEIDX.TCH') then
  259.   begin
  260.     Writeln ('Error: The NODEIDX.TCH file was not found in the ', UpStr(IPCDir), ' directory!');
  261.     Writeln ('Make sure TOP uses the same work path and has been previously run or is'#13#10'currently running.');
  262.     Halt;
  263.   end;
  264.   If not FExists (IPCDir + 'NODEIDX2.TCH') then
  265.   begin
  266.     Writeln ('Error: The NODEIDX2.TCH file was not found in the ', UpStr(IPCDir), ' directory!');
  267.     Writeln ('Make sure TOP uses the same work path and has been previously run or is'#13#10'currently running.');
  268.     Halt;
  269.   end;
  270. end;
  271.  
  272. Function UnUsedNode : byte;
  273. Var
  274.   f : file of byte;
  275.   L : byte;
  276.   B : byte;
  277.   Error : Integer;
  278. begin
  279.   If Paramcount < 2 then
  280.   begin
  281.     L := 0;
  282.     Assign (F, IPCDir + 'NODEIDX2.TCH');
  283.     Reset (f);
  284.     Repeat
  285.       Inc (l);
  286.       {$I-}
  287.       Repeat
  288.         Read (f,b);
  289.       Until IOResult = 0;
  290.       {$I+}
  291.     Until b = 0;
  292.     Close (f);
  293.   end
  294.   else
  295.   begin
  296.     Val (ParamStr(2), L, Error);
  297.     If (Error <> 0) or (L = 0) then
  298.     begin
  299.       Writeln ('Invalid forced node passed!');
  300.       Writeln ('Node must be from 1 to 255');
  301.       Halt;
  302.     end;
  303.   end;
  304.   UnUsedNode := L;
  305. end;
  306.  
  307. Procedure TakeNode;
  308. Var
  309.   L : byte;
  310.   B : byte;
  311.   f : File of byte;
  312.   IDXFile : File of IDXRec;
  313.   IDXData : IDXRec;
  314. begin
  315.   L := 0;
  316.   Assign (f, IPCDir + 'MSG'+NodeStr+'.TCH');
  317.   Rewrite (f);
  318.   Close (f);
  319.   Assign (f, IPCDir + 'MIX'+NodeStr+'.TCH');
  320.   Rewrite (f);
  321.   Close (f);
  322.   Assign (F, IPCDir + 'NODEIDX2.TCH');
  323.   Reset (f);
  324.   Seek (f, Node);
  325.   b := 1;
  326.   {$I-}
  327.   Repeat
  328.     Write (f,b);
  329.   Until IOResult = 0;
  330.   {$I+}
  331.   Close (f);
  332.   Assign (IDXFile, IPCDir + 'NODEIDX.TCH');
  333.   Reset (IDXFile);
  334.   Seek (IDXFile, Node);
  335.   FillChar (IDXData, SizeOf(IDXData), #0);
  336.   IDXData.Alias := 'J'#8'lackjack Dealer'#0;
  337.   IDXData.Alias[0] := 'B';
  338.   IDXData.RealName := 'J'#0;
  339.   IDXData.RealName[0] := 'B';
  340.   IDXData.Baud := 0;
  341. {  If registered then}
  342. {  begin
  343.     IDXData.Location := 'egistered'+#0;
  344.     IDXData.Location[0] := 'R';
  345.   end}
  346.   {else}
  347.   begin
  348.     IDXData.Location := 'NREGISTERED'+#0;
  349.     IDXData.Location[0] := 'U';
  350.   end;
  351.   IDXData.Gender := 0;
  352.   IDXData.LastAccess := 0;
  353.   IDXData.Channel := 1;
  354.   IDXData.ChannelListed := True;
  355.   IDXData.Security := 65535;
  356.   {$I-}
  357.   Repeat
  358.     Write (IDXFile, IDXData);
  359.   Until IOResult = 0;
  360.   {$I+}
  361.   Close (IDXFile);
  362. end;
  363.  
  364. Procedure SendMSG (N : byte; NodeData : NodeRec);
  365. Var
  366.   b : byte;
  367.   f : File of byte;
  368.   NodeFile : File of NodeRec;
  369. begin
  370.   Assign (f, IPCDir + 'MIX' + PaddedNum(N)+'.TCH');
  371.   Reset (f);
  372.   b := 0;
  373.   If not Eof (f) then
  374.   Repeat
  375.     {$I-}
  376.     Repeat
  377.       Read (f,b);
  378.     Until IOResult = 0;
  379.     {$I+}
  380.     If Eof (f) then
  381.     begin
  382.       b := 0;
  383.       Write (f,b);
  384.     end;
  385.   Until B = 0
  386.   else Write (f,b);
  387.   b := 1;
  388.   Seek (f, FilePos(f) - 1);
  389.   {$I-}
  390.   Repeat
  391.     Write (f,b);
  392.   Until IOResult = 0;
  393.   {$I+}
  394.   Assign (NodeFile, IPCDir + 'MSG' + PaddedNum(N)+'.TCH');
  395.   Reset (NodeFile);
  396.   Seek (NodeFile, FilePos(f) - 1);
  397.   {$I-}
  398.   Repeat
  399.     Write (NodeFile, NodeData);
  400.   Until IOResult = 0;
  401.   {$I+}
  402.   Close (NodeFile);
  403.   Close (f);
  404.   Assign (F, IPCDir + 'CHGIDX.TCH');
  405.   Reset (f);
  406.   Seek (f, N);
  407.   b := 1;
  408.   {$I-}
  409.   Repeat
  410.     Write (f,b);
  411.   Until IOResult = 0;
  412.   {$I+}
  413.   Close (f);
  414. end;
  415.  
  416. Procedure BroadCast (T : Byte; Alias : Str30; Data : Str255);
  417. Var
  418.   IDX2 : File of byte;
  419.   b : byte;
  420.   L : Word;
  421.   NodeData : NodeRec;
  422. begin
  423.   FillChar (NodeData, SizeOf(NodeData), #0);
  424.   NodeData.Doneto := -1;
  425.   Alias := Alias + #0;
  426.   Data := Data + #0;
  427.   NodeData.Kind := T;
  428.   NodeData.From := Node;
  429.   NodeData.Alias := Minus1 (Alias);
  430.   NodeData.Alias[0] := Alias[1];
  431.   NodeData.Data := Minus1 (Data);
  432.   NodeData.Data[0] := Data[1];
  433.   NodeData.Channel := 1;
  434.   NodeData.MinSec := 0;
  435.   NodeData.Data1 := 0;
  436.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  437.   {$I-}
  438.   Repeat
  439.     Reset (IDX2);
  440.   Until IOResult = 0;
  441.   {$I+}
  442.   For L := 0 to (FileSize(IDX2) - 1) do
  443.   begin
  444.     {$I-}
  445.     Repeat
  446.       Read (IDX2, b);
  447.     Until IOResult = 0;
  448.     {$I+}
  449.     If (L <> Node) and (b=1) and (NodeStat[L] <> 0) then SendMSG (L, NodeData);
  450.   end;
  451.   Close (IDX2);
  452. end;
  453.  
  454. Procedure BroadCastAll (T : Byte; Alias : Str30; Data : Str255);
  455. Var
  456.   IDX2 : File of byte;
  457.   b : byte;
  458.   L : Word;
  459.   NodeData : NodeRec;
  460. begin
  461.   FillChar (NodeData, SizeOf(NodeData), #0);
  462.   NodeData.Doneto := -1;
  463.   Alias := Alias + #0;
  464.   Data := Data + #0;
  465.   NodeData.Kind := T;
  466.   NodeData.From := Node;
  467.   NodeData.Alias := Minus1 (Alias);
  468.   NodeData.Alias[0] := Alias[1];
  469.   NodeData.Data := Minus1 (Data);
  470.   NodeData.Data[0] := Data[1];
  471.   NodeData.Channel := 1;
  472.   NodeData.MinSec := 0;
  473.   NodeData.Data1 := 0;
  474.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  475.   {$I-}
  476.   Repeat
  477.     Reset (IDX2);
  478.   Until IOResult = 0;
  479.   {$I+}
  480.   For L := 0 to (FileSize(IDX2) - 1) do
  481.   begin
  482.     {$I-}
  483.     Repeat
  484.       Read (IDX2, b);
  485.     Until IOResult = 0;
  486.     {$I+}
  487.     If (L <> Node) and (b=1) then SendMSG (L, NodeData);
  488.   end;
  489.   Close (IDX2);
  490. end;
  491.  
  492. Procedure BroadCastAllBut (T : Byte; Alias : Str30; Data : Str255; NoSend : Byte);
  493. Var
  494.   IDX2 : File of byte;
  495.   b : byte;
  496.   L : Word;
  497.   NodeData : NodeRec;
  498. begin
  499.   FillChar (NodeData, SizeOf(NodeData), #0);
  500.   NodeData.Doneto := -1;
  501.   Alias := Alias + #0;
  502.   Data := Data + #0;
  503.   NodeData.Kind := T;
  504.   NodeData.From := node;
  505.   NodeData.Alias := Minus1 (Alias);
  506.   NodeData.Alias[0] := Alias[1];
  507.   NodeData.Data := Minus1 (Data);
  508.   NodeData.Data[0] := Data[1];
  509.   NodeData.Channel := 1;
  510.   NodeData.MinSec := 0;
  511.   NodeData.Data1 := 0;
  512.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  513.   {$I-}
  514.   Repeat
  515.     Reset (IDX2);
  516.   Until IOResult = 0;
  517.   {$I+}
  518.   For L := 0 to (FileSize(IDX2) - 1) do
  519.   begin
  520.     {$I-}
  521.     Repeat
  522.       Read (IDX2, b);
  523.     Until IOResult = 0;
  524.     {$I+}
  525.     If (L <> Node) and (b=1) and (NoSend <> L) then SendMSG (L, NodeData);
  526.   end;
  527.   Close (IDX2);
  528. end;
  529.  
  530. Procedure GiveMSG (T : Byte; Alias : Str30; Data : Str255; Node : Byte);
  531. Var
  532.   IDX2 : File of byte;
  533.   b : byte;
  534.   L : Word;
  535.   NodeData : NodeRec;
  536. begin
  537.   FillChar (NodeData, SizeOf(NodeData), #0);
  538.   NodeData.Doneto := -1;
  539.   Alias := Alias + #0;
  540.   Data := Data + #0;
  541.   NodeData.Kind := T;
  542.   NodeData.From := node;
  543.   NodeData.Alias := Minus1 (Alias);
  544.   NodeData.Alias[0] := Alias[1];
  545.   NodeData.Data := Minus1 (Data);
  546.   NodeData.Data[0] := Data[1];
  547.   NodeData.Channel := 1;
  548.   NodeData.MinSec := 0;
  549.   NodeData.Data1 := 0;
  550.   SendMSG (Node, NodeData);
  551. end;
  552.  
  553. Procedure BroadCastBut (T : Byte; Alias : Str30; Data : Str255; NoSend : Byte);
  554. Var
  555.   IDX2 : File of byte;
  556.   b : byte;
  557.   L : Word;
  558.   NodeData : NodeRec;
  559. begin
  560.   FillChar (NodeData, SizeOf(NodeData), #0);
  561.   NodeData.Doneto := -1;
  562.   Alias := Alias + #0;
  563.   Data := Data + #0;
  564.   NodeData.Kind := T;
  565.   NodeData.From := node;
  566.   NodeData.Alias := Minus1 (Alias);
  567.   NodeData.Alias[0] := Alias[1];
  568.   NodeData.Data := Minus1 (Data);
  569.   NodeData.Data[0] := Data[1];
  570.   NodeData.Channel := 1;
  571.   NodeData.MinSec := 0;
  572.   NodeData.Data1 := 0;
  573.   Assign (IDX2, IPCDir + 'NODEIDX2.TCH');
  574.   {$I-}
  575.   Repeat
  576.     Reset (IDX2);
  577.   Until IOResult = 0;
  578.   {$I+}
  579.   For L := 0 to (FileSize(IDX2) - 1) do
  580.   begin
  581.     {$I-}
  582.     Repeat
  583.       Read (IDX2, b);
  584.     Until IOResult = 0;
  585.     {$I+}
  586.     If (L <> Node) and (b=1) and (L <> NoSend) and (NodeStat[L] <> 0) then SendMSG (L, NodeData);
  587.   end;
  588.   Close (IDX2);
  589. end;
  590.  
  591. Function NodeUser (I : Integer) : String;
  592. Var
  593.   IDXFile : File of IDXRec;
  594.   IDXData : IDXRec;
  595. begin
  596.   If I > 0 then
  597.   begin
  598.     Assign (IDXFile, IPCDir + 'NODEIDX.TCH');
  599.     Reset (IDXFile);
  600.     Seek (IDXFile, I);
  601.     {$I-}
  602.     Repeat
  603.       Read (IDXFile, IDXData);
  604.     Until IOResult = 0;
  605.     {$I+}
  606.     NodeUser := CStr (IDXData.Alias);
  607.     Close (IDXFile);
  608.   end
  609.   else NodeUser := 'everyone';
  610. end;
  611.  
  612. Function NodeGender (I : Word) : Boolean;
  613. Var
  614.   IDXFile : File of IDXRec;
  615.   IDXData : IDXRec;
  616. begin
  617.   If I > 0 then
  618.   begin
  619.     Assign (IDXFile, IPCDir + 'NODEIDX.TCH');
  620.     Reset (IDXFile);
  621.     Seek (IDXFile, I);
  622.     {$I-}
  623.     Repeat
  624.       Read (IDXFile, IDXData);
  625.     Until IOResult = 0;
  626.     {$I+}
  627.     Close (IDXFile);
  628.     NodeGender := IDXData.Gender = 1;
  629.   end
  630.   else NodeGender := False;
  631. end;
  632.  
  633. Procedure InitTOP;
  634. begin
  635.   Node := UnusedNode;
  636.   Writeln ('Logging onto TOP as node ', Node);
  637.   Str (Node, NodeStr);
  638.   NodeStr := PaddedNum (Node);
  639.   TakeNode;
  640.   BroadCastAll (2, 'BJ'+#8+'lackjack Dealer', '');
  641.   BroadCastAll (9, '', '^I^i*** Blackjack'+ProgVerStr+' Game Module Active ***');
  642.   BroadCastAll (9, '', '^A^nThis program is registered to: ^A^p'+Registerdata.TheName);
  643. {  If not Registered then}
  644.     BroadCastAll (9, '', '^I^oBe sure to register soon!');
  645.   BroadCastAll (9, '', '^A^nType ^A^p/BJ HELP ^A^nfor the commands.');
  646. end;
  647.  
  648. Procedure DeInit;
  649. Var
  650.   B : byte;
  651.   f : File of byte;
  652. begin
  653.   BroadCastAll (3, '^A^mThe ^A^pBlackjack Dealer','');
  654.   BroadCastAll (9, '', '^I^i*** Blackjack'+ProgVerStr+' Game Module Deactivated ***');
  655.   Assign (F, IPCDir + 'NODEIDX2.TCH');
  656.   Reset (f);
  657.   Seek (f, node);
  658.   b := 0;
  659.   {$I-}
  660.   Repeat
  661.     Write (f,b);
  662.   Until IOResult = 0;
  663.   {$I+}
  664.   Close (f);
  665.   TextAttr := $07;
  666.   Window (1,1,80,25);
  667.   ClrScr;
  668. end;
  669.  
  670. Procedure InitScreen;
  671. begin
  672.   Delay (1000);
  673.   ClrScr;
  674.   TextAttr := $71;  { Grey on blue }
  675.   { Put background in, skipping the bottom line to create a status bar }
  676.   For L := 1 to 1920 do Write ('░');
  677.   TextAttr := $74;
  678.   GotoXY (1,1);   ClrEol;
  679.   GotoXY (3,1);  Writeln ('Blackjack for TOP'+ProgVerStr+' - Copyright 1996 Paul Sidorsky - All Rights Reserved');
  680.   WindowBorder (5,3,74,21, White, Blue);
  681.   GotoXY (1,25);
  682.   TextAttr := $70;
  683.   Write (' Press <ESC> to deactivate blackjack');
  684.   ClrEol;
  685. {  If not registered then}
  686.   begin
  687.     GotoXY (67,25);
  688.     Textcolor (Red+Blink);
  689.     Textbackground (LightGray);
  690.     Write ('Unregistered');
  691.   end;
  692. {  else
  693.   begin
  694.     GotoXY (67,25);
  695.     Textcolor (Red);
  696.     Textbackground (LightGray);
  697.     Write ('Registered');
  698.   end;}
  699.   Window (6,4,73,20);
  700.   Textbackground (Blue);
  701.   Textcolor (Yellow);
  702.   Writeln ('Waiting for people to join blackjack.');
  703. end;
  704.  
  705. Procedure InitVars;
  706. Var
  707.   D : integer;
  708. begin
  709.   For L := 1 to 255 do
  710.   begin
  711.     NodeStat[L] := 0;
  712.     NodeCD[L] := ConfigData.StartCD;
  713.     NodeBet[L] := ConfigData.BetCD;
  714.     NodeInsure[L] := False;
  715.     For D := 1 to 6 do
  716.     begin
  717.       NodeHand[D, L] := '';
  718.       NodeDD[D, L] := 1;
  719.       NodeDoneH[D, L] := False;
  720.     end;
  721.     NodeNumHands[L] := 0;
  722.   end;
  723.   For D := 1 to 6 do UsedCards[D] := '';
  724. end;
  725.  
  726. Function MSGWait : boolean;
  727. Var
  728.   b : byte;
  729.   f : File of byte;
  730. begin
  731.   Assign (f, IPCDir + 'CHGIDX.TCH');
  732.   Reset (f);
  733.   Seek (f, node);
  734.   {$I-}
  735.   Repeat
  736.     Read (f,b);
  737.   Until IOResult = 0;
  738.   {$I+}
  739.   MSGWait := b = 1;
  740.   Close (f);
  741. end;
  742.  
  743. Function DoneAllHands(P : Word) : Boolean;
  744. Var
  745.   H : Word;
  746.   C : Word;
  747. begin
  748.   C := 0;
  749.   For H := 1 to NodeNumHands[P] do
  750.     If NodeDoneH[H, P] then Inc(C);
  751.   If C = NodeNumHands[P] then DoneAllHands := True else DoneAllHands := False;
  752. end;
  753.  
  754. Function OkayToSplit(N : Word; P : Word) : Boolean;
  755. Var
  756.   H : Word;
  757.   C : Word;
  758. begin
  759.   OkayToSplit := False;
  760.   C := 0;
  761.   If NodeNumHands[P] < 6 then
  762.   begin
  763.     For H := 1 to NodeNumHands[P] do
  764.       If Length(NodeHand[H, P]) = 4 then
  765.         Inc(C);
  766.     If C = NodeNumHands[P] then OkayToSplit := True;
  767.   end;
  768. end;
  769.  
  770. Function GetCard : String;
  771. Const
  772.   Cards : Array [1..13] of Char = 'A23456789TJQK';
  773.   Kinds : Array [1..4] of Char = 'HDSC';
  774. Var
  775.   Value, Kind : Byte;
  776.   Card : String[6];
  777.   Hand : Word;
  778. begin
  779.   Hand := Random (6)+1;
  780.   Repeat
  781.     Value := Random (13)+1;
  782.     Kind := Random (4)+1;
  783.     Card := Cards[Value] + Kinds [Kind];
  784.   Until Pos (Card, UsedCards[Hand]) = 0;
  785.   UsedCards[Hand] := UsedCards[Hand] + Card;
  786.   { Shuffle once only 6 cards are left in that deck. }
  787.   If Length (UsedCards[Hand]) >= 92 then UsedCards[Hand] := '';
  788.   GetCard := Card;
  789. end;
  790.  
  791. Function HandValue (Hand : String) : Byte;
  792. Var
  793.   Value : Byte;
  794.   Aces : Byte;
  795. begin
  796.   Value := 0;
  797.   { Count aces }
  798.   Aces := 0;
  799.   For L := 1 to Length (Hand) do if Hand[L] = 'A' then Inc (Aces);
  800.   While Hand[0] > #1 do
  801.   begin
  802.     If Hand[1] = 'A' then Value := Value + 11;
  803.     If Hand[1] in ['T','J','Q','K'] then Value := Value + 10;
  804.     If Hand[1] in ['2'..'9'] then Value := Value + Ord(Hand[1])-48;
  805.     Delete (Hand, 1, 2);
  806.   end;
  807.   While (Value > 21) and (Aces <> 0) do
  808.   begin
  809.     Dec (Value,10);
  810.     Dec (Aces);
  811.   end;
  812.   HandValue := Value;
  813. end;
  814.  
  815. Function ColorHand (Hand : String) : String;
  816. Var
  817.   New : String;
  818. begin
  819.   New := '';
  820.   While Hand[0] > #1 do
  821.   begin
  822.     If Hand[2] in ['D','H'] then New := New + '^H^e'+Hand[1]+Hand[2]+'^A^k '
  823.     else
  824.     If Hand[2] in ['C','S'] then New := New + '^H^a'+Hand[1]+Hand[2]+'^A^k '
  825.     else New := New + '^H^a  ^A^k';
  826.     Delete (Hand, 1, 2);
  827.   end;
  828.   ColorHand := New;
  829. end;
  830.  
  831. Procedure NextPlayer;
  832. Var
  833.   I : Word;
  834.   X : Byte;
  835. begin
  836.   If NodeStat[NodeTurn] <> 0 then
  837.   begin
  838.     X := 0;
  839.     For I := 1 to NodeNumHands[NodeTurn] Do
  840.     begin
  841.       If NodeHand[I, NodeTurn] <> '' then
  842.         If HandValue (NodeHand[I, NodeTurn]) > 21 then Inc(X);
  843.     end;
  844.     if X >= NodeNumHands[NodeTurn] then NodeStat[NodeTurn] := 1;
  845.   end;
  846.   If NodeStat[NodeTurn] = 1 then
  847.   begin
  848.     If NodeInsure[NodeTurn] then
  849.     begin
  850.       Dec (NodeCD[NodeTurn], Round (NodeBet[NodeTurn]/2));
  851.       GiveMSG (9, '', '^A^pYou^I^n lose ^A^nyour insurance bet of ^A^p'+ToStr(Round(NodeBet[NodeTurn]/2))
  852.                +' ^A^nCyberdollars!', NodeTurn);
  853.       If NodeGender (NodeTurn) then
  854.         BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^nher insurance bet of ^A^p'
  855.                       +ToStr(Round(NodeBet[NodeTurn]/2))+' ^A^nCyberdollars!', NodeTurn)
  856.       else
  857.         BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^nhis insurance bet of ^A^p'
  858.                       +ToStr(Round(NodeBet[NodeTurn]/2))+' ^A^nCyberdollars!', NodeTurn)
  859.     end;
  860.   end;
  861.   I := NodeTurn;
  862.   Repeat
  863.     Inc (I);
  864.   Until (I = 256) or (NodeStat[I] = 2);
  865.   If I = 256 then NodeTurn := -1       { Dealer's turn }
  866.     else NodeTurn := I;
  867.   If NodeTurn > 1 then
  868.   begin
  869.     NodeData2.DoneTo := -1;
  870.     NodeData2.From := node;
  871.     NodeData2.Gender := 0;
  872.     NodeData2.Alias := '';
  873.     NodeData2.Kind := 9;
  874.     NodeData2.Data := 'A^mIt is your turn in ^A^pblackjack^A^m!'#0;
  875.     NodeData2.Data[0] := '^';
  876.     NodeData2.Channel := 1;
  877.     NodeData2.MinSec := 0;
  878.     NodeData2.Data1 := 0;
  879.     SendMSG (NodeTurn, NodeData2);
  880.   end;
  881.   SecPassed := 0;
  882.   If NodeTurn > 1 then Writeln ('It is ', NodeUser(NodeTurn), '''s turn in blackjack.')
  883.   else Writeln ('It is the Dealer''s turn in blackjack.');
  884. end;
  885.  
  886. Procedure DisplayHand (Node : Word);
  887. var
  888.   X : Word;
  889. begin
  890.   GiveMSG (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand[1]+DealerHand[2])+'^H^a  ^A^n  (^A^p'
  891.            +ToStr(HandValue(DealerHand[1]+DealerHand[2]))+'^A^n)', Node);
  892.   If NodeNumHands[Node] > 1 then
  893.   begin
  894.     For X := 1 to NodeNumHands[Node] do
  895.       If not NodeDoneH[X, Node] then
  896.       GiveMSG (9, '', '^A^nHand #'+ToStr(X)+':      '+ColorHand(NodeHand[X, Node])+' ^A^n(^A^p'
  897.                +ToStr(HandValue(NodeHand[X, Node]))+'^A^n)', Node);
  898.   end
  899.   else
  900.     GiveMSG (9, '', '^A^nYour cards:     '+ColorHand(NodeHand[1, Node])+' ^A^n(^A^p'
  901.              +ToStr(HandValue(NodeHand[1, Node]))+'^A^n)', Node);
  902. end;
  903.  
  904. Procedure RegRemind;
  905. Var
  906.   N : Byte;
  907. begin
  908.   N := Random (4);
  909.   Case N of
  910.     0 : Broadcast (9,'','From ^A^lBlackjack Dealer^A^o, holding up a big placard: ^A^kRemember to register Blackjack!');
  911.     1 : BroadCast (9,'','^I^pThis version of Blackjack for TOP is UNREGISTERED!^A^o');
  912.     2 : BroadCast (9,'','From ^A^lBlackjack Dealer^A^o, in a hypnotic tone: ^A^kRegister blackjack, Register blackjack...');
  913.     3 : BroadCast (9,'','From ^A^lBlackjack Dealer^A^o, over the bar''s PA system: ^A^kBlackjack is UNREGISTERED!');
  914.   end;
  915. end;
  916.  
  917. Procedure Retal (Node : Word);
  918. Var
  919.   N : Byte;
  920.   J : Byte;
  921.   T : LongInt;
  922. begin
  923.   N := Random (30);
  924.   If N > 9 then
  925.   begin
  926.     J := Random (9);
  927.     Case J of
  928.     0 : begin
  929.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois booting ^A^lyou ^A^oto the head!',
  930.                       Node);
  931.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois booting ^A^l'+NodeUser(Node)+' ^A^oto the head!', Node);
  932.         end;
  933.     1 : begin
  934.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois frowning darkly at ^A^lyou^A^o!',
  935.                       Node);
  936.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ois frowning darkly at ^A^l'+NodeUser(Node)+'^A^o!', Node);
  937.         end;
  938.     2 : begin
  939.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust smacked ^A^lyou ^A^oacross the back of the head!',
  940.                       Node);
  941.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust smacked ^A^l'+NodeUser(Node)
  942.                         +' ^A^oacross the back of the head!', Node);
  943.         end;
  944.     3 : If NodeStat[Node] > 0 then
  945.           BroadCastAll (9, '^oThe Blackjack Dealer',
  946.               '^oFrom ^A^lThe Blackjack Dealer^A^o, grumbling unhappily: ^A^kStop that, '
  947.                         +NodeUser(Node)+', or I''ll kick you out of the game!');
  948.     4 : If NodeStat[Node] > 0 then
  949.           BroadCastAll (9, '^oThe Blackjack Dealer',
  950.               '^oFrom ^A^lThe Blackjack Dealer^A^o, grumbling unhappily: ^A^kStop that, '
  951.                         +NodeUser(Node)+', or I''ll have to fine you!');
  952.     5 : begin
  953.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust elbowed ^A^lyou ^A^oin the face!',
  954.                       Node);
  955.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust elbowed ^A^l'+NodeUser(Node)+' ^A^oin the face!', Node);
  956.         end;
  957.     6 : BroadCastAll (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust put up ^A^lhis^A^o deflector shields!');
  958.     7 : begin
  959.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust poked ^A^lyou ^A^oin the ribs!',
  960.                       Node);
  961.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust poked ^A^l'+NodeUser(Node)+' ^A^oin the ribs!', Node);
  962.         end;
  963.     8 : begin
  964.           GiveMSG (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust gave ^A^lyou ^A^oa good, swift, kick in the butt!',
  965.                       Node);
  966.           BroadCastAllBut (9, '', '^oThe ^A^lBlackjack Dealer ^A^ojust gave ^A^l'+NodeUser(Node)
  967.                            +' ^A^oa good, swift, kick in the butt!', Node);
  968.         end;
  969.     end;
  970.   end
  971.   else
  972.   If ((N = 9) or (N = 8) or (N = 15)) and (NodeStat[NodeData.From] > 0) then
  973.   begin
  974.     If NodeStat[nodedata.from] = 2 then
  975.     begin
  976.       For J := 1 to NodeNumHands[J] do
  977.         If HandValue (NodeHand[J, Node]) < 22 then
  978.           Dec (NodeCD[Node], NodeBet[Node]*NodeDD[J, Node]);
  979.       If NodeInsure[Node] then Dec (NodeCD[Node], Round(NodeBet[Node]/2));
  980.     end;
  981.     NodeStat[Node] := 0;
  982.     BroadCastBut (9,'','^A^nThe ^A^pblackjack dealer ^A^njust tossed ^A^p'+(NodeUser(Node))
  983.                   +' ^A^nout of the ^A^pblackjack^A^n game!', Node);
  984.     GiveMSG (9,'','^A^nThe angry ^A^pblackjack dealer ^A^njust tossed ^A^pyou ^A^nout of the ^A^pblackjack^A^n game!',
  985.                   Node);
  986.     Writeln (NodeUser(Node), ' is dealt out of the blackjack game.');
  987.     If (nodedata.from) = NodeTurn then NextPlayer;
  988.   end;
  989.   If (N = 25) and (NodeStat[NodeData.From] > 0) then
  990.   begin
  991.     T := (((random(5) + 4) MOD 3) + 1) * 100;
  992.     Dec(NodeCD[NodeData.From], T);
  993.     BroadCastBut (9,'','^A^nThe ^pblackjack dealer ^njust ^I^pfined^A '+(NodeUser(Node))
  994.                   +' ^l'+ ToStr(T) +'^n CyberDollars!', Node);
  995.     GiveMSG (9,'','^A^nThe ^pblackjack dealer ^njust ^I^pfined^A you'
  996.              +' ^l'+ ToStr(T) +'^n CyberDollars!', Node);
  997.     Writeln(NodeUser(Node), ' has been fined ', T, 'CDs.');
  998.   end;
  999. end;
  1000.  
  1001. Procedure Process (NodeData : NodeRec);
  1002. Var
  1003.   s : String;
  1004.   I : Word;
  1005.   L : LongInt;
  1006.   Error : Integer;
  1007.   J : Word;
  1008.   H : Word;
  1009. begin
  1010.   NodeData2.DoneTo := -1;
  1011.   NodeData2.From := node;
  1012.   NodeData2.Gender := 0;
  1013.   NodeData2.Alias := '';
  1014.   NodeData2.Kind := 9;
  1015.   NodeData2.Channel := 1;
  1016.   NodeData2.MinSec := 0;
  1017.   NodeData2.Data1 := 0;
  1018.   If NodeData.Kind = 6 then
  1019.   begin
  1020.     s := KillSpaces(UpStr(CStr(NodeData.Data)));
  1021.     If s = 'ON' then
  1022.     begin
  1023.       If NodeStat[NodeData.From+1] = 0 then
  1024.       begin
  1025.         GiveMSG (9, '', '^A^nOk, you will now be playing in the next ^A^pblackjack ^A^ngame!',
  1026.                  NodeData.from);
  1027.         NodeStat[NodeData.from] := 1;
  1028.         BroadCastBut (9,'','^A^p'+CStr(NodeData.Alias)+' ^A^nwill be playing in the next ^A^pblackjack^A^n game!',
  1029.                       NodeData.from);
  1030.         Writeln (CStr(NodeData.Alias), ' joins the blackjack game.');
  1031.       end
  1032.       else
  1033.         GiveMSG (9, '', '^A^nYou are already playing ^A^pblackjack^A^n!', NodeData.from);
  1034.     end;
  1035.     If s = 'OFF' then
  1036.     begin
  1037.       If NodeStat[NodeData.from] = 0 then
  1038.         GiveMSG (9, '', '^A^nYou aren''t playing in ^A^pblackjack^A^n!', NodeData.from)
  1039.       else
  1040.       begin
  1041.         GiveMSG (9, '', '^A^nOk, you are no longer playing ^A^pblackjack^A^n.', NodeData.from);
  1042.         If NodeStat[NodeData.from] = 2 then
  1043.         begin
  1044.           For H := 1 to NodeNumHands[NodeData.from] do
  1045.           Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD[H, NodeData.from]);
  1046.           NextPlayer;
  1047.         end;
  1048.         BroadCastBut (9,'','^A^p'+CStr(NodeData.Alias)+' ^A^nask to be dealt out of the ^A^pblackjack^A^n game!',
  1049.                       NodeData.from);
  1050.         Writeln (CStr(NodeData.Alias), ' is dealt out of the blackjack game.');
  1051.         NodeStat[NodeData.from] := 0;
  1052.       end;
  1053.     end;
  1054.     If (s='INSURE')or(s='INSURANCE')or(s='INSUR')or(s='INS')or(s='INSUER') then
  1055.     begin
  1056.       If (NodeStat[NodeData.from] = 2) then
  1057.       begin
  1058.         If NodeData.from = NodeTurn then
  1059.         begin
  1060.           If NodeInsure[NodeData.from] then
  1061.             GiveMSG (9, '', '^A^nYou''ve already made an insurance bet!', NodeData.from)
  1062.           else
  1063.           begin
  1064.             If (Length (NodeHand[1, NodeData.from]) = 4) and (NodeNumHands[NodeData.from] = 1) then
  1065.             begin
  1066.               GiveMSG (9, '', '^A^nOk, you make an insurance bet.', NodeData.from);
  1067.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nmakes an insurance bet.', NodeData.from);
  1068.               NodeInsure[NodeData.from] := True;
  1069.             end
  1070.             else GiveMSG (9, '', '^A^nYou can''t buy insurance now!', NodeData.from);
  1071.           end;
  1072.         end
  1073.         else
  1074.           GiveMSG (9, '', '^A^nIt isn''t your turn!', NodeData.from);
  1075.       end
  1076.       else
  1077.         GiveMSG (9, '', '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1078.     end;
  1079.     If (s='STAY')or(s='STA')or(s='STY')or(s='SAY')or(s='TAY')or(s='STYA')or(s='STAYU')or
  1080.        (s='STAND') then
  1081.     begin
  1082.       If (NodeStat[NodeData.from] = 2) then
  1083.       begin
  1084.         If NodeData.from = NodeTurn then
  1085.         begin
  1086.           GiveMSG (9, '', '^A^nOk, you stay.', NodeData.from);
  1087.           BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nstays.', NodeData.from);
  1088.           NextPlayer;
  1089.         end
  1090.         else
  1091.           GiveMSG (9, '', '^A^nIt isn''t your turn!', NodeData.from);
  1092.       end
  1093.       else
  1094.         GiveMSG (9, '', '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1095.     end;
  1096.     If (s='HAND')or(s='HAN')or(s='HADN')or(s='AHND') then
  1097.     begin
  1098.       If NodeStat[NodeData.from] = 2 then DisplayHand (NodeData.from)
  1099.       else
  1100.         GiveMSG (9, '', '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1101.     end;
  1102.     If (s = 'CD') or (s = '$') then
  1103.       GiveMSG (9, '', '^A^nYou have ^A^p'+ ToStr(NodeCD[NodeData.from])+'^A^n Cyberdollars.', NodeData.from);
  1104.     If Copy(s, 1, 3) = 'HIT' then
  1105.     begin
  1106.       If NodeStat[NodeData.from] = 2 then
  1107.       begin
  1108.         If NodeData.from = NodeTurn then
  1109.         begin
  1110.           If Length(s) = 3 then H := 1 else Val(Copy(s, 4, 1), H, Error);
  1111.           if H > NodeNumHands[NodeData.from] then GiveMsg(9, '', '^A^nYou don''t have '+ToStr(H)+' hands!', NodeData.from)
  1112.           else
  1113.           If NodeDoneH[H, NodeData.from] then GiveMSG (9, '', '^A^nYou can''t play that hand!', NodeData.from)
  1114.           else
  1115.           begin
  1116.             if NodeNumHands[NodeData.from] = 1 then
  1117.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nhits.', NodeData.from)
  1118.             else
  1119.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nhits hand #'+ToStr(H)+'.', NodeData.from);
  1120.             NodeHand[H, NodeData.from] := NodeHand[H, NodeData.from] + GetCard;
  1121.             DisplayHand (NodeData.from);
  1122.             SecPassed := 0;
  1123.             Writeln (NodeUser(NodeTurn), ' hits.');
  1124.             If HandValue(NodeHand[H, NodeData.from]) > 21 then
  1125.             begin
  1126.               GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1127.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1128.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!'
  1129.                             , NodeData.from);
  1130.               GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!', NodeData.from);
  1131.               Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]);
  1132.               Writeln (NodeUser(NodeTurn), ' busts.');
  1133.               NodeDoneH[H, NodeData.from] := True;
  1134.               If DoneAllHands(NodeData.from) then NextPlayer;
  1135.             end;
  1136.           end;
  1137.         end
  1138.         else
  1139.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1140.       end
  1141.       else
  1142.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1143.     end;
  1144. {    If (s='HIT2')or(s='HTI2')or(s='HI2T')or(s='IHT2') then
  1145.     begin
  1146.       If NodeStat[NodeData.from] = 2 then
  1147.       begin
  1148.         If NodeData.from = NodeTurn then
  1149.         begin
  1150.           If NodeHand2[NodeData.from] = '' then
  1151.             GiveMSG (9, '', '^A^nYou don''t have a second hand!', NodeData.from)
  1152.           else
  1153.           begin
  1154.             If NodeDoneH2[NodeData.from] then GiveMSG (9, '', '^A^nYou can''t play that hand!', NodeData.from)
  1155.             else
  1156.             begin
  1157.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nhits second hand.', NodeData.from);
  1158.               NodeHand2[NodeData.from] := NodeHand2[NodeData.from] + GetCard;
  1159.               DisplayHand (NodeData.from);
  1160.               SecPassed := 0;
  1161.               Writeln (NodeUser(NodeTurn), ' hits second hand.');
  1162.               If HandValue(NodeHand2[NodeData.from]) > 21 then
  1163.               begin
  1164.                 GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1165.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1166.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!'
  1167.                               , NodeData.from);
  1168.                 GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn])+' ^A^nCyberdollars!', NodeData.from);
  1169.                 Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]);
  1170.                 Writeln (NodeUser(NodeTurn), ' busts.');
  1171.                 NodeDoneH2[NodeData.from] := True;
  1172.                 If NodeDoneH1[NodeData.from] and NodeDoneH2[NodeData.from] then NextPlayer;
  1173.               end;
  1174.             end;
  1175.           end;
  1176.         end
  1177.         else
  1178.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1179.       end
  1180.       else
  1181.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1182.     end;}
  1183.     If (s = 'HELP') or (s = '!') or (s = '?') or (s = 'COMMANDS') then
  1184.     begin
  1185.       For I := 1 to 14 do
  1186.         GiveMSG (9, '', HelpData[I], NodeData.from);
  1187.     end;
  1188.     If Copy(s, 1, 5) = 'SPLIT' then
  1189.     begin
  1190.       If NodeStat[NodeData.from] = 2 then
  1191.         If NodeData.from = NodeTurn then
  1192.         begin
  1193.           If Length(s) = 5 then H := 1 else Val(Copy(s, 6, 1), H, Error);
  1194.           if H > NodeNumHands[NodeData.from] then GiveMsg(9, '', '^A^nYou don''t have '+ToStr(H)+' hands!', NodeData.from)
  1195.           else
  1196.           If OkayToSplit(H, NodeData.from) then
  1197.           begin
  1198.             If HandValue (NodeHand[H, NodeData.from][1]+NodeHand[H, NodeData.from][2])
  1199.                = HandValue (NodeHand[H, NodeData.from][3]+NodeHand[H, NodeData.from][4]) then
  1200.             begin
  1201.               GiveMSG (9, '', '^A^nOk, you split.', NodeData.from);
  1202.               SecPassed := 0;
  1203.               If NodeNumHands[NodeData.from] = 1 then
  1204.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nsplits.', NodeData.from)
  1205.               else
  1206.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nsplits hand #'+ToStr(H)+'.', NodeData.from);
  1207.               Inc(NodeNumHands[NodeData.from]);
  1208.               NodeHand[NodeNumHands[NodeData.from], NodeData.from] :=
  1209.                 NodeHand[H, NodeData.from][3]+NodeHand[H, NodeData.from][4];
  1210.               Dec (NodeHand[H, NodeData.from][0], 2);
  1211.               NodeHand[H, NodeData.from] := NodeHand[H, NodeData.from] + GetCard;
  1212.               NodeHand[NodeNumHands[NodeData.From], NodeData.from] :=
  1213.                 NodeHand[NodeNumHands[NodeData.From], NodeData.from] + GetCard;
  1214.               DisplayHand (NodeData.from);
  1215.             end
  1216.             else GiveMSG (9, '', '^A^nYou can''t split when card values are different!', NodeData.from)
  1217.           end
  1218.           else GiveMSG (9, '', '^A^nYou can''t split now!', NodeData.from)
  1219.         end
  1220.         else
  1221.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from)
  1222.       else
  1223.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1224.     end;
  1225.     if Copy(s, 1, 2) = 'DD' then s := 'DOUBLE' + s[3];
  1226.     if Copy(s, 1, 6) = 'DOUBLE' then
  1227.     begin
  1228.       If NodeStat[NodeData.from] = 2 then
  1229.       begin
  1230.         If NodeData.from = NodeTurn then
  1231.         begin
  1232.           If Length(s) = 6 then H := 1 else Val(Copy(s, 7, 1), H, Error);
  1233.           if H > NodeNumHands[NodeData.from] then GiveMsg(9, '', '^A^nYou don''t have '+ToStr(H)+' hands!', NodeData.from)
  1234.           else
  1235.           If NodeDoneH[H, NodeData.from] then GiveMSG (9, '', '^A^nYou can''t play that hand!', NodeData.from)
  1236.           else
  1237.           if Length(NodeHand[H, NodeData.from]) <= 4 then
  1238.           begin
  1239.             if NodeNumHands[NodeData.from] = 1 then
  1240.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^ndoubles down.', NodeData.from)
  1241.             else
  1242.             BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^ndoubles down hand #'+ToStr(H)+'.', NodeData.from);
  1243.             NodeHand[H, NodeData.from] := NodeHand[H, NodeData.from] + GetCard;
  1244.             NodeDD[H, NodeData.from] := 2;
  1245.             GiveMSG (9, '', '^A^nOk, you ^A^pdouble down^A^n!', NodeData.from);
  1246.             DisplayHand (NodeData.from);
  1247.             SecPassed := 0;
  1248.             Writeln (NodeUser(NodeTurn), ' doubles down.');
  1249.             If HandValue(NodeHand[H, NodeData.from]) > 21 then
  1250.             begin
  1251.               GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1252.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1253.               BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD[H, NodeTurn])
  1254.                             +' ^A^nCyberdollars!', NodeData.from);
  1255.               GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD[H, NodeTurn])+' ^A^nCyberdollars!',
  1256.                        NodeData.from);
  1257.               Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD[H, NodeData.from]);
  1258.               Writeln (NodeUser(NodeTurn), ' busts.');
  1259.             end;
  1260.             NodeDoneH[H, NodeData.from] := True;
  1261.             if DoneAllHands(NodeData.from) then NextPlayer;
  1262.           end
  1263.           else
  1264.             GiveMSG (9, '', '^A^nYou can''t double down after hitting!', NodeData.from);
  1265.         end
  1266.         else
  1267.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1268.       end
  1269.       else
  1270.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1271.     end;
  1272. {    If (s = 'DOUBLE2') or (s = 'DOUBLEDOWN2') or (s = 'DD2') then
  1273.     begin
  1274.       If NodeStat[NodeData.from] = 2 then
  1275.       begin
  1276.         If NodeData.from = NodeTurn then
  1277.         begin
  1278.           If NodeHand2[NodeData.from] = '' then
  1279.             GiveMSG (9, '', '^A^nYou don''t have a second hand!', NodeData.from)
  1280.           else
  1281.           begin
  1282.             if Length(NodeHand2[NodeData.from]) <= 4 then
  1283.             begin
  1284.               BroadcastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^ndoubles down on second hand.', NodeData.from);
  1285.               NodeHand2[NodeData.from] := NodeHand2[NodeData.from] + GetCard;
  1286.               NodeDD2[NodeData.from] := 2;
  1287.               GiveMSG (9, '', '^A^nOk, you ^A^pdouble down^A^n!', NodeData.from);
  1288.               DisplayHand (NodeData.from);
  1289.               SecPassed := 0;
  1290.               Writeln (NodeUser(NodeTurn), ' doubles down on second hand.');
  1291.               If HandValue(NodeHand2[NodeData.from]) > 21 then
  1292.               begin
  1293.                 GiveMSG (9, '', '^I^nYou busted!', NodeData.from);
  1294.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+' ^A^nbusts!', NodeData.from);
  1295.                 BroadCastBut (9, '', '^A^p'+NodeUser(NodeTurn)+'^I^n loses ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD2[NodeTurn])
  1296.                               +' ^A^nCyberdollars!', NodeData.from);
  1297.                 GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[NodeTurn]*NodeDD2[NodeTurn])+' ^A^nCyberdollars!',
  1298.                          NodeData.from);
  1299.                 Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD2[NodeData.from]);
  1300.                 Writeln (NodeUser(NodeTurn), ' busts.');
  1301.               end;
  1302.               NodeDoneH2[NodeData.from] := True;
  1303.               If NodeDoneH1[NodeData.from] and NodeDoneH2[NodeData.from] then NextPlayer;
  1304.             end
  1305.             else
  1306.             GiveMSG (9, '', '^a^nYou can''t double down after hitting!', NodeData.from);
  1307.           end
  1308.         end
  1309.         else
  1310.           GiveMSG (9, '', '^A^nIt is not your turn!', NodeData.from);
  1311.       end
  1312.       else
  1313.         GiveMSG (9, '',  '^A^nYou aren''t playing in the ^A^pblackjack^A^n game.', NodeData.from);
  1314.     end;}
  1315.     If (s='TURN')or(s='TUR')or(s='TUNR') then
  1316.     begin
  1317.       If GamePlaying then
  1318.       begin
  1319.         If NodeTurn = NodeData.from then
  1320.           GiveMSG (9, '', '^A^nIt is ^A^pyour ^A^nturn in blackjack.',
  1321.                    NodeData.from)
  1322.         else
  1323.           GiveMSG (9, '', '^A^nIt is ^A^p'+NodeUser(NodeTurn)+'^A^n''s turn in blackjack.',
  1324.                    NodeData.from);
  1325.       end
  1326.       else
  1327.         GiveMSG (9, '', '^A^nThere is no blackjack game being played at the moment.', NodeData.from);
  1328.     end;
  1329.     If (s='SCAN')or(s='SCA')or(s='SCNA') then
  1330.     begin
  1331.       GiveMSG (9, '', #13#10'^A^oPlayer                          Playing    Cyberdollars', NodeData.from);
  1332.       GiveMSG (9, '', '^A^o-------------------------------------------------------', NodeData.from);
  1333.       For I := 1 to 255 do
  1334.       begin
  1335.         If NodeStat[I] = 1 then
  1336.           GiveMSG (9, '', '^A^o'+NodeUser(I)+Spaces(34-Length(KillTOPCodes(NodeUser(I)))) +' No         '+ToStr(NodeCD[I]),
  1337.                    NodeData.from);
  1338.         If NodeStat[I] = 2 then
  1339.           GiveMSG (9, '', '^A^o'+NodeUser(I)+Spaces(34-Length(KillTOPCodes(NodeUser(I)))) +'Yes         '+ToStr(NodeCD[I]),
  1340.                    NodeData.from);
  1341.       end;
  1342.       GiveMSG (9, '', #0, NodeData.from);
  1343.     end;
  1344.     If (s='BET')or(s='BTE') then
  1345.       GiveMSG (9, '', '^A^nYour current bet is ^A^p'+ToStr(NodeBet[NodeData.from])+' ^A^nCyberdollars.', NodeData.from)
  1346.     else
  1347.     If (s[1] = 'B') and (s[2] = 'E') and (s[3] = 'T') and (s[0] > #3) then
  1348.     begin
  1349.       If NodeStat[NodeData.from] < 2 then
  1350.       begin
  1351.         Delete (s, 1, 3);
  1352.         Val (s, L, Error);
  1353.         If (Error <> 0) or (L > ConfigData.MaxBet) or (L < ConfigData.MinBet) then
  1354.         begin
  1355.           GiveMSG (9, '', '^A^nBets must be between ^A^p'+ToStr(ConfigData.MinBet)+' ^A^nand ^A^p'+ToStr(ConfigData.MaxBet)+
  1356.                    ' ^A^nCyberdollars.', NodeData.from);
  1357.         end
  1358.         else
  1359.         begin
  1360.           NodeBet[NodeData.from] := L;
  1361.           GiveMSG (9, '', '^A^nOk, your bet will now be ^A^p'+ToStr(L)+' ^A^nCyberdollars.', NodeData.from);
  1362.         end;
  1363.       end
  1364.       else
  1365.         GiveMSG (9, '', '^A^nSorry, you cannot change your bet during a game.', NodeData.from);
  1366.     end;
  1367.   end;
  1368.   If (NodeData.Kind = 3) or (NodeData.Kind = 19) then
  1369.   begin
  1370.     If NodeStat[NodeData.from] = 2 then
  1371.     begin
  1372.       For J := 1 to NodeNumHands[Node] do
  1373.       If (HandValue (NodeHand[J, Node]) < 22) then
  1374.       Dec (NodeCD[NodeData.from], NodeBet[NodeData.from]*NodeDD[J, NodeData.from]);
  1375.       If NodeInsure[Node] then Dec (NodeCD[Node], Round(NodeBet[Node]/2));
  1376.       NodeStat[NodeData.from] := 0;
  1377.       BroadCastBut (9,'','^A^p'+CStr(NodeData.Alias)+' ^A^nis dealt out of the ^A^pblackjack^A^n game!',
  1378.                     NodeData.from);
  1379.       Writeln (CStr(NodeData.Alias), ' is dealt out of the blackjack game.');
  1380.       If (NodeData.from) = NodeTurn then NextPlayer;
  1381.     end;
  1382.     NodeCD[NodeData.from] := ConfigData.StartCD;
  1383.     NodeBet[NodeData.from] := ConfigData.BetCD;
  1384.   end;
  1385.   If (NodeData.Kind = 1) then
  1386.   begin
  1387.     s := UpStr(CStr(NodeData.Data));
  1388.     For J := 1 to 16 do
  1389.       If s = ComList[J] then GiveMSG (6, '^A^pThe blackjack dealer', 'You missed a "^A^k/^A^o" in your blackjack command.'
  1390.                                       , NodeData.from);
  1391.   end;
  1392.   If (NodeData.Kind = 10) and (NodeData.DoneTo = Node) then
  1393.   begin
  1394.     s := CStr(NodeData.Data);
  1395.     If Pos ('just barfed ALL OVER', s) <> 0 then Retal (NodeData.from);
  1396.     If Pos ('just bonked',s) <> 0 then Retal (NodeData.from);
  1397.     If Pos ('is booting',s) <> 0 then Retal (NodeData.from);
  1398.     If Pos ('with a disruptor!',s) <> 0 then Retal (NodeData.from);
  1399.     If Pos ('just tossed a grenade!',s) <> 0 then Retal (NodeData.from);
  1400.     If Pos ('is hitting',s) <> 0 then Retal (NodeData.from);
  1401.     If Pos ('is kicking the life out of',s) <> 0 then Retal (NodeData.from);
  1402.     If Pos ('with a mushroom cloud!',s) <> 0 then Retal (NodeData.from);
  1403.     If Pos ('a phaser and blasted',s) <> 0 then Retal (NodeData.from);
  1404.     If Pos ('is punching',s) <> 0 then Retal (NodeData.from);
  1405.     If Pos ('just shot',s) <> 0 then Retal (NodeData.from);
  1406.     If Pos ('just slapped',s) <> 0 then Retal (NodeData.from);
  1407.     If Pos ('across the back of the head!',s) <> 0 then Retal (NodeData.from);
  1408.     If Pos ('just spit on',s) <> 0 then Retal (NodeData.from);
  1409.     If Pos ('is stripping',s) <> 0 then Retal (NodeData.from);
  1410.     If Pos ('just zapped',s) <> 0 then Retal (NodeData.from);
  1411.     If Pos ('just bashed',s) <> 0 then Retal (NodeData.from);
  1412.     If Pos ('just stapled',s) <> 0 then Retal (NodeData.from);
  1413.     If Pos ('just killed',s) <> 0 then Retal (NodeData.from);
  1414.     If Pos ('just elbowed',s) <> 0 then Retal (NodeData.from);
  1415.     If Pos ('just poked',s) <> 0 then Retal (NodeData.from);
  1416.   end;
  1417. end;
  1418.  
  1419. Procedure GetMSGs;
  1420. Var
  1421.   b : byte;
  1422.   z : byte;
  1423.   f : file of byte;
  1424.   NodeFile : File of NodeRec;
  1425. begin
  1426.   z := 0;
  1427.   Assign (f, IPCDir + 'MIX'+NodeStr+'.TCH');
  1428.   Assign (NodeFile, IPCDir + 'MSG'+NodeStr+'.TCH');
  1429.   Reset (f);
  1430.   Reset (NodeFile);
  1431.   Repeat
  1432.     {$I-}
  1433.     Repeat
  1434.       Read (f,b);
  1435.     Until IOResult = 0;
  1436.     Seek (f, FilePos (f) - 1);
  1437.     Repeat
  1438.       Write (f,z);
  1439.     Until IOResult = 0;
  1440.     Repeat
  1441.       Read (NodeFile, NodeData);
  1442.     Until IOResult = 0;
  1443.     {$I+}
  1444.     If b = 1 then Process (NodeData);
  1445.   Until Eof (f);
  1446.   Close (f);
  1447.   Close (NodeFile);
  1448.   b := 0;
  1449.   Assign (f, IPCDir + 'CHGIDX.TCH');
  1450.   Reset (f);
  1451.   Seek (f, node);
  1452.   {$I-}
  1453.   Repeat
  1454.     Write (f,b);
  1455.   Until IOResult = 0;
  1456.   {$I+}
  1457.   Close (f);
  1458. end;
  1459.  
  1460. Procedure WaitSec;
  1461. begin
  1462.   GetTime (L, L, OldSec, L);
  1463.   Repeat
  1464.     GetTime (L, L, Sec, L);
  1465.   Until Sec <> OldSec;
  1466.   OldSec := Sec;
  1467.   Inc (SecPassed);
  1468. end;
  1469.  
  1470. Procedure StartGame;
  1471. Var
  1472.   SomeoneIn : Boolean;
  1473.   I : Word;
  1474. begin
  1475.   Writeln ('Starting a new blackjack game');
  1476.  { UsedCards := ''; }
  1477.   NodeData2.DoneTo := -1;
  1478.   NodeData2.From := node;
  1479.   NodeData2.Gender := 0;
  1480.   NodeData2.Alias := '';
  1481.   NodeData2.Kind := 9;
  1482.   NodeData2.Channel := 1;
  1483.   NodeData2.MinSec := 0;
  1484.   NodeData2.Data1 := 0;
  1485.   SomeoneIn := False;
  1486.   { Get dealer's hand }
  1487.   DealerHand := GetCard + GetCard;
  1488.   If (Random(5) = 0) {and (not registered)} then RegRemind;
  1489.   For I := 1 to 255 do
  1490.     If NodeStat[I] > 0 then
  1491.     begin
  1492.       SomeoneIn := True;
  1493.       GiveMSG (9, '', #0, I);
  1494.       GiveMSG (9, '', '^A^nA new ^A^pblackjack ^A^ngame has begun!', I);
  1495.       NodeStat[I] := 2;
  1496.     end;
  1497.   { Deal first cards }
  1498.   For I := 1 to 255 do
  1499.     If NodeStat[I] = 2 then
  1500.     begin
  1501.       NodeNumHands[I] := 1;
  1502.       NodeHand[1, I] := GetCard + GetCard;
  1503.       GiveMSG (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand[1]+DealerHand[2])+'^H^a  ^A^n  (^A^p'
  1504.                +ToStr(HandValue(DealerHand[1]+DealerHand[2]))+'^A^n)', I);
  1505.       GiveMSG (9, '', '^A^nYour cards:     '+ColorHand(NodeHand[1, I])+' ^A^n(^A^p'+ToStr(HandValue(NodeHand[1, I]))+'^A^n)',
  1506.                I);
  1507.       If DealerHand[1] = 'A' then GiveMSG (9, '',
  1508.         '^A^nDealer has possible blackjack, you may want to make an insurance bet.', I);
  1509.     end;
  1510.   If SomeoneIn then
  1511.   begin
  1512.     For I := 255 downto 1 do If NodeStat[I] = 2 then NodeTurn := I;
  1513.     GamePlaying := True;
  1514.     GiveMSG (9, '', '^A^nIt is your turn in ^A^pblackjack^A^n!', NodeTurn);
  1515.     Writeln ('It is ', NodeUser(NodeTurn), '''s turn in blackjack.');
  1516.   end
  1517.   else Writeln ('No players.');
  1518.   SecPassed := 0;
  1519. end;
  1520.  
  1521. Procedure WarnUser;
  1522. begin
  1523.   GiveMSG (9, '', #7'^I^nIt is still your turn in ^I^pblackjack^A^n!', NodeTurn);
  1524.   WaitSec;
  1525. end;
  1526.  
  1527. Procedure DealerPlay;
  1528. Var
  1529.   H : Word;
  1530.   I : Word;
  1531.   DealerValue : Word;
  1532. begin
  1533.   BroadCast (9, '', '');
  1534.   BroadCast (9, '', '^A^nThe ^A^pBlackjack dealer ^A^nnow plays.');
  1535.   WaitSec;
  1536.   BroadCast (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand)+' ^A^n(^A^p'+ToStr(HandValue(DealerHand))+'^A^n)');
  1537.   WaitSec;
  1538.   While HandValue (DealerHand) < 17 do
  1539.   begin
  1540.     Writeln ('Dealer hits.');
  1541.     BroadCast (9, '', '^A^pDealer ^A^nhits.');
  1542.     DealerHand := DealerHand + GetCard;
  1543.     WaitSec;
  1544.     BroadCast (9, '', '^A^nDealer''s cards: '+ColorHand(DealerHand)+' ^A^n(^A^p'+ToStr(HandValue(DealerHand))+'^A^n)');
  1545.     WaitSec;
  1546.   end;
  1547.   WaitSec;
  1548.   If HandValue (DealerHand) < 22 then BroadCast (9, '', '^A^pDealer ^A^nstays.'#13#10)
  1549.   else BroadCast (9, '', '^A^pDealer ^A^nbusts!'#13#10);
  1550.   BroadCast (9, '', '^A^nThe ^A^pblackjack ^A^ngame is over!');
  1551.  
  1552.   { Pay the winners }
  1553.   DealerValue := HandValue (DealerHand);
  1554.   If DealerValue > 21 then DealerValue := 0;
  1555.   If (DealerValue = 21) and (Length (DealerHand) = 4) then
  1556.   begin
  1557.     { Blackjack for dealer }
  1558.     BroadCast (9, '', '^A^nThe ^A^pdealer ^A^nhas a ^I^pblackjack^A^n!');
  1559.     For I := 1 to 255 do if NodeStat[I] = 2 then
  1560.     begin
  1561.       If NodeInsure[I] then
  1562.       begin
  1563.         Inc (NodeCD[I], Round (NodeBet[I]));
  1564.         GiveMSG (9, '', '^A^pYou^I^n win ^A^nyour insurance bet and get ^A^p'+ToStr(Round(NodeBet[I]))
  1565.                  +' ^A^nCyberdollars!', I);
  1566.         If NodeGender (I) then
  1567.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^nher insurance bet and gets ^A^p'
  1568.                         +ToStr(Round(NodeBet[I]))+' ^A^nCyberdollars!', I)
  1569.         else
  1570.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^nhis insurance bet and gets ^A^p'
  1571.                         +ToStr(Round(NodeBet[I]))+' ^A^nCyberdollars!', I)
  1572.       end;
  1573.       For H := 1 to NodeNumHands[I] do
  1574.       begin
  1575.       If (HandValue (NodeHand[H, I]) = 21) and (Length(NodeHand[H, I]) = 4) then
  1576.       begin
  1577.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s hand #'+ToStr(H)+': '+ColorHand(NodeHand[H, I])+
  1578.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1579.         GiveMSG (9, '', '^A^pYour^A^n hand #'+ToStr(H)+':   '+ColorHand(NodeHand[H, I])+
  1580.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1581.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1582.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1583.       end
  1584.       else
  1585.       begin
  1586.         If HandValue (NodeHand[H, I]) < 22 then
  1587.         begin
  1588.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s hand #'+ToStr(H)+': '+ColorHand(NodeHand[H, I])+
  1589.                         ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1590.           GiveMSG (9, '', '^A^pYour^A^n hand #'+ToStr(H)+':   '+ColorHand(NodeHand[H, I])+
  1591.                   ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1592.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1593.           GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1594.           Dec (NodeCD[I], NodeBet[I]*NodeDD[H, I]);
  1595.         end;
  1596.       end;
  1597. {      If (HandValue (NodeHand2[I]) = 21) and (Length(NodeHand2[I]) = 4) and
  1598.          (NodeHand2[I] <> '') then
  1599.       begin
  1600.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s second hand: '+ColorHand(NodeHand2[I])+
  1601.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1602.         GiveMSG (9, '', '^A^pYour^A^n second hand: '+ColorHand(NodeHand2[I])+
  1603.                    ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1604.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1605.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1606.       end
  1607.       else
  1608.       begin
  1609.         If (NodeHand2[I] <> '') and (HandValue (NodeHand2[I]) < 22) then
  1610.         begin
  1611.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s second hand: '+ColorHand(NodeHand2[I])+
  1612.                      ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1613.           GiveMSG (9, '', '^A^pYour^A^n second hand: '+ColorHand(NodeHand2[I])+
  1614.                      ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1615.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1616.           GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1617.           Dec (NodeCD[I], NodeBet[I]*NodeDD2[I]);
  1618.         end;
  1619.       end;}
  1620.       end;
  1621.     end;
  1622.   end
  1623.   else
  1624.   For I := 1 to 255 do if NodeStat[I] = 2 then
  1625.   begin
  1626.     For H := 1 to NodeNumHands[I] do
  1627.     begin
  1628.     If HandValue (NodeHand[H, I]) < 22 then
  1629.     begin
  1630.       BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s hand #'+ToStr(H)+': '+ColorHand(NodeHand[H, I])+
  1631.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1632.       GiveMSG (9, '', '^A^pYour^A^n hand #'+ToStr(H)+':   '+ColorHand(NodeHand[H, I])+
  1633.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand[H, I]))+'^A^n)', I);
  1634.       If (HandValue (NodeHand[H, I]) = 21) and (Length (NodeHand[H, I]) = 4) then
  1635.       begin
  1636.         { Blackjack }
  1637.         GiveMSG (9, '', '^I^nYou got a ^I^pblackjack^I^n!', I);
  1638.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+' ^A^nhas a ^A^pblackjack^A^n!', I);
  1639.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))
  1640.                           +' ^A^nCyberdollars!', I);
  1641.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))+' ^A^nCyberdollars!', I);
  1642.         Inc (NodeCD[I], Round(NodeBet[I]*(3/2)));
  1643.         Writeln (NodeUser(I), ' gets a blackjack.');
  1644.       end
  1645.       else
  1646.       If HandValue (NodeHand[H, I]) > DealerValue then
  1647.       begin
  1648.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1649.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1650.         Inc (NodeCD[I], NodeBet[I]*NodeDD[H, I]);
  1651.       end
  1652.       else
  1653.       If HandValue (NodeHand[H, I]) < DealerValue then
  1654.       begin
  1655.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1656.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD[H, I])+' ^A^nCyberdollars!',I);
  1657.         Dec (NodeCD[I], NodeBet[I]*NodeDD[H, I]);
  1658.       end
  1659.       else
  1660.       If HandValue (NodeHand[H, I]) = DealerValue then
  1661.       begin
  1662.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1663.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1664.       end;
  1665.       If NodeInsure[I] then
  1666.       begin
  1667.         Dec (NodeCD[I], Round (NodeBet[I]/2));
  1668.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^nyour insurance bet of ^A^p'+ToStr(Round(NodeBet[I]/2))
  1669.                  +' ^A^nCyberdollars!', I);
  1670.         If NodeGender (I) then
  1671.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nher insurance bet of ^A^p'
  1672.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1673.         else
  1674.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nhis insurance bet of ^A^p'
  1675.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1676.       end;
  1677.     end;
  1678.     end;
  1679. {    If (NodeHand2[I] <> '') and (HandValue (NodeHand2[I]) < 22) then
  1680.     begin
  1681.       BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n''s second hand: '+ColorHand(NodeHand2[I])+
  1682.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1683.       GiveMSG (9, '', '^A^pYour^A^n second hand: '+ColorHand(NodeHand2[I])+
  1684.                  ' ^A^n(^A^p'+ToStr(HandValue(NodeHand2[I]))+'^A^n)', I);
  1685.       If (HandValue (NodeHand2[I]) = 21) and (Length (NodeHand2[I]) = 4) then
  1686.       begin}
  1687.         { Blackjack }{
  1688.         GiveMSG (9, '', '^I^nYou got a ^I^pblackjack^I^n!', I);
  1689.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+' ^A^nhas a ^A^pblackjack^A^n!', I);
  1690.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))
  1691.                           +' ^A^nCyberdollars!', I);
  1692.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(Round(NodeBet[I]*(3/2)))+' ^A^nCyberdollars!', I);
  1693.         Inc (NodeCD[I], Round(NodeBet[I]*(3/2)));
  1694.         Writeln (NodeUser(I), ' gets a blackjack.');
  1695.       end
  1696.       else
  1697.       If HandValue (NodeHand2[I]) > DealerValue then
  1698.       begin
  1699.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n wins ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1700.         GiveMSG (9, '', '^A^pYou^I^n win ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1701.         Inc (NodeCD[I], NodeBet[I]*NodeDD2[I]);
  1702.       end
  1703.       else
  1704.       If HandValue (NodeHand2[I]) < DealerValue then
  1705.       begin
  1706.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1707.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^p'+ToStr(NodeBet[I]*NodeDD2[I])+' ^A^nCyberdollars!',I);
  1708.         Dec (NodeCD[I], NodeBet[I]*NodeDD2[I]);
  1709.       end
  1710.       else
  1711.       If HandValue (NodeHand2[I]) = DealerValue then
  1712.       begin
  1713.         BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^A^n loses nothing.',I);
  1714.         GiveMSG (9, '', '^A^pYou^A^n lose nothing.',I);
  1715.       end;
  1716.       If NodeInsure[I] then
  1717.       begin
  1718.         Dec (NodeCD[I], Round (NodeBet[I]/2));
  1719.         GiveMSG (9, '', '^A^pYou^I^n lose ^A^nyour insurance bet of ^A^p'+ToStr(Round(NodeBet[I]/2))
  1720.                  +' ^A^nCyberdollars!', I);
  1721.         If NodeGender (I) then
  1722.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nher insurance bet of ^A^p'
  1723.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1724.         else
  1725.           BroadCastBut (9, '', '^A^p'+NodeUser(I)+'^I^n loses ^A^nhis insurance bet of ^A^p'
  1726.                         +ToStr(Round(NodeBet[I]/2))+' ^A^nCyberdollars!', I)
  1727.       end;
  1728.     end;}
  1729.   end;
  1730.   GamePlaying := False;
  1731.   SecPassed := 0;
  1732.   For I := 1 to 255 do
  1733.   begin
  1734.     If NodeStat[I] = 2 then NodeStat[I] := 1;
  1735.     For H := 1 to 6 do
  1736.     begin
  1737.       NodeHand[H, I] := '';
  1738.       NodeDD[H, I] := 1;
  1739.       NodeDoneH[H, I] := False;
  1740.     end;
  1741.     NodeNumHands[I] := 0;
  1742.     NodeInsure[I] := False;
  1743.   end;
  1744. end;
  1745.  
  1746. Procedure BootUser;
  1747. begin
  1748.   GiveMSG (9, '', #7'^I^nYou have been thrown out of the ^I^pblackjack^I^n game for taking too long!', NodeTurn);
  1749.   BroadCastBut (9, '', '^A^nThe ^A^pBlackjack dealer^A^n has thrown ^A^p'+NodeUser(NodeTurn)
  1750.                 +'^A^n out of the game for taking too long!', NodeTurn);
  1751.   NodeStat[NodeTurn] := 0;
  1752.   Dec (NodeCD[NodeTurn], NodeBet[NodeTurn]);
  1753.   WaitSec;
  1754.   NextPlayer;
  1755. end;
  1756.  
  1757. Procedure RunBJ;
  1758. Var
  1759.   ch : Char;
  1760. begin
  1761.   ch := #0;
  1762.   OldSec := 0;
  1763.   SecPassed := 0;
  1764.   GamePlaying := False;
  1765.   Repeat
  1766.     GetTime (L, L, Sec, L);
  1767.     If Sec <> OldSec then
  1768.     begin
  1769.       OldSec := Sec;
  1770.       Inc (SecPassed);
  1771.     end;
  1772.     If not GamePlaying and (SecPassed > ConfigData.TimeBetweenGames) then StartGame;
  1773.     If GamePlaying and (SecPassed = ConfigData.FirstWarn) then WarnUser;
  1774.     If GamePlaying and (SecPassed = ConfigData.SecondWarn) then WarnUser;
  1775.     If GamePlaying and (SecPassed = ConfigData.BootFromBJ) then BootUser;
  1776.     If MSGWait then GetMSGs;
  1777.     TimeSlice (2);
  1778.     If (NodeTurn = -1) and (GamePlaying) then DealerPlay;
  1779.     If Keypressed then ch := Readkey;
  1780.   Until ch = #27;
  1781. end;
  1782.  
  1783. begin
  1784.   InitProgram;
  1785.   InitTOP;
  1786.   InitScreen;
  1787.   InitVars;
  1788.   RunBJ;
  1789.   DeInit;
  1790. end.
  1791.