Mercurial > vba-clojure
diff clojure/com/aurellem/gb/stats.clj @ 192:fd549c8f42ae
fixed compilation problems, added more functionality to pokemon-info
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 22:35:57 -0500 |
parents | |
children | 1ce54929bc0c |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/clojure/com/aurellem/gb/stats.clj Thu Mar 22 22:35:57 2012 -0500 1.3 @@ -0,0 +1,53 @@ 1.4 +(ns com.aurellem.gb.stats 1.5 + (:use (com.aurellem.gb gb-driver util constants)) 1.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 1.7 + 1.8 +(def pokemon-1-stats-start-address 0xD18B) 1.9 + 1.10 +(defn pokemon-stats-address [poke-num] 1.11 + (+ pokemon-1-stats-start-address 1.12 + (* poke-num pokemon-record-width))) 1.13 + 1.14 +(def stats-record-size 11) 1.15 + 1.16 +(defn read-stats 1.17 + ([^SaveState state poke-num] 1.18 + (let [start (pokemon-stats-address poke-num) 1.19 + [level 1.20 + hp-h 1.21 + hp-l 1.22 + attack-h 1.23 + attack-l 1.24 + defense-h 1.25 + defense-l 1.26 + speed-h 1.27 + speed-l 1.28 + special-h 1.29 + special-l] 1.30 + (subvec (vec (memory state)) 1.31 + start (+ start stats-record-size ))] 1.32 + {:level level 1.33 + :hp (glue-bytes hp-h hp-l) 1.34 + :attack (glue-bytes attack-h attack-l) 1.35 + :defense (glue-bytes defense-h defense-l) 1.36 + :speed (glue-bytes speed-h speed-l) 1.37 + :special (glue-bytes special-h special-l)})) 1.38 + ([poke-num] 1.39 + (read-stats @current-state poke-num))) 1.40 + 1.41 +(defn give-stats 1.42 + ([^SaveState state poke-num new-stats] 1.43 + (let [new-stats* (merge (read-stats state poke-num) 1.44 + new-stats) 1.45 + raw-stats 1.46 + (flatten 1.47 + [(:level new-stats*) 1.48 + (disect-bytes-2 (:hp new-stats*)) 1.49 + (disect-bytes-2 (:attack new-stats*)) 1.50 + (disect-bytes-2 (:defense new-stats*)) 1.51 + (disect-bytes-2 (:speed new-stats*)) 1.52 + (disect-bytes-2 (:special new-stats*))])] 1.53 + (set-memory-range state (pokemon-stats-address poke-num) 1.54 + raw-stats))) 1.55 + ([poke-num new-stats] 1.56 + (give-stats @current-state poke-num new-stats)))