Metropoli BBS
VIEWER: between.pps MODE: TEXT (CP437)
' BETWEEN.PPE - Written by Dan Shore
'                June 5, 1996
'
' Purpose:  To allow a user to GAMBLE time or bytes
'
' To install:
'
'         1.  Put BETWEEN.PPE in it's own subdirectory off of the BANK.PPE
'
'         2.  Edit GAMBLE.DAT - This file contains the name of the
'                               gambling modules (PPE) and a description.
'                               This file resides in the same directory
'                               as BANK.PPE
'
'                               Each gamble ppe that is used with
'                               BANK.PPE will have two lines entered in
'                               this configuration file.  The first is
'                               the full path and name of the PPE.  The
'                               second is a brief description of the
'                               gamble module ppe.
'
'             Example:
'                          C:\PCB\PPE\BANK\BETWEEN\BETWEEN.PPE
'                          Brief one line description of game
'
'
'         3.  Edit BETWEEN.CFG - Consists of two lines w/three fields
'                                 Line #1 = Time Gamble setup
'                                 Line #2 = Byte Gamble setup
'
'             Field #1 = TRUE or FALSE to all that type of gamble
'             Field #2 = Maximum amount that can be gambled
'             Field #3 = Win percentage
'
'             Example:      TRUE;30;.5
'                           TRUE;500000;.5
'
'
' Note about gambling add-ons:
'
'         1.  The gambling module PPE *MUST* read & write to a file called
'             BANK????.INF (???? = node number).  This file contains
'             bank balance information about the current user.
'
'             The "PATH" to this file is passed at the 1st command
'             line parameter (See first line of code).
'
'             This information in this file will be as follows:
'
'               Line #1 = Current Bank Time
'               Line #2 = Current Bank Bytes
'
'──────────────────────────────────────────────────────────────────────────────
'
'  Declare our variables
'
STRING hold                    ' Generic STRING variable
STRING hold2                   ' Generic STRING variable
STRING main_prompt             ' Generic prompt
STRING user_input              ' Generic user input
STRING bank_inf_path           ' Path to BANK????.INF file
STRING mod_name                ' Name of Gambling Modules

STRING allow_time              ' Allow time gamble
STRING time_max                ' Max time to bet
STRING time_win_perc           ' Amount of time when user wins
STRING allow_byte              ' Allow byte gamble
STRING byte_max                ' Max bytes to bet
STRING byte_win_perc           ' Amount of bytes when user wins
STRING bank_txt                ' External Text file

INTEGER size                   ' Generic INTEGER variable
INTEGER bank_bytes             ' Current Bank Bytes
INTEGER bank_time              ' Current Bank Time
INTEGER gamble_amount          ' Amount user gambled

INT  x                         ' Generic INT variable
INT gamble_type                ' Time and/or Byte gamble allowed
                               ' 1 = TIME, 2 = BYTE, 3 = BOTH

FLOAT win_percentage           ' Show user win percentages

BOOLEAN do_time                ' Time or byte gamble
BOOLEAN did_win                ' Flag to show user won
BOOLEAN already_gambled        ' Flag to show user already gambled today
BOOLEAN allow_once             ' Flag to allow player to play more than once
'──────────────────────────────────────────────────────────────────────────────
'
'  Declare our Gambling Procedure.
'
DECLARE PROCEDURE DO_GAMBLE (VAR BOOLEAN did_win)
DECLARE PROCEDURE SHOW_CARD (INT card)

*$USEFUNCS

