annotate 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
rev   line source
rlm@176 1 (ns com.aurellem.gb.status
rlm@176 2 (:use (com.aurellem.gb gb-driver util constants))
rlm@176 3 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@176 4
rlm@176 5 (def status-name->status-code
rlm@176 6 {:normal (Integer/parseInt "00000000" 2)
rlm@176 7 :sleep-1 (Integer/parseInt "00000001" 2)
rlm@176 8 :sleep-2 (Integer/parseInt "00000010" 2)
rlm@176 9 :sleep-3 (Integer/parseInt "00000011" 2)
rlm@176 10 :sleep-4 (Integer/parseInt "00000100" 2)
rlm@176 11 :sleep-5 (Integer/parseInt "00000101" 2)
rlm@176 12 :sleep-6 (Integer/parseInt "00000111" 2)
rlm@176 13 :poisoned (Integer/parseInt "00001000" 2)
rlm@176 14 :burned (Integer/parseInt "00010000" 2)
rlm@176 15 :frozen (Integer/parseInt "00100000" 2)
rlm@176 16 :paralyzed (Integer/parseInt "01000000" 2)})
rlm@176 17
rlm@176 18 (def status-code->status-name
rlm@176 19 (zipmap (vals status-name->status-code)
rlm@176 20 (keys status-name->status-code)))
rlm@176 21
rlm@176 22
rlm@176 23 (def pokemon-1-status-address 0xD16E)
rlm@176 24
rlm@176 25 (defn pokemon-status-address [poke-num]
rlm@176 26 (+ pokemon-1-status-address
rlm@176 27 (* poke-num pokemon-record-width)))
rlm@176 28
rlm@176 29 (defn give-stat
rlm@176 30 ([^SaveState state poke-num status]
rlm@176 31 (assert (<= 0 poke-num 5))
rlm@176 32 (let [status-code
rlm@176 33 (status-name->status-code status)]
rlm@176 34 (assert status-code)
rlm@176 35 (set-memory state
rlm@176 36 (pokemon-status-address poke-num)
rlm@176 37 status-code)))
rlm@176 38 ([poke-num status]
rlm@176 39 (give-stat @current-state poke-num status))
rlm@176 40 ([status]
rlm@176 41 (give-stat @current-state 0 status)))
rlm@176 42
rlm@176 43 (defn give-stat-all
rlm@176 44 ([^SaveState state status]
rlm@176 45 (reduce (fn [state num]
rlm@176 46 (give-stat state num status))
rlm@176 47 state
rlm@176 48 (range (party-number state))))
rlm@176 49 ([status]
rlm@176 50 (give-stat-all @current-state status)))