view clojure/com/aurellem/gb/status.clj @ 186:531e1342ff56

merged changes.
author Dylan Holmes <ocsenave@gmail.com>
date Thu, 22 Mar 2012 07:03:02 -0500
parents d63886d63b2f
children 893c753f8088
line wrap: on
line source
1 (ns com.aurellem.gb.status
2 (:use (com.aurellem.gb gb-driver util constants pokemon))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
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)})
18 (def status-code->status-name
19 (zipmap (vals status-name->status-code)
20 (keys status-name->status-code)))
22 (def pokemon-1-status-address 0xD16E)
24 (defn pokemon-status-address [poke-num]
25 (+ pokemon-1-status-address
26 (* poke-num pokemon-record-width)))
28 (defn give-stat
29 ([^SaveState state poke-num status]
30 (assert (<= 0 poke-num 5))
31 (let [status-code
32 (status-name->status-code status)]
33 (assert status-code)
34 (set-memory state
35 (pokemon-status-address poke-num)
36 status-code)))
37 ([poke-num status]
38 (give-stat @current-state poke-num status))
39 ([status]
40 (give-stat @current-state 0 status)))
42 (defn give-stat-all
43 ([^SaveState state status]
44 (reduce (fn [state num]
45 (give-stat state num status))
46 state
47 (range (party-number state))))
48 ([status]
49 (give-stat-all @current-state status)))