comparison clojure/com/aurellem/gb/status.clj @ 176:95b2758dd517

wrote functions to read and write pokemon DV values and status
author Robert McIntyre <rlm@mit.edu>
date Wed, 21 Mar 2012 22:13:43 -0500
parents
children d63886d63b2f
comparison
equal deleted inserted replaced
175:5d9a7a0ca09a 176:95b2758dd517
1 (ns com.aurellem.gb.status
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
4
5 (def status-name->status-code
6 {:normal (Integer/parseInt "00000000" 2)
7 :sleep-1 (Integer/parseInt "00000001" 2)
8 :sleep-2 (Integer/parseInt "00000010" 2)
9 :sleep-3 (Integer/parseInt "00000011" 2)
10 :sleep-4 (Integer/parseInt "00000100" 2)
11 :sleep-5 (Integer/parseInt "00000101" 2)
12 :sleep-6 (Integer/parseInt "00000111" 2)
13 :poisoned (Integer/parseInt "00001000" 2)
14 :burned (Integer/parseInt "00010000" 2)
15 :frozen (Integer/parseInt "00100000" 2)
16 :paralyzed (Integer/parseInt "01000000" 2)})
17
18 (def status-code->status-name
19 (zipmap (vals status-name->status-code)
20 (keys status-name->status-code)))
21
22
23 (def pokemon-1-status-address 0xD16E)
24
25 (defn pokemon-status-address [poke-num]
26 (+ pokemon-1-status-address
27 (* poke-num pokemon-record-width)))
28
29 (defn give-stat
30 ([^SaveState state poke-num status]
31 (assert (<= 0 poke-num 5))
32 (let [status-code
33 (status-name->status-code status)]
34 (assert status-code)
35 (set-memory state
36 (pokemon-status-address poke-num)
37 status-code)))
38 ([poke-num status]
39 (give-stat @current-state poke-num status))
40 ([status]
41 (give-stat @current-state 0 status)))
42
43 (defn give-stat-all
44 ([^SaveState state status]
45 (reduce (fn [state num]
46 (give-stat state num status))
47 state
48 (range (party-number state))))
49 ([status]
50 (give-stat-all @current-state status)))