annotate clojure/com/aurellem/gb/experience.clj @ 209:912496041f98

give pokemon appears to work.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 05:45:56 -0500
parents fd549c8f42ae
children
rev   line source
rlm@191 1 (ns com.aurellem.gb.experience
rlm@191 2 (:use (com.aurellem.gb gb-driver util constants))
rlm@191 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@191 4
rlm@191 5 (def experience-pokemon-1 0xD178)
rlm@191 6
rlm@191 7 (defn experience-start-address [poke-num]
rlm@191 8 (+ experience-pokemon-1
rlm@191 9 (* pokemon-record-width poke-num)))
rlm@191 10
rlm@191 11 (def experience-record-width 13)
rlm@191 12
rlm@191 13 (defn read-experience
rlm@191 14 ([^SaveState state poke-num]
rlm@191 15 (let [start (experience-start-address poke-num)
rlm@191 16 [exp-h
rlm@191 17 exp-m
rlm@191 18 exp-l
rlm@191 19 hp-exp-h
rlm@191 20 hp-exp-l
rlm@191 21 attack-exp-h
rlm@191 22 attack-exp-l
rlm@191 23 defense-exp-h
rlm@191 24 defense-exp-l
rlm@191 25 speed-exp-h
rlm@191 26 speed-exp-l
rlm@191 27 special-exp-h
rlm@191 28 special-exp-l]
rlm@191 29 (subvec (vec (memory state))
rlm@192 30 start (+ experience-record-width start))]
rlm@192 31 {:main-exp (glue-bytes exp-h exp-m exp-l)
rlm@192 32 :hp-exp (glue-bytes hp-exp-h hp-exp-l)
rlm@192 33 :attack-exp (glue-bytes attack-exp-h attack-exp-l)
rlm@192 34 :defense-exp (glue-bytes defense-exp-h defense-exp-l)
rlm@192 35 :speed-exp (glue-bytes speed-exp-h speed-exp-l)
rlm@192 36 :special-exp (glue-bytes special-exp-h special-exp-l)}))
rlm@192 37 ([poke-num]
rlm@191 38 (read-experience @current-state poke-num)))
rlm@191 39
rlm@191 40 (defn give-experience
rlm@191 41 ([^SaveState state poke-num exp]
rlm@192 42 (let [exp* (merge (read-experience state poke-num) exp)
rlm@191 43 raw-exp-data
rlm@191 44 (flatten
rlm@192 45 [(disect-bytes-3 (:main-exp exp*))
rlm@192 46 (disect-bytes-2 (:hp-exp exp*))
rlm@192 47 (disect-bytes-2 (:attack-exp exp*))
rlm@192 48 (disect-bytes-2 (:defense-exp exp*))
rlm@192 49 (disect-bytes-2 (:speed-exp exp*))
rlm@192 50 (disect-bytes-2 (:special-exp exp*))])]
rlm@191 51 (set-memory-range state
rlm@191 52 (experience-start-address poke-num)
rlm@191 53 raw-exp-data)))
rlm@191 54 ([poke-num exp]
rlm@191 55 (give-experience @current-state poke-num exp)))