BEGIN
  '
  '  Retrieve path to bank????.inf file
  '
  bank_inf_path = GETTOKEN()

  '
  '  Define external text file - Support Language Files
  '
  bank_txt = PPEPATH() + "GAMBTXT" + LANGEXT()

  '
  '  Open our Log File and log username
  '
  FAPPEND 7, PPEPATH() + "NODE" + STRING(PCBNODE()) + ".LOG", O_RW, S_DN
  FPUTLN 7, "────────────── " + MIXED(U_NAME()) + " ──────────────"

  '
  '  This is the name of the Gambling Module
  '
  mod_name = "Between Card"

  '
  '  Read configuration file for BETWEEN
  '
  GOSUB READ_CFG

  '
  '  Check to see if user has already gambled today
  '
  IF (allow_once) GOSUB CHECK_IF_PLAYED

  '
  '  Read the .INF file
  '
  GOSUB READ_BANK_INF

  '
  '  Display intro file to explain to user what the game is about.
  '
  '  *** Make sure to tell user they can ONLY gamble what is in the BANK
  '
  '
  DISPFILE PPEPATH() + "INTRO", GRAPH+LANG+SEC
  NEWLINE

  '
  '  Show user if they are allowed to gamble time and/or bytes
  '
  GOSUB ALLOWED_BET

  '
  '  Show user percentage when they win
  '
  GOSUB SHOW_WIN_PERCENTAGE

  '
  '  Ask user if they wish to gamble time or bytes
  '
  GOSUB ASK_TIME_BYTE

  '
  '  Write username to GAM-USER.DAT - This file keeps track of which
  '  users have played the gamble game already today.
  '
  IF (allow_once) THEN
    '
    FPUTLN 2, U_NAME()
    FCLOSE 2
    '
  END IF

  '
  '  Run the gambling game
  '
  DO_GAMBLE (did_win)

  '
  '  Write information back to BANK????.INF file
  '
  GOSUB WRITE_INF

  '
  '  Exit the PPE
  '
  GOTO EXIT_PROG

END

'────────────────────────────────────────────────────
'                Start of Subroutines
'────────────────────────────────────────────────────

'
'  Show user if they are allowed to gamble time and/or bytes
'
:ALLOWED_BET
  '
  '  Inform the user if they are allowed to gamble time or bytes
  '
  IF (allow_time = "TRUE" && bank_time != 0) THEN
    PRINTLN READLINE(bank_txt, 1)
    FPUTLN 7, READLINE(bank_txt, 2)
    gamble_type = 1
  END IF

  IF (allow_byte = "TRUE" && bank_bytes != 0) THEN
    PRINTLN READLINE(bank_txt, 3)
    FPUTLN 7, READLINE(bank_txt, 4)
    IF (gamble_type) THEN
      gamble_type = 3
    ELSE
      gamble_type = 2
    END IF
  END IF
  IF (bank_time = 0 && bank_bytes = 0) THEN
    PRINTLN READLINE(bank_txt, 5)
    FPUTLN 7, READLINE(bank_txt, 6)
    NEWLINE
    WAIT
    GOTO EXIT_PROG
  END IF
  NEWLINE
  RETURN

'
'  Show user what the winners received for time and byte bets
'
:SHOW_WIN_PERCENTAGE

   '
   '  Show time win percentage
   '
   IF (gamble_type = 1 || gamble_type = 3) THEN
     x = TOFLOAT(time_win_perc) * 100
     hold = STRING(x) + "%"
     PRINTLN READLINE(bank_txt, 7), hold, READLINE(bank_txt, 8)
     FPUTLN 7, READLINE(bank_txt, 9), hold
   END IF

   '
   '  Show byte win percentage
   '
   IF (gamble_type > 1) THEN
     x = TOFLOAT(byte_win_perc) * 100
     hold = STRING(x) + "%"
     PRINTLN READLINE(bank_txt, 10), hold, READLINE(bank_txt, 8)
     FPUTLN 7, READLINE(bank_txt, 11), hold
   END IF

   NEWLINE
   RETURN

