\ VP-stats
\ Game statistics
\ 
\ $Id: VP-stats.txt,v 1.1 2000/10/25 01:02:57 kris_johnson Exp $

\ Copyright 2000
\ Kristopher D. Johnson
\ 
\ See LICENSE-JacksOrBetter for the
\ conditions under which you may
\ use, redistribute, or modify this 
\ code, or create derived works.

docneeds VP-globals

.( VP-stats... )

\ Structure containing
\ statistics data
struct
  \ Total number of games played
  2 cells field >gamesPlayed

  \ Total number of hands played
  2 cells field >totalHands

  \ Hands played in current game
  2 cells field >gameHands

  \ Total amount spent
  2 cells field >totalBet

  \ Total amount paid out
  2 cells field >totalPayout

  \ Amount spent in current game
  2 cells field >gameBet

  \ Amount paid out in current game
  2 cells field >gamePayout

  \ Highest # of chips held
  1 cells field >highChips
end-struct Statistics

sizeof Statistics constant /Statistics

\ Global statistics structure
Statistics stats
stats /Statistics 0 fill

variable statsSize

\ Save statistics for
\ restoration at next run
: save-stats ( -- )
  true /Statistics stats >abs
  AppVersion PrefStatistics AppID
  ( saved? size &buf. vers id creator. )
  PrefSetAppPreferences
;

\ Restore global statistics values
\ that were saved by save-stats
: restore-stats ( -- )
  /Statistics statsSize !
  true statsSize >abs stats >abs
  PrefStatistics AppID
  ( saved? &size. &buf. id creator. )
  PrefGetAppPreferences ( n )
  noPreferenceFound = if
    false exit
  then
  statsSize @ /Statistics >=
;

stats >gamesPlayed
constant gamesPlayed

stats >totalHands
constant totalHands

stats >gameHands
constant gameHands

stats >totalBet
constant totalBet

stats >totalPayout
constant totalPayout

stats >gameBet
constant gameBet

stats >gamePayout
constant gamePayout

stats >highChips
constant highChips

: reset-totals ( -- )
  0. gamesPlayed 2!
  0. totalHands 2!
  0. totalBet 2!
  0. totalPayout 2!
  0 highChips !
;

: reset-game-stats ( -- )
  0. gameHands 2!
  0. gameBet 2!
  0. gamePayout 2!
;

: reset-stats ( -- )
  reset-totals
  reset-game-stats
;

