# HG changeset patch # User Robert McIntyre # Date 1332397539 18000 # Node ID 4f5ea93cbaca78545e6f198329e7cb610196c1e4 # Parent d63886d63b2f28d37f428bb851c17346bb9414ac determined location of pokemon types; added functions for reading/setting them. diff -r d63886d63b2f -r 4f5ea93cbaca clojure/com/aurellem/exp/play.clj --- a/clojure/com/aurellem/exp/play.clj Wed Mar 21 23:02:45 2012 -0500 +++ b/clojure/com/aurellem/exp/play.clj Thu Mar 22 01:25:39 2012 -0500 @@ -1,8 +1,8 @@ (ns com.aurellem.exp.play "scratchpad namespace" (:use (com.aurellem.gb gb-driver util constants - assembly - items pokemon status + assembly saves + items pokemon status types characters species moves)) (:import java.io.File) (:import [com.aurellem.gb.gb_driver SaveState])) diff -r d63886d63b2f -r 4f5ea93cbaca clojure/com/aurellem/exp/pokemon-layout --- a/clojure/com/aurellem/exp/pokemon-layout Wed Mar 21 23:02:45 2012 -0500 +++ b/clojure/com/aurellem/exp/pokemon-layout Thu Mar 22 01:25:39 2012 -0500 @@ -11,8 +11,8 @@ D16C \l Pokemon 1 Current Hit Points D16D D16E Status -D16F -D170 +D16F Type 1 (does not affect display) +D170 Type 2 (does not affect display) D171 D172 Move 1 ID D173 Move 2 ID @@ -55,8 +55,8 @@ D198 \l Pokemon 2 Current Hit Points D199 D19A Status -D19B -D19C +D19B Type 1 (does not affect display) +D19C Type 2 (does not affect display) D19D D19E Move 1 ID D19F Move 2 ID @@ -99,8 +99,8 @@ D1C4 \l Pokemon 3 Current Hit Points D1C5 D1C6 Status -D1C7 -D1C8 +D1C7 Type 1 (does not affect display) +D1C8 Type 2 (does not affect display) D1C9 D1CA Move 1 ID D1CB Move 2 ID @@ -143,8 +143,8 @@ D1F0 \l Pokemon 4 Current Hit Points D1F1 D1F2 Status -D1F3 -D1F4 +D1F3 Type 1 (does not affect display) +D1F4 Type 2 (does not affect display) D1F5 D1F6 Move 1 ID D1F7 Move 2 ID @@ -187,8 +187,8 @@ D21C \l Pokemon 5 Current Hit Points D21D D21E Status -D21F -D220 +D21F Type 1 (does not affect display) +D220 Type 2 (does not affect display) D221 D222 Move 1 ID D223 Move 2 ID @@ -231,8 +231,8 @@ D248 \l Pokemon 6 Current Hit Points D249 D24A Status -D24B -D24C +D24B Type 1 (does not affect display) +D24C Type 2 (does not affect display) D24D D24E Move 1 ID D24F Move 2 ID diff -r d63886d63b2f -r 4f5ea93cbaca clojure/com/aurellem/exp/pokemon.clj --- a/clojure/com/aurellem/exp/pokemon.clj Wed Mar 21 23:02:45 2012 -0500 +++ b/clojure/com/aurellem/exp/pokemon.clj Thu Mar 22 01:25:39 2012 -0500 @@ -639,7 +639,7 @@ -(defn pre-battle [] (read-state "prepare-for-battle")) + (defn pika-lvl-100-DV-0 [] diff -r d63886d63b2f -r 4f5ea93cbaca clojure/com/aurellem/gb/types.clj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clojure/com/aurellem/gb/types.clj Thu Mar 22 01:25:39 2012 -0500 @@ -0,0 +1,58 @@ +(ns com.aurellem.gb.types + (:use (com.aurellem.gb gb-driver util constants)) + (:import [com.aurellem.gb.gb_driver SaveState])) + +(def type-code->type-name + {0x00 :normal + 0x01 :fighting + 0x02 :flying + 0x03 :poision + 0x04 :ground + 0x05 :rock + 0x07 :bug + 0x08 :ghost + 0x14 :fire + 0x15 :water + 0x16 :grass + 0x17 :electric + 0x18 :psychic + 0x19 :ice + 0x1A :dragon}) + +(def type-name->type-code + (zipmap (vals type-code->type-name) + (keys type-code->type-name))) + +(def pokemon-1-types-start-address 0xD16F) + +(defn pokemon-type-start-address [poke-num] + (+ pokemon-1-types-start-address + (* pokemon-record-width poke-num))) + +(defn give-type + ([^SaveState state poke-num types] + (assert (<= 0 poke-num 5)) + (let [types* + (if (= (count types) 1) + [(first types) (first types)] + types)] + (set-memory-range + state + (pokemon-type-start-address poke-num) + (map type-name->type-code types)))) + ([poke-num types] + (give-type @current-state poke-num types))) + +(defn read-types + ([^SaveState state poke-num] + (assert (<= 0 poke-num 5)) + (let [types-start (pokemon-type-start-address poke-num) + [type-1 type-2] + (subvec (vec (memory state)) + types-start (+ 2 types-start))] + (if (= type-1 type-2) + [(type-code->type-name type-1)] + (mapv type-code->type-name [type-1 type-2])))) + ([poke-num] + (read-types @current-state poke-num))) + \ No newline at end of file