Mercurial > vba-clojure
view clojure/com/aurellem/gb/stats.clj @ 197:659764a2ea40
break for eating!
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 23 Mar 2012 00:14:37 -0500 |
parents | fd549c8f42ae |
children | 1ce54929bc0c |
line wrap: on
line source
1 (ns com.aurellem.gb.stats2 (:use (com.aurellem.gb gb-driver util constants))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def pokemon-1-stats-start-address 0xD18B)7 (defn pokemon-stats-address [poke-num]8 (+ pokemon-1-stats-start-address9 (* poke-num pokemon-record-width)))11 (def stats-record-size 11)13 (defn read-stats14 ([^SaveState state poke-num]15 (let [start (pokemon-stats-address poke-num)16 [level17 hp-h18 hp-l19 attack-h20 attack-l21 defense-h22 defense-l23 speed-h24 speed-l25 special-h26 special-l]27 (subvec (vec (memory state))28 start (+ start stats-record-size ))]29 {:level level30 :hp (glue-bytes hp-h hp-l)31 :attack (glue-bytes attack-h attack-l)32 :defense (glue-bytes defense-h defense-l)33 :speed (glue-bytes speed-h speed-l)34 :special (glue-bytes special-h special-l)}))35 ([poke-num]36 (read-stats @current-state poke-num)))38 (defn give-stats39 ([^SaveState state poke-num new-stats]40 (let [new-stats* (merge (read-stats state poke-num)41 new-stats)42 raw-stats43 (flatten44 [(:level new-stats*)45 (disect-bytes-2 (:hp new-stats*))46 (disect-bytes-2 (:attack new-stats*))47 (disect-bytes-2 (:defense new-stats*))48 (disect-bytes-2 (:speed new-stats*))49 (disect-bytes-2 (:special new-stats*))])]50 (set-memory-range state (pokemon-stats-address poke-num)51 raw-stats)))52 ([poke-num new-stats]53 (give-stats @current-state poke-num new-stats)))