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@192
|
13 (defn read-stats
|
rlm@192
|
14 ([^SaveState state poke-num]
|
rlm@192
|
15 (let [start (pokemon-stats-address poke-num)
|
rlm@192
|
16 [level
|
rlm@192
|
17 hp-h
|
rlm@192
|
18 hp-l
|
rlm@192
|
19 attack-h
|
rlm@192
|
20 attack-l
|
rlm@192
|
21 defense-h
|
rlm@192
|
22 defense-l
|
rlm@192
|
23 speed-h
|
rlm@192
|
24 speed-l
|
rlm@192
|
25 special-h
|
rlm@192
|
26 special-l]
|
rlm@192
|
27 (subvec (vec (memory state))
|
rlm@192
|
28 start (+ start stats-record-size ))]
|
rlm@192
|
29 {:level level
|
rlm@192
|
30 :hp (glue-bytes hp-h hp-l)
|
rlm@192
|
31 :attack (glue-bytes attack-h attack-l)
|
rlm@192
|
32 :defense (glue-bytes defense-h defense-l)
|
rlm@192
|
33 :speed (glue-bytes speed-h speed-l)
|
rlm@192
|
34 :special (glue-bytes special-h special-l)}))
|
rlm@192
|
35 ([poke-num]
|
rlm@192
|
36 (read-stats @current-state poke-num)))
|
rlm@192
|
37
|
rlm@192
|
38 (defn give-stats
|
rlm@192
|
39 ([^SaveState state poke-num new-stats]
|
rlm@192
|
40 (let [new-stats* (merge (read-stats state poke-num)
|
rlm@192
|
41 new-stats)
|
rlm@192
|
42 raw-stats
|
rlm@192
|
43 (flatten
|
rlm@192
|
44 [(:level new-stats*)
|
rlm@192
|
45 (disect-bytes-2 (:hp new-stats*))
|
rlm@192
|
46 (disect-bytes-2 (:attack new-stats*))
|
rlm@192
|
47 (disect-bytes-2 (:defense new-stats*))
|
rlm@192
|
48 (disect-bytes-2 (:speed new-stats*))
|
rlm@192
|
49 (disect-bytes-2 (:special new-stats*))])]
|
rlm@192
|
50 (set-memory-range state (pokemon-stats-address poke-num)
|
rlm@192
|
51 raw-stats)))
|
rlm@192
|
52 ([poke-num new-stats]
|
rlm@192
|
53 (give-stats @current-state poke-num new-stats)))
|