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@191
|
30 start (+ experience-record-width start))
|
rlm@191
|
31 glue-bytes (fn [l h]
|
rlm@191
|
32 (+ l (bit-shift-left h 8)))]
|
rlm@191
|
33 {:main-exp (+ (glue-bytes exp-l exp-m)
|
rlm@191
|
34 (bit-shift-left exp-h 16))
|
rlm@191
|
35 :hp-exp (glue-bytes hp-exp-l hp-exp-h)
|
rlm@191
|
36 :attack-exp (glue-bytes attack-exp-l attack-exp-h)
|
rlm@191
|
37 :defense-exp (glue-bytes defense-exp-l defense-exp-h)
|
rlm@191
|
38 :speed-exp (glue-bytes speed-exp-l speed-exp-h)
|
rlm@191
|
39 :special-exp (glue-bytes special-exp-l special-exp-h)}))
|
rlm@191
|
40 ([poke-num]
|
rlm@191
|
41 (read-experience @current-state poke-num)))
|
rlm@191
|
42
|
rlm@191
|
43 (defn give-experience
|
rlm@191
|
44 ([^SaveState state poke-num exp]
|
rlm@191
|
45 (let [exp* (merge (read-experience state poke-num)
|
rlm@191
|
46 exp)
|
rlm@191
|
47
|
rlm@191
|
48 disect-bytes
|
rlm@191
|
49 (fn [exp]
|
rlm@191
|
50 [(bit-shift-right
|
rlm@191
|
51 (bit-and exp 0xFF00) 8)
|
rlm@191
|
52 (bit-and exp 0xFF)])
|
rlm@191
|
53
|
rlm@191
|
54 raw-exp-data
|
rlm@191
|
55 (flatten
|
rlm@191
|
56 [(bit-shift-right (bit-and (:main-exp exp*) 0xFF0000) 16)
|
rlm@191
|
57 (disect-bytes (:main-exp exp*))
|
rlm@191
|
58 (disect-bytes (:hp-exp exp*))
|
rlm@191
|
59 (disect-bytes (:attack-exp exp*))
|
rlm@191
|
60 (disect-bytes (:defense-exp exp*))
|
rlm@191
|
61 (disect-bytes (:speed-exp exp*))
|
rlm@191
|
62 (disect-bytes (:special-exp exp*))])]
|
rlm@191
|
63 (set-memory-range state
|
rlm@191
|
64 (experience-start-address poke-num)
|
rlm@191
|
65 raw-exp-data)))
|
rlm@191
|
66 ([poke-num exp]
|
rlm@191
|
67 (give-experience @current-state poke-num exp)))
|