Mercurial > vba-clojure
changeset 186:531e1342ff56
merged changes.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Thu, 22 Mar 2012 07:03:02 -0500 |
parents | c8ec477beeac (current diff) f0c1e5574e81 (diff) |
children | 4e3d5f338750 |
files | clojure/com/aurellem/exp/pokemon-layout clojure/com/aurellem/gb/items.clj |
diffstat | 1 files changed, 58 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/clojure/com/aurellem/gb/types.clj Thu Mar 22 07:03:02 2012 -0500 1.3 @@ -0,0 +1,58 @@ 1.4 +(ns com.aurellem.gb.types 1.5 + (:use (com.aurellem.gb gb-driver util constants)) 1.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 1.7 + 1.8 +(def type-code->type-name 1.9 + {0x00 :normal 1.10 + 0x01 :fighting 1.11 + 0x02 :flying 1.12 + 0x03 :poision 1.13 + 0x04 :ground 1.14 + 0x05 :rock 1.15 + 0x07 :bug 1.16 + 0x08 :ghost 1.17 + 0x14 :fire 1.18 + 0x15 :water 1.19 + 0x16 :grass 1.20 + 0x17 :electric 1.21 + 0x18 :psychic 1.22 + 0x19 :ice 1.23 + 0x1A :dragon}) 1.24 + 1.25 +(def type-name->type-code 1.26 + (zipmap (vals type-code->type-name) 1.27 + (keys type-code->type-name))) 1.28 + 1.29 +(def pokemon-1-types-start-address 0xD16F) 1.30 + 1.31 +(defn pokemon-type-start-address [poke-num] 1.32 + (+ pokemon-1-types-start-address 1.33 + (* pokemon-record-width poke-num))) 1.34 + 1.35 +(defn give-type 1.36 + ([^SaveState state poke-num types] 1.37 + (assert (<= 0 poke-num 5)) 1.38 + (let [types* 1.39 + (if (= (count types) 1) 1.40 + [(first types) (first types)] 1.41 + types)] 1.42 + (set-memory-range 1.43 + state 1.44 + (pokemon-type-start-address poke-num) 1.45 + (map type-name->type-code types)))) 1.46 + ([poke-num types] 1.47 + (give-type @current-state poke-num types))) 1.48 + 1.49 +(defn read-types 1.50 + ([^SaveState state poke-num] 1.51 + (assert (<= 0 poke-num 5)) 1.52 + (let [types-start (pokemon-type-start-address poke-num) 1.53 + [type-1 type-2] 1.54 + (subvec (vec (memory state)) 1.55 + types-start (+ 2 types-start))] 1.56 + (if (= type-1 type-2) 1.57 + [(type-code->type-name type-1)] 1.58 + (mapv type-code->type-name [type-1 type-2])))) 1.59 + ([poke-num] 1.60 + (read-types @current-state poke-num))) 1.61 + 1.62 \ No newline at end of file