' TWENFIVE.PPE - Written by Dan Shore
' July 19, 1996
'
' Purpose: To allow a user to GAMBLE time or bytes
'
' To install:
'
' 1. Put TWENFIVE.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\TWENFIVE\TWENFIVE.PPE
' Brief one line description of game
'
'
' 3. Edit TWENFIVE.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 bank_bytes ' Current Bank Bytes
INTEGER bank_time ' Current Bank Time
INTEGER gamble_amount ' Amount user gambled
INT x ' Miscellaneous 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)
*$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 = "Twenty-Five"
'
' Read configuration file for Twenty-Five
'
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)
'
PROCEDURE DO_GAMBLE (VAR BOOLEAN did_win)
INT grid_info(10)
INT grid_total
INT y
CLS
DISPFILE PPEPATH() + "GRID", LANG+GRAPH+SEC
'
' Assign values to the 10 grids
'
x = 1
WHILE (x < 11) DO
y = RANDOM(9)
IF (INSTR(hold, STRING(y))) CONTINUE
grid_info(x) = y
hold = hold + STRING(y)
INC x
END WHILE
FPUTLN 7, "Grid Info: A=", grid_info(1), " B=", grid_info(2), " C=", grid_info(3), " D=", grid_info(4), " E=", grid_info(5)
FPUTLN 7, "Grid Info: F=", grid_info(6), " G=", grid_info(7), " H=", grid_info(8), " I=", grid_info(9), " J=", grid_info(10)
'
' Ask user for input
'
NEWLINE
x = 1
hold = ""
WHILE (x < 6) DO
ANSIPOS 15, 18
user_input = ""
main_prompt = READLINE(bank_txt, 30)
INPUTSTR main_prompt, user_input, @X07, 1, "ABCDEFGHIJ", GUIDE+FIELDLEN+UPCASE+ERASELINE
IF (user_input = "") BREAK
FPUTLN 7, READLINE(bank_txt, 31), user_input, READLINE(bank_txt, 32), grid_info(S2I(user_input,36)-9)
IF (INSTR(hold, user_input)) THEN
ANSIPOS 15, 18
PRINT READLINE(bank_txt, 33)
DELAY 36
ANSIPOS 15,18
CLREOL
CONTINUE
ELSE
'
' Show grid value
'
SELECT CASE (user_input)
CASE "A"
ANSIPOS 19, 7
PRINT "@X0C", grid_info(1)
CASE "B"
ANSIPOS 27, 7
PRINT "@X0C", grid_info(2)
CASE "C"
ANSIPOS 35, 7
PRINT "@X0C", grid_info(3)
CASE "D"
ANSIPOS 43, 7
PRINT "@X0C", grid_info(4)
CASE "E"
ANSIPOS 51, 7
PRINT "@X0C", grid_info(5)
CASE "F"
ANSIPOS 19, 12
PRINT "@X0C", grid_info(6)
CASE "G"
ANSIPOS 27, 12
PRINT "@X0C", grid_info(7)
CASE "H"
ANSIPOS 35, 12
PRINT "@X0C", grid_info(8)
CASE "I"
ANSIPOS 43, 12
PRINT "@X0C", grid_info(9)
CASE "J"
ANSIPOS 51, 12
PRINT "@X0C", grid_info(10)
END SELECT
END IF
hold = hold + user_input
grid_total = grid_total + grid_info(S2I(user_input,36)-9)
ANSIPOS 15, 19
PRINT READLINE(bank_txt, 34), grid_total
INC x
END WHILE
'
' See if user picked the correct number
'
ANSIPOS 11, 19
CLREOL
IF (grid_total >= 25) THEN
PRINTLN READLINE(bank_txt, 35)
did_win = TRUE
FPUTLN 7, READLINE(bank_txt, 36), grid_total
FPUTLN 7, READLINE(bank_txt, 37)
NEWLINE
WAIT
ELSE
PRINTLN READLINE(bank_txt, 38), grid_total
PRINTLN READLINE(bank_txt, 39)
FPUTLN 7, READLINE(bank_txt, 40), grid_total
FPUTLN 7, READLINE(bank_txt, 41)
NEWLINE
WAIT
END IF
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() + "TWENFIVE.CFG")) THEN
FAPPEND 6, bank_inf_path + "NODE" + STRING(PCBNODE()) + ".LOG", O_RW, S_DN
FPUTLN 6, "Could not find TWENFIVE.CFG - Module Aborted"
FCLOSE 6
GOTO EXIT_PROG
END IF
FOPEN 1, PPEPATH() + "TWENFIVE.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