annotate clojure/com/aurellem/gb/stats.clj @ 296:659a9c84c785

restored deposit-one-item, working on getting rival's name into item computer.
author Robert McIntyre <rlm@mit.edu>
date Fri, 30 Mar 2012 18:41:39 -0500
parents 912496041f98
children
rev   line source
rlm@192 1 (ns com.aurellem.gb.stats
rlm@192 2 (:use (com.aurellem.gb gb-driver util constants))
rlm@192 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@192 4
rlm@192 5 (def pokemon-1-stats-start-address 0xD18B)
rlm@192 6
rlm@192 7 (defn pokemon-stats-address [poke-num]
rlm@192 8 (+ pokemon-1-stats-start-address
rlm@192 9 (* poke-num pokemon-record-width)))
rlm@192 10
rlm@192 11 (def stats-record-size 11)
rlm@192 12
rlm@202 13 (def pokemon-1-current-hp-address 0xD16B)
rlm@202 14
rlm@202 15 (defn current-hp-address [poke-num]
rlm@202 16 (+ pokemon-1-current-hp-address
rlm@202 17 (* pokemon-record-width poke-num)))
rlm@202 18
rlm@202 19 (defn read-current-hp
rlm@202 20 ([^SaveState state poke-num]
rlm@202 21 (let [mem (memory state)
rlm@202 22 start (current-hp-address poke-num)
rlm@202 23 hp-h (aget mem start)
rlm@202 24 hp-l (aget mem (inc start))]
rlm@202 25 (glue-bytes hp-h hp-l)))
rlm@202 26 ([poke-num]
rlm@202 27 (read-current-hp @current-state poke-num)))
rlm@202 28
rlm@202 29 (defn set-current-hp
rlm@202 30 ([^SaveState state poke-num new-hp]
rlm@209 31 (set-memory-range state (current-hp-address poke-num)
rlm@202 32 (disect-bytes-2 new-hp)))
rlm@202 33 ([poke-num new-hp]
rlm@202 34 (set-current-hp @current-state poke-num new-hp)))
rlm@202 35
rlm@192 36 (defn read-stats
rlm@192 37 ([^SaveState state poke-num]
rlm@192 38 (let [start (pokemon-stats-address poke-num)
rlm@192 39 [level
rlm@192 40 hp-h
rlm@192 41 hp-l
rlm@192 42 attack-h
rlm@192 43 attack-l
rlm@192 44 defense-h
rlm@192 45 defense-l
rlm@192 46 speed-h
rlm@192 47 speed-l
rlm@192 48 special-h
rlm@192 49 special-l]
rlm@192 50 (subvec (vec (memory state))
rlm@192 51 start (+ start stats-record-size ))]
rlm@192 52 {:level level
rlm@202 53 :current-hp (read-current-hp state poke-num)
rlm@192 54 :hp (glue-bytes hp-h hp-l)
rlm@192 55 :attack (glue-bytes attack-h attack-l)
rlm@192 56 :defense (glue-bytes defense-h defense-l)
rlm@192 57 :speed (glue-bytes speed-h speed-l)
rlm@192 58 :special (glue-bytes special-h special-l)}))
rlm@192 59 ([poke-num]
rlm@192 60 (read-stats @current-state poke-num)))
rlm@192 61
rlm@192 62 (defn give-stats
rlm@192 63 ([^SaveState state poke-num new-stats]
rlm@192 64 (let [new-stats* (merge (read-stats state poke-num)
rlm@192 65 new-stats)
rlm@192 66 raw-stats
rlm@192 67 (flatten
rlm@192 68 [(:level new-stats*)
rlm@192 69 (disect-bytes-2 (:hp new-stats*))
rlm@192 70 (disect-bytes-2 (:attack new-stats*))
rlm@192 71 (disect-bytes-2 (:defense new-stats*))
rlm@192 72 (disect-bytes-2 (:speed new-stats*))
rlm@192 73 (disect-bytes-2 (:special new-stats*))])]
rlm@209 74 (set-current-hp
rlm@202 75 (set-memory-range state (pokemon-stats-address poke-num)
rlm@202 76 raw-stats)
rlm@209 77 poke-num
rlm@202 78 (:current-hp new-stats*))))
rlm@192 79 ([poke-num new-stats]
rlm@192 80 (give-stats @current-state poke-num new-stats)))
rlm@202 81
rlm@202 82
rlm@202 83
rlm@202 84