'
'  Write new information to BANK????.INF file
'
:WRITE_INF

   '
   '  Determine amount won.  Take the amount gambled and multiply
   '  by the percentage defined in the .CFG file
   '
   '  If user loses gamble, deduct amount from bank balance
   '
   IF (did_win) THEN
     IF (do_time) THEN
       '
       '  Calculate winning amount
       '
       gamble_amount = gamble_amount * TOFLOAT(time_win_perc)
       FPUTLN 7, READLINE(bank_txt, 12), gamble_amount, READLINE(bank_txt, 13)
       bank_time = bank_time + gamble_amount
     ELSE
       '
       '  Calculate winning amount
       '
       gamble_amount = gamble_amount * TOFLOAT(byte_win_perc)
       FPUTLN 7, READLINE(bank_txt, 12), gamble_amount, READLINE(bank_txt, 14)
       bank_bytes = bank_bytes + gamble_amount
     END IF
   ELSE
     '
     '  Calculate loss
     '
     IF (do_time) THEN
       bank_time = bank_time - gamble_amount
     ELSE
       bank_bytes = bank_bytes - gamble_amount
     END IF
     '
   END IF

   '
   '  Delete the INF file and write a new file with the new information.
   '
   '  Bank.PPE will read this file when it reloads
   '
   DELETE bank_inf_path + "BANK" + STRING(PCBNODE()) + ".INF"
   FOPEN 1, bank_inf_path + "BANK" + STRING(PCBNODE()) + ".INF", O_WR, S_DN
   FPUTLN 1, STRING(bank_time)
   FPUTLN 1, STRING(bank_bytes)
   FCLOSE 1

   RETURN


'
'  Ask user if they wish to gamble time or bytes. Then ask them how much
'
:ASK_TIME_BYTE

   WHILE (1) DO

     '
     '  If user can gamble time or bytes, prompt them for which type
     '  If user can only bet time OR bytes, then pass this section
     '
     user_input = ""
     IF (gamble_type = 3) THEN
       main_prompt = READLINE(bank_txt, 15)
       INPUTSTR main_prompt, user_input, @X07, 1, "TB", UPCASE+LFAFTER+GUIDE+FIELDLEN
     ELSE IF (gamble_type = 1) THEN
       user_input = "T"
'       FPUTLN 7, READLINE(bank_txt, 16)
     ELSE IF (gamble_type = 2) THEN
       user_input = "B"
'       FPUTLN 7, READLINE(bank_txt, 17)
     END IF

     '
     '  Process user request for time or byte bet.  Or jump to time
     '  or byte bet right away due to user only being able to bet
     '  one type (time or byte) due to bank restrictions.
     '
     IF (user_input != "") THEN
       SELECT CASE (user_input)

         '
         '  Time bet.  Build variables based on time (prompt and max amount)
         '  for next prompt shown to user
         '
         CASE "T"
           FPUTLN 7, READLINE(bank_txt, 16)
           hold = READLINE(bank_txt, 18)
           IF (TOINTEGER(time_max) > bank_time) THEN
             hold2 = STRING(bank_time)
           ELSE
             hold2 = time_max
           END IF
           do_time = TRUE
         '
         '  Byte bet.  Build variables based on bytes (prompt and max amount)
         '  for next prompt shown to user
         '
         CASE "B"
           FPUTLN 7, READLINE(bank_txt, 17)
           hold = READLINE(bank_txt, 19)
           IF (TOINTEGER(byte_max) > bank_bytes) THEN
             hold2 = STRING(bank_bytes)
           ELSE
             hold2 = byte_max
           END IF
           do_time = FALSE
       END SELECT
       user_input = ""

       '
       '  Ask user how much they wish to bet
       '
       WHILE (user_input = "") DO
         user_input = ""
         main_prompt = READLINE(bank_txt, 20) + hold + READLINE(bank_txt, 21) + hold2 + READLINE(bank_txt, 22)
         INPUTSTR main_prompt, user_input, @X07, 9, "0123456789", UPCASE+LFAFTER+GUIDE+FIELDLEN
       END WHILE

       '
       '  See if user wishes to quit.  If not, log bet amount
       '
       IF (user_input = "0" || user_input = "") GOTO EXIT_PROG
       FPUTLN 7, "Amount of bet = ", user_input

       '
       '  See if user entered too large a value
       '
       IF (TOINTEGER(user_input) > TOINTEGER(hold2)) THEN
         NEWLINE
         IF (do_time) THEN
           PRINTLN READLINE(bank_txt, 23), hold2
         ELSE
           PRINTLN READLINE(bank_txt, 24), hold2
         END IF
         FPUTLN 7, READLINE(bank_txt, 25)
         CONTINUE
       END IF

       '
       '  Put gamble amount in gamble variable and exit loop
       '
       gamble_amount = TOINTEGER(user_input)
       BREAK
       '
     ELSE
       '
       '  User hit enter to QUIT gamble
       '
       GOTO EXIT_PROG
       '
     END IF
   END WHILE
   RETURN

