Mercurial > vba-clojure
diff 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 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/clojure/com/aurellem/gb/status.clj Wed Mar 21 22:13:43 2012 -0500 1.3 @@ -0,0 +1,50 @@ 1.4 +(ns com.aurellem.gb.status 1.5 + (:use (com.aurellem.gb gb-driver util constants)) 1.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 1.7 + 1.8 +(def status-name->status-code 1.9 + {:normal (Integer/parseInt "00000000" 2) 1.10 + :sleep-1 (Integer/parseInt "00000001" 2) 1.11 + :sleep-2 (Integer/parseInt "00000010" 2) 1.12 + :sleep-3 (Integer/parseInt "00000011" 2) 1.13 + :sleep-4 (Integer/parseInt "00000100" 2) 1.14 + :sleep-5 (Integer/parseInt "00000101" 2) 1.15 + :sleep-6 (Integer/parseInt "00000111" 2) 1.16 + :poisoned (Integer/parseInt "00001000" 2) 1.17 + :burned (Integer/parseInt "00010000" 2) 1.18 + :frozen (Integer/parseInt "00100000" 2) 1.19 + :paralyzed (Integer/parseInt "01000000" 2)}) 1.20 + 1.21 +(def status-code->status-name 1.22 + (zipmap (vals status-name->status-code) 1.23 + (keys status-name->status-code))) 1.24 + 1.25 + 1.26 +(def pokemon-1-status-address 0xD16E) 1.27 + 1.28 +(defn pokemon-status-address [poke-num] 1.29 + (+ pokemon-1-status-address 1.30 + (* poke-num pokemon-record-width))) 1.31 + 1.32 +(defn give-stat 1.33 + ([^SaveState state poke-num status] 1.34 + (assert (<= 0 poke-num 5)) 1.35 + (let [status-code 1.36 + (status-name->status-code status)] 1.37 + (assert status-code) 1.38 + (set-memory state 1.39 + (pokemon-status-address poke-num) 1.40 + status-code))) 1.41 + ([poke-num status] 1.42 + (give-stat @current-state poke-num status)) 1.43 + ([status] 1.44 + (give-stat @current-state 0 status))) 1.45 + 1.46 +(defn give-stat-all 1.47 + ([^SaveState state status] 1.48 + (reduce (fn [state num] 1.49 + (give-stat state num status)) 1.50 + state 1.51 + (range (party-number state)))) 1.52 + ([status] 1.53 + (give-stat-all @current-state status)))