diff clojure/com/aurellem/gb/stats.clj @ 202:1ce54929bc0c

enhanced pokemon printing to print out current HP as well as current total HP.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 03:31:49 -0500
parents fd549c8f42ae
children 912496041f98
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/stats.clj	Fri Mar 23 02:44:45 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/stats.clj	Fri Mar 23 03:31:49 2012 -0500
     1.3 @@ -10,6 +10,29 @@
     1.4  
     1.5  (def stats-record-size 11)
     1.6  
     1.7 +(def pokemon-1-current-hp-address 0xD16B)
     1.8 +
     1.9 +(defn current-hp-address [poke-num]
    1.10 +  (+ pokemon-1-current-hp-address
    1.11 +     (* pokemon-record-width poke-num)))
    1.12 +
    1.13 +(defn read-current-hp
    1.14 +  ([^SaveState state poke-num]
    1.15 +     (let [mem (memory state)
    1.16 +           start (current-hp-address poke-num)
    1.17 +           hp-h (aget mem start)
    1.18 +           hp-l (aget mem (inc start))]
    1.19 +       (glue-bytes hp-h hp-l)))
    1.20 +  ([poke-num]
    1.21 +     (read-current-hp @current-state poke-num)))
    1.22 +
    1.23 +(defn set-current-hp
    1.24 +  ([^SaveState state poke-num new-hp]
    1.25 +     (set-memory state (current-hp-address poke-num)
    1.26 +                 (disect-bytes-2 new-hp)))
    1.27 +  ([poke-num new-hp]
    1.28 +     (set-current-hp @current-state poke-num new-hp)))
    1.29 +
    1.30  (defn read-stats
    1.31    ([^SaveState state poke-num]
    1.32       (let [start (pokemon-stats-address poke-num)
    1.33 @@ -27,6 +50,7 @@
    1.34             (subvec (vec (memory state))
    1.35                     start (+ start stats-record-size ))]
    1.36         {:level level
    1.37 +        :current-hp (read-current-hp state poke-num)
    1.38          :hp (glue-bytes hp-h hp-l)
    1.39          :attack (glue-bytes attack-h attack-l)
    1.40          :defense (glue-bytes defense-h defense-l)
    1.41 @@ -47,7 +71,13 @@
    1.42               (disect-bytes-2 (:defense new-stats*))
    1.43               (disect-bytes-2 (:speed new-stats*))
    1.44               (disect-bytes-2 (:special new-stats*))])]
    1.45 -       (set-memory-range state (pokemon-stats-address poke-num)
    1.46 -                         raw-stats)))
    1.47 +       (set-current-hp
    1.48 +        (set-memory-range state (pokemon-stats-address poke-num)
    1.49 +                          raw-stats)
    1.50 +        (:current-hp new-stats*))))
    1.51    ([poke-num new-stats]
    1.52       (give-stats @current-state poke-num new-stats)))
    1.53 +
    1.54 +
    1.55 +       
    1.56 +     
    1.57 \ No newline at end of file