'
'  Gamble Module code - Add your gambling code here.  The only thing
'  the gamble code must do is:
'
'  1.  Set "did_win = TRUE" for a winner
'  2.  Log if user wins or loses (FPUTLN 7)
'  3.  Log all gambling activity (easier to track what the program/user did)
'
'
'  You can also add your text to GAMBTXT or leave it in the .PPS file
'
PROCEDURE DO_GAMBLE (VAR BOOLEAN did_win)

  BOOLEAN correct_pick
  INT y, card1, card2

  '
  '  Tell user computer is picking a number
  '
  NEWLINE
  PRINTLN READLINE(bank_txt,30)
  NEWLINE
  PRINT READLINE(bank_txt,31)
  PRINT "."
  DELAY 6
  PRINT "."
  card1 = RANDOM(12) + 1
  card2 = card1
  DELAY 6
  PRINT "."
  '
  '  keep doing random numbers until we get
  '  different cards for each.
  '
  WHILE (card2 = card1) DO
    DELAY 3
    card2 = RANDOM(12) + 1
  END WHILE
  '
  '  Log cards picked by computer
  '
  PRINTLN READLINE(bank_txt,32)
  FPUTLN 7, READLINE(bank_txt,33), card1
  FPUTLN 7, READLINE(bank_txt,34), card2


  NEWLINE
  PRINT READLINE(bank_txt,35), " "
  SHOW_CARD (card1)
  PRINT READLINE(bank_txt,36), " "
  SHOW_CARD (card2)
  '
  '  Ask user for input
  '
  hold2 = YESCHAR() + NOCHAR()
  NEWLINE
  main_prompt = READLINE(bank_txt,37)
  INPUTSTR main_prompt, user_input, @X07, 1, hold2, LFAFTER+GUIDE+FIELDLEN+UPCASE
  user_input = UPPER(user_input)
  IF (user_input = YESCHAR()) THEN
    FPUTLN 7, READLINE(bank_txt,38)
  ELSE
    FPUTLN 7, READLINE(bank_txt,39)
  END IF
  '
  '  Pick next card for user
  '
  y = RANDOM(12) + 1

  '
  '  Show user their card
  '
  NEWLINE
  PRINT READLINE(bank_txt,40), " "
  SHOW_CARD (y)
  FPUTLN 7, READLINE(bank_txt,41), " ", y
  '
  '  See if user made the correct choice
  '
  IF (y != card1 && y != card2) THEN
    SELECT CASE (user_input)
      CASE "Y"
        IF (card1 < card2) THEN
          IF (y <= card2 && y >= card1) correct_pick = TRUE
        ELSE
          IF (y <= card1 && y >= card2) correct_pick = TRUE
        END IF
      CASE "N"
        IF (card1 < card2) THEN
          IF (y > card2 || y < card1) correct_pick = TRUE
        ELSE
          IF (y > card1 || y < card2) correct_pick = TRUE
        END IF
    END SELECT
  ELSE
    NEWLINE
    PRINTLN READLINE(bank_txt,42)
    DELAY 36
  ENDIF
  '
  '  Announce winner or loser
  '
  IF (correct_pick) THEN
    NEWLINE
    PRINTLN READLINE(bank_txt,43)
    did_win = TRUE
    FPUTLN 7, READLINE(bank_txt,44)
    NEWLINES 2
    WAIT
  ELSE
    NEWLINE
    PRINT READLINE(bank_txt,45)
    NEWLINE
    PRINTLN READLINE(bank_txt,46)
    FPUTLN 7, READLINE(bank_txt,47)
    NEWLINES 2
    WAIT
  END IF

