view clojure/com/aurellem/gb/experience.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
line wrap: on
line source
1 (ns com.aurellem.gb.experience
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (def experience-pokemon-1 0xD178)
7 (defn experience-start-address [poke-num]
8 (+ experience-pokemon-1
9 (* pokemon-record-width poke-num)))
11 (def experience-record-width 13)
13 (defn read-experience
14 ([^SaveState state poke-num]
15 (let [start (experience-start-address poke-num)
16 [exp-h
17 exp-m
18 exp-l
19 hp-exp-h
20 hp-exp-l
21 attack-exp-h
22 attack-exp-l
23 defense-exp-h
24 defense-exp-l
25 speed-exp-h
26 speed-exp-l
27 special-exp-h
28 special-exp-l]
29 (subvec (vec (memory state))
30 start (+ experience-record-width start))]
31 {:main-exp (glue-bytes exp-h exp-m exp-l)
32 :hp-exp (glue-bytes hp-exp-h hp-exp-l)
33 :attack-exp (glue-bytes attack-exp-h attack-exp-l)
34 :defense-exp (glue-bytes defense-exp-h defense-exp-l)
35 :speed-exp (glue-bytes speed-exp-h speed-exp-l)
36 :special-exp (glue-bytes special-exp-h special-exp-l)}))
37 ([poke-num]
38 (read-experience @current-state poke-num)))
40 (defn give-experience
41 ([^SaveState state poke-num exp]
42 (let [exp* (merge (read-experience state poke-num) exp)
43 raw-exp-data
44 (flatten
45 [(disect-bytes-3 (:main-exp exp*))
46 (disect-bytes-2 (:hp-exp exp*))
47 (disect-bytes-2 (:attack-exp exp*))
48 (disect-bytes-2 (:defense-exp exp*))
49 (disect-bytes-2 (:speed-exp exp*))
50 (disect-bytes-2 (:special-exp exp*))])]
51 (set-memory-range state
52 (experience-start-address poke-num)
53 raw-exp-data)))
54 ([poke-num exp]
55 (give-experience @current-state poke-num exp)))