Mercurial > vba-clojure
changeset 192:fd549c8f42ae
fixed compilation problems, added more functionality to pokemon-info
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 22:35:57 -0500 |
parents | 893c753f8088 |
children | da1a5ed61a8d |
files | clojure/com/aurellem/gb/experience.clj clojure/com/aurellem/gb/moves.clj clojure/com/aurellem/gb/pokemon.clj clojure/com/aurellem/gb/stats.clj clojure/com/aurellem/gb/status.clj clojure/com/aurellem/gb/util.clj |
diffstat | 6 files changed, 145 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/experience.clj Thu Mar 22 20:10:09 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/experience.clj Thu Mar 22 22:35:57 2012 -0500 1.3 @@ -27,39 +27,27 @@ 1.4 special-exp-h 1.5 special-exp-l] 1.6 (subvec (vec (memory state)) 1.7 - start (+ experience-record-width start)) 1.8 - glue-bytes (fn [l h] 1.9 - (+ l (bit-shift-left h 8)))] 1.10 - {:main-exp (+ (glue-bytes exp-l exp-m) 1.11 - (bit-shift-left exp-h 16)) 1.12 - :hp-exp (glue-bytes hp-exp-l hp-exp-h) 1.13 - :attack-exp (glue-bytes attack-exp-l attack-exp-h) 1.14 - :defense-exp (glue-bytes defense-exp-l defense-exp-h) 1.15 - :speed-exp (glue-bytes speed-exp-l speed-exp-h) 1.16 - :special-exp (glue-bytes special-exp-l special-exp-h)})) 1.17 - ([poke-num] 1.18 + start (+ experience-record-width start))] 1.19 + {:main-exp (glue-bytes exp-h exp-m exp-l) 1.20 + :hp-exp (glue-bytes hp-exp-h hp-exp-l) 1.21 + :attack-exp (glue-bytes attack-exp-h attack-exp-l) 1.22 + :defense-exp (glue-bytes defense-exp-h defense-exp-l) 1.23 + :speed-exp (glue-bytes speed-exp-h speed-exp-l) 1.24 + :special-exp (glue-bytes special-exp-h special-exp-l)})) 1.25 + ([poke-num] 1.26 (read-experience @current-state poke-num))) 1.27 1.28 (defn give-experience 1.29 ([^SaveState state poke-num exp] 1.30 - (let [exp* (merge (read-experience state poke-num) 1.31 - exp) 1.32 - 1.33 - disect-bytes 1.34 - (fn [exp] 1.35 - [(bit-shift-right 1.36 - (bit-and exp 0xFF00) 8) 1.37 - (bit-and exp 0xFF)]) 1.38 - 1.39 + (let [exp* (merge (read-experience state poke-num) exp) 1.40 raw-exp-data 1.41 (flatten 1.42 - [(bit-shift-right (bit-and (:main-exp exp*) 0xFF0000) 16) 1.43 - (disect-bytes (:main-exp exp*)) 1.44 - (disect-bytes (:hp-exp exp*)) 1.45 - (disect-bytes (:attack-exp exp*)) 1.46 - (disect-bytes (:defense-exp exp*)) 1.47 - (disect-bytes (:speed-exp exp*)) 1.48 - (disect-bytes (:special-exp exp*))])] 1.49 + [(disect-bytes-3 (:main-exp exp*)) 1.50 + (disect-bytes-2 (:hp-exp exp*)) 1.51 + (disect-bytes-2 (:attack-exp exp*)) 1.52 + (disect-bytes-2 (:defense-exp exp*)) 1.53 + (disect-bytes-2 (:speed-exp exp*)) 1.54 + (disect-bytes-2 (:special-exp exp*))])] 1.55 (set-memory-range state 1.56 (experience-start-address poke-num) 1.57 raw-exp-data)))
2.1 --- a/clojure/com/aurellem/gb/moves.clj Thu Mar 22 20:10:09 2012 -0500 2.2 +++ b/clojure/com/aurellem/gb/moves.clj Thu Mar 22 22:35:57 2012 -0500 2.3 @@ -191,7 +191,7 @@ 2.4 (map 2.5 move-code->move-name 2.6 (subvec (vec (memory state)) 2.7 - start (+ start (num-moves state poke-num)))))))) 2.8 + start (+ start 4))))))) 2.9 ([poke-num] 2.10 (read-moves @current-state poke-num))) 2.11 2.12 @@ -240,7 +240,7 @@ 2.13 (bit-and 2.14 pp-raw 2.15 (Integer/parseInt "00111111" 2))] 2.16 - [pp-up current-pp])) 2.17 + {:pp-ups pp-up :current-pp current-pp})) 2.18 ([pokemon-num move-num] 2.19 (read-pp @current-state pokemon-num move-num))) 2.20
3.1 --- a/clojure/com/aurellem/gb/pokemon.clj Thu Mar 22 20:10:09 2012 -0500 3.2 +++ b/clojure/com/aurellem/gb/pokemon.clj Thu Mar 22 22:35:57 2012 -0500 3.3 @@ -1,7 +1,7 @@ 3.4 (ns com.aurellem.gb.pokemon 3.5 (:use (com.aurellem.gb gb-driver util constants characters 3.6 moves types items status dv species 3.7 - experience 3.8 + experience stats 3.9 )) 3.10 (:import [com.aurellem.gb.gb_driver SaveState])) 3.11 3.12 @@ -66,7 +66,12 @@ 3.13 (partition name-width raw-names))))) 3.14 ([] (original-trainers @current-state))) 3.15 3.16 -(defn set-original-trainer 3.17 +(defn read-OT-name 3.18 + ([^SaveState state poke-num] 3.19 + (nth (original-trainers state) poke-num)) 3.20 + ([poke-num] (read-OT @current-state poke-num))) 3.21 + 3.22 +(defn set-OT-name 3.23 "Set the OT name for a pokemon. 3.24 Note that a pokemon is still considered 'yours' if 3.25 the OT ID is the same as your own." 3.26 @@ -82,18 +87,25 @@ 3.27 3.28 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252]) 3.29 3.30 -(defn set-pokemon-id 3.31 - ([^SaveState state n new-id] 3.32 - (assert (<= 0 n (dec (party-number state)))) 3.33 - (assert (<= 0 new-id 0xFFFF)) 3.34 +(defn read-OT-id 3.35 + ([^SaveState state poke-num] 3.36 + (let [mem (memory state) 3.37 + start (OT-ID-addresses poke-num)] 3.38 + (glue-bytes 3.39 + (aget mem start) 3.40 + (aget mem (inc start))))) 3.41 + ([poke-num] (read-OT-id @current-state poke-num))) 3.42 + 3.43 +(defn set-OT-id 3.44 + ([^SaveState state poke-num new-OT-num] 3.45 + (assert (<= 0 poke-num 5)) 3.46 + (assert (<= 0 new-OT-num 0xFFFF)) 3.47 (set-memory-range 3.48 state 3.49 - (OT-ID-addresses n) 3.50 - [(bit-shift-right (bit-and new-id 0xFF00) 8) 3.51 - (bit-and new-id 0xFF) 3.52 - ])) 3.53 - ([n new-id] 3.54 - (set-pokemon-id @current-state n new-id))) 3.55 + (OT-ID-addresses poke-num) 3.56 + (disect-bytes-2 new-OT-num))) 3.57 + ([poke-num new-OT-num] 3.58 + (set-pokemon-id @current-state poke-num new-OT-num))) 3.59 3.60 (def unknown "[[[UNKNOWN]]]") 3.61 3.62 @@ -204,7 +216,10 @@ 3.63 (range (count moves))) 3.64 nickname (pokemon-nickname state poke-num) 3.65 status (read-status state poke-num) 3.66 + stats (read-stats state poke-num) 3.67 experience (read-experience state poke-num) 3.68 + OT-name (read-OT-name state poke-num) 3.69 + ID (read-OT-id state poke-num) 3.70 ] 3.71 3.72 {:name nickname 3.73 @@ -212,12 +227,26 @@ 3.74 :species2 species2 3.75 :type type 3.76 :dv dv-values 3.77 + :original-trainer OT-name 3.78 + :ID ID 3.79 + 3.80 :moves (zipmap moves moves-pp) 3.81 3.82 :satus status 3.83 + :stats stats 3.84 :experience experience 3.85 + 3.86 } 3.87 )) 3.88 ([poke-num] 3.89 (pokemon-info @current-state poke-num))) 3.90 3.91 + 3.92 +(defn give-status-all 3.93 + ([^SaveState state status] 3.94 + (reduce (fn [state num] 3.95 + (give-status state num status)) 3.96 + state 3.97 + (range (party-number state)))) 3.98 + ([status] 3.99 + (give-status-all @current-state status)))
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/clojure/com/aurellem/gb/stats.clj Thu Mar 22 22:35:57 2012 -0500 4.3 @@ -0,0 +1,53 @@ 4.4 +(ns com.aurellem.gb.stats 4.5 + (:use (com.aurellem.gb gb-driver util constants)) 4.6 + (:import [com.aurellem.gb.gb_driver SaveState])) 4.7 + 4.8 +(def pokemon-1-stats-start-address 0xD18B) 4.9 + 4.10 +(defn pokemon-stats-address [poke-num] 4.11 + (+ pokemon-1-stats-start-address 4.12 + (* poke-num pokemon-record-width))) 4.13 + 4.14 +(def stats-record-size 11) 4.15 + 4.16 +(defn read-stats 4.17 + ([^SaveState state poke-num] 4.18 + (let [start (pokemon-stats-address poke-num) 4.19 + [level 4.20 + hp-h 4.21 + hp-l 4.22 + attack-h 4.23 + attack-l 4.24 + defense-h 4.25 + defense-l 4.26 + speed-h 4.27 + speed-l 4.28 + special-h 4.29 + special-l] 4.30 + (subvec (vec (memory state)) 4.31 + start (+ start stats-record-size ))] 4.32 + {:level level 4.33 + :hp (glue-bytes hp-h hp-l) 4.34 + :attack (glue-bytes attack-h attack-l) 4.35 + :defense (glue-bytes defense-h defense-l) 4.36 + :speed (glue-bytes speed-h speed-l) 4.37 + :special (glue-bytes special-h special-l)})) 4.38 + ([poke-num] 4.39 + (read-stats @current-state poke-num))) 4.40 + 4.41 +(defn give-stats 4.42 + ([^SaveState state poke-num new-stats] 4.43 + (let [new-stats* (merge (read-stats state poke-num) 4.44 + new-stats) 4.45 + raw-stats 4.46 + (flatten 4.47 + [(:level new-stats*) 4.48 + (disect-bytes-2 (:hp new-stats*)) 4.49 + (disect-bytes-2 (:attack new-stats*)) 4.50 + (disect-bytes-2 (:defense new-stats*)) 4.51 + (disect-bytes-2 (:speed new-stats*)) 4.52 + (disect-bytes-2 (:special new-stats*))])] 4.53 + (set-memory-range state (pokemon-stats-address poke-num) 4.54 + raw-stats))) 4.55 + ([poke-num new-stats] 4.56 + (give-stats @current-state poke-num new-stats)))
5.1 --- a/clojure/com/aurellem/gb/status.clj Thu Mar 22 20:10:09 2012 -0500 5.2 +++ b/clojure/com/aurellem/gb/status.clj Thu Mar 22 22:35:57 2012 -0500 5.3 @@ -1,5 +1,5 @@ 5.4 (ns com.aurellem.gb.status 5.5 - (:use (com.aurellem.gb gb-driver util constants pokemon)) 5.6 + (:use (com.aurellem.gb gb-driver util constants)) 5.7 (:import [com.aurellem.gb.gb_driver SaveState])) 5.8 5.9 (def status-name->status-code 5.10 @@ -44,15 +44,7 @@ 5.11 (pokemon-status-address poke-num) 5.12 status-code))) 5.13 ([poke-num status] 5.14 - (give-stat @current-state poke-num status)) 5.15 + (give-status @current-state poke-num status)) 5.16 ([status] 5.17 - (give-stat @current-state 0 status))) 5.18 + (give-status @current-state 0 status))) 5.19 5.20 -(defn give-status-all 5.21 - ([^SaveState state status] 5.22 - (reduce (fn [state num] 5.23 - (give-stat state num status)) 5.24 - state 5.25 - (range (party-number state)))) 5.26 - ([status] 5.27 - (give-stat-all @current-state status)))
6.1 --- a/clojure/com/aurellem/gb/util.clj Thu Mar 22 20:10:09 2012 -0500 6.2 +++ b/clojure/com/aurellem/gb/util.clj Thu Mar 22 22:35:57 2012 -0500 6.3 @@ -110,4 +110,34 @@ 6.4 (read-state "mid-game")) 6.5 6.6 6.7 - 6.8 \ No newline at end of file 6.9 + 6.10 +(defn disect-bytes-2 6.11 + "return a vector consiting of the last 16 bytes of the 6.12 + integer expressed as two 8 bit nimbers (inside an integer) 6.13 + in the form [high-bits low-bits." 6.14 + [num] 6.15 + [(bit-shift-right 6.16 + (bit-and num 0xFF00) 8) 6.17 + (bit-and num 0xFF)]) 6.18 + 6.19 +(defn disect-bytes-3 6.20 + "same as disect-bytes-2 except that it assumes the input is a 6.21 + 24 bit number and returns [high-bits medium-bits low-bits]" 6.22 + [num] 6.23 + (vec 6.24 + (concat 6.25 + [(bit-shift-right (bit-and num 0xFF0000) 16)] 6.26 + (disect-bytes-2 num)))) 6.27 + 6.28 +(defn glue-bytes 6.29 + "Given two or three 8-bit numbers inside 32-bit integers, 6.30 + combine them into the integer number that they together 6.31 + represent." 6.32 + ([h l] 6.33 + (+ l (bit-shift-left h 8))) 6.34 + 6.35 + ([h m l] 6.36 + (+ (glue-bytes m l) 6.37 + (bit-shift-left h 16)))) 6.38 + 6.39 +