view clojure/com/aurellem/gb/stats.clj @ 198:5055ec9de278

competed move-table printing component of pokemon printing function.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 00:30:34 -0500
parents fd549c8f42ae
children 1ce54929bc0c
line wrap: on
line source
1 (ns com.aurellem.gb.stats
2 (: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-address
9 (* poke-num pokemon-record-width)))
11 (def stats-record-size 11)
13 (defn read-stats
14 ([^SaveState state poke-num]
15 (let [start (pokemon-stats-address poke-num)
16 [level
17 hp-h
18 hp-l
19 attack-h
20 attack-l
21 defense-h
22 defense-l
23 speed-h
24 speed-l
25 special-h
26 special-l]
27 (subvec (vec (memory state))
28 start (+ start stats-record-size ))]
29 {:level level
30 :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-stats
39 ([^SaveState state poke-num new-stats]
40 (let [new-stats* (merge (read-stats state poke-num)
41 new-stats)
42 raw-stats
43 (flatten
44 [(: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)))