annotate clojure/com/aurellem/gb/status.clj @ 180:4f5ea93cbaca

determined location of pokemon types; added functions for reading/setting them.
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Mar 2012 01:25:39 -0500
parents d63886d63b2f
children 893c753f8088
rev   line source
rlm@176 1 (ns com.aurellem.gb.status
rlm@179 2 (:use (com.aurellem.gb gb-driver util constants pokemon))
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 (def pokemon-1-status-address 0xD16E)
rlm@176 23
rlm@176 24 (defn pokemon-status-address [poke-num]
rlm@176 25 (+ pokemon-1-status-address
rlm@176 26 (* poke-num pokemon-record-width)))
rlm@176 27
rlm@176 28 (defn give-stat
rlm@176 29 ([^SaveState state poke-num status]
rlm@176 30 (assert (<= 0 poke-num 5))
rlm@176 31 (let [status-code
rlm@176 32 (status-name->status-code status)]
rlm@176 33 (assert status-code)
rlm@176 34 (set-memory state
rlm@176 35 (pokemon-status-address poke-num)
rlm@176 36 status-code)))
rlm@176 37 ([poke-num status]
rlm@176 38 (give-stat @current-state poke-num status))
rlm@176 39 ([status]
rlm@176 40 (give-stat @current-state 0 status)))
rlm@176 41
rlm@176 42 (defn give-stat-all
rlm@176 43 ([^SaveState state status]
rlm@176 44 (reduce (fn [state num]
rlm@176 45 (give-stat state num status))
rlm@176 46 state
rlm@176 47 (range (party-number state))))
rlm@176 48 ([status]
rlm@176 49 (give-stat-all @current-state status)))