Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/stats.clj @ 192:fd549c8f42ae
fixed compilation problems, added more functionality to pokemon-info
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 22:35:57 -0500 |
parents | |
children | 1ce54929bc0c |
comparison
equal
deleted
inserted
replaced
191:893c753f8088 | 192:fd549c8f42ae |
---|---|
1 (ns com.aurellem.gb.stats | |
2 (:use (com.aurellem.gb gb-driver util constants)) | |
3 (:import [com.aurellem.gb.gb_driver SaveState])) | |
4 | |
5 (def pokemon-1-stats-start-address 0xD18B) | |
6 | |
7 (defn pokemon-stats-address [poke-num] | |
8 (+ pokemon-1-stats-start-address | |
9 (* poke-num pokemon-record-width))) | |
10 | |
11 (def stats-record-size 11) | |
12 | |
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))) | |
37 | |
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))) |