ENDPROC

PROCEDURE SHOW_CARD(INT y)

  '
  '  Show cards picked to user
  '
  SELECT CASE (y)
    CASE 1
      PRINTLN "@X0CA"
    CASE 11
      PRINTLN "@X0CJ"
    CASE 12
      PRINTLN "@X0CQ"
    CASE 13
      PRINTLN "@X0CK"
    DEFAULT
      PRINTLN "@X0C",y
  END SELECT

ENDPROC
'
'  Read the BANK????.INF file for current user information
'
:READ_BANK_INF

   FOPEN 1, bank_inf_path + "BANK" + STRING(PCBNODE()) + ".INF", O_RD, S_DN
   FGET 1, hold
   bank_time = TOINTEGER(hold)
   FGET 1, hold
   bank_bytes = TOINTEGER(hold)
   FCLOSE 1
   RETURN

'
'  Common exit point for program
'
:EXIT_PROG

   FPUTLN 7, READLINE(bank_txt, 26)
   FPUTLN 7
   FCLOSE 7
   END

'
'  Read gambling configuration file to determine if time or bytes
'  are allowed to bet.  If so, maximum amounts to bet, and the winning
'  percentage are all defined in this file
'
:READ_CFG

   '
   '  Check for existance of .CFG file
   '
   IF (!EXIST(PPEPATH() + "BETWEEN.CFG")) THEN
     FAPPEND 6, bank_inf_path + "NODE" + STRING(PCBNODE()) + ".LOG", O_RW, S_DN
     FPUTLN 6, "Could not find BETWEEN.CFG - Module Aborted"
     FCLOSE 6
     GOTO EXIT_PROG
   END IF

   FOPEN 1, PPEPATH() + "BETWEEN.CFG", O_RD, S_DN

   '
   '  Continuous Loop
   '
   WHILE (1) DO
     '
     '  See if player is allowed to play more than once per day
     '
     FGET 1, hold
     '
     '  See if line is a comment or blank line
     '
     IF (LEFT(hold,1) = "'" || LEFT(hold,1) = "") CONTINUE
     IF (hold = "TRUE") allow_once = TRUE
     '
     '  Process Time information
     '
     FGET 1, hold
     TOKENIZE hold
     hold = UPPER(hold)
     allow_time = GETTOKEN()
     time_max = GETTOKEN()
     time_win_perc = GETTOKEN()
     '
     '  Process Byte information
     '
     FGET 1, hold
     TOKENIZE hold
     allow_byte = GETTOKEN()
     byte_max = GETTOKEN()
     byte_win_perc = GETTOKEN()
     BREAK
     '
   END WHILE

   FCLOSE 1
   RETURN

'
'  See if the user has already gambled today
'
:CHECK_IF_PLAYED

   '
   '  Check the date file to see if it is a new day.  If it is
   '  delete the file containing the usernames who have gambled today
   '
   '  If the date file does not exist, we will create it
   '
   FOPEN 2, PPEPATH() + "CKDATE.DAT", O_RW, S_DN
   FGET 2, hold
   IF (TODATE(hold) < DATE() || hold = "") THEN
     FREWIND 2
     FPUT 2, DATE()
     DELETE PPEPATH() + "GAM-USER.DAT"
   END IF
   FCLOSE 2

   '
   '  Check to see if user has already gambled today
   '
   FOPEN 2, PPEPATH() + "GAM-USER.DAT", O_RW, S_DN
   WHILE (1) DO
     FGET 2, hold
     IF (FERR(2)) BREAK
     IF (INSTR(hold, U_NAME())) THEN
       NEWLINES 5
       PRINTLN READLINE(bank_txt, 27), mod_name, READLINE(bank_txt, 28)
       NEWLINE
       WAIT
       already_gambled = TRUE
     END IF
   END WHILE

   '
   '  If user already played, exit the program
   '
   IF (already_gambled) THEN
     FPUTLN 7, READLINE(bank_txt, 29)
     GOTO EXIT_PROG
   END IF
   RETURN
[ RETURN TO DIRECTORY ]