Mercurial > vba-clojure
diff clojure/com/aurellem/exp/pokemon.clj @ 169:4857f59f63a6
added functions to read and set DV values for pokemon.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 21 Mar 2012 01:37:10 -0500 |
parents | 04dfda91db9c |
children | 63ec3db6f6d1 |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/exp/pokemon.clj Tue Mar 20 20:26:00 2012 -0500 1.2 +++ b/clojure/com/aurellem/exp/pokemon.clj Wed Mar 21 01:37:10 2012 -0500 1.3 @@ -657,6 +657,193 @@ 1.4 (defn pre-battle [] (read-state "prepare-for-battle")) 1.5 1.6 1.7 +(defn pika-lvl-100-DV-0 [] 1.8 + (read-state "at-pc-lv-100-pikachu")) 1.9 1.10 +;; Performed following experiment: 1.11 +;; Raised Pikachu to Lvl 100 with rare-candies, 1.12 +;; then put it at the head of the party and 1.13 +;; set 0xD185 and 0xD186 to zero. 1.14 1.15 +;; then, for each pattern, deposited pikachu into 1.16 +;; Box 1 and immediately widthdrew it and observed the 1.17 +;; stats. 1.18 1.19 + 1.20 +;; Pikachu L:100 Base Stats with DVs = 0 1.21 +;; HP : 187 1.22 +;; Attack : 123 1.23 +;; Defense : 73 1.24 +;; Speed : 194 1.25 +;; Special : 112 1.26 + 1.27 +;; 0xD185: 1.28 + 1.29 +;; 00000001 1.30 +;; Defense => 75 (+2) 1.31 +;; HP => 195 (+8) 1.32 + 1.33 +;; 00000010 1.34 +;; Defense => 77 (+4) 1.35 + 1.36 +;; 00000100 1.37 +;; Defense => 81 (+8) 1.38 + 1.39 +;; 00001000 1.40 +;; Defense => 89 (+16) 1.41 + 1.42 +;; 00010000 1.43 +;; HP => 203 (+16) 1.44 +;; Attack => 125 (+2) 1.45 + 1.46 +;; 00100000 1.47 +;; Attack => 127 (+4) 1.48 + 1.49 +;; 01000000 1.50 +;; Attack -> 131 (+8) 1.51 + 1.52 +;; 10000000 1.53 +;; Attack -> 139 (+16) 1.54 + 1.55 +;; 0xD186 1.56 + 1.57 +;; 00000001 1.58 +;; HP => 189 (+2) 1.59 +;; Special => (+2) 1.60 + 1.61 +;; 00000010 1.62 +;; Special => 116 (+4) 1.63 + 1.64 +;; 00000100 1.65 +;; Special => 120 (+8) 1.66 + 1.67 +;; 00001000 1.68 +;; Special => 128 (+16) 1.69 + 1.70 +;; 00010000 1.71 +;; HP => 191 (+4) 1.72 +;; Speed => 196 (+2) 1.73 + 1.74 +;; 00100000 1.75 +;; Speed => 198 (+4) 1.76 + 1.77 +;; 01000000 1.78 +;; Speed => 202 (+8) 1.79 + 1.80 +;; 10000000 1.81 +;; Speed => 210 (+16) 1.82 + 1.83 +(def pokemon-1-DV-start 0xD185) 1.84 + 1.85 +(defn pokemon-DV-start-point [poke-num] 1.86 + (+ (* poke-num pokemon-record-width) 1.87 + pokemon-1-DV-start)) 1.88 + 1.89 +(def reverse-4-bit 1.90 + {0 0 1.91 + 1 8 1.92 + 2 4 1.93 + 3 12 1.94 + 5 10 1.95 + 6 6 1.96 + 7 14 1.97 + 9 9 1.98 + 15 15 1.99 + 13 11 1.100 + 1.101 + 8 1 1.102 + 4 2 1.103 + 12 3 1.104 + 10 5 1.105 + 11 13 1.106 + 14 7 }) 1.107 + 1.108 +(defn read-DV 1.109 + ([^SaveState state poke-num] 1.110 + (assert (<= 0 poke-num 5)) 1.111 + (let [[raw-DV-1 1.112 + raw-DV-2] 1.113 + (subvec (vec (memory state)) 1.114 + (pokemon-DV-start-point poke-num) 1.115 + (+ 2 (pokemon-DV-start-point poke-num))) 1.116 + defense-DV (bit-and raw-DV-1 0x0F) 1.117 + attack-DV (bit-shift-right 1.118 + (bit-and raw-DV-1 0xF0) 1.119 + 4) 1.120 + special-DV (bit-and raw-DV-2 0x0F) 1.121 + speed-DV (bit-shift-right 1.122 + (bit-and raw-DV-2 0xF0) 1.123 + 4) 1.124 + HP-DV 1.125 + (+ 1.126 + (if (bit-test special-DV 0) 1 0) 1.127 + (if (bit-test speed-DV 0) 2 0) 1.128 + (if (bit-test defense-DV 0) 4 0) 1.129 + (if (bit-test attack-DV 0) 8 0))] 1.130 + {:attack attack-DV 1.131 + :defense defense-DV 1.132 + :speed speed-DV 1.133 + :special special-DV 1.134 + :hp HP-DV})) 1.135 + ([poke-num] 1.136 + (read-DV @current-state poke-num))) 1.137 + 1.138 + 1.139 +(defn give-DV 1.140 + ([^SaveState state poke-num dv-values] 1.141 + 1.142 + (assert (<= 0 poke-num 5)) 1.143 + (map #(assert (<= 0 % 15)) (vals dv-values)) 1.144 + (let [raw-dv-1* 1.145 + (+ (:defense dv-values) 1.146 + (bit-shift-left (:attack dv-values) 4)) 1.147 + raw-dv-2* 1.148 + (+ (:special dv-values) 1.149 + (bit-shift-left (:speed dv-values) 4)) 1.150 + hp-dv (:hp dv-values) 1.151 + hp-masks-1 1.152 + [[0 (bit-test hp-dv 2)] 1.153 + [4 (bit-test hp-dv 3)]] 1.154 + hp-masks-2 1.155 + [[0 (bit-test hp-dv 0)] 1.156 + [4 (bit-test hp-dv 1)]] 1.157 + set-hp-bits 1.158 + (fn [init [index hp?]] 1.159 + (if hp? 1.160 + (bit-set init index) 1.161 + (bit-clear init index))) 1.162 + 1.163 + raw-dv-1 (reduce set-hp-bits raw-dv-1* 1.164 + hp-masks-1) 1.165 + 1.166 + raw-dv-2 (reduce set-hp-bits raw-dv-2* 1.167 + hp-masks-2) 1.168 + 1.169 + dv-start (pokemon-DV-start-point poke-num)] 1.170 + 1.171 + (if (or (not= raw-dv-1* raw-dv-1) 1.172 + (not= raw-dv-2* raw-dv-2)) 1.173 + (println "Warning: inconsistent DV-values." 1.174 + "Using HP settings.")) 1.175 + 1.176 + (set-memory 1.177 + (set-memory state dv-start raw-dv-1) 1.178 + (inc dv-start) raw-dv-2))) 1.179 + ([poke-num dv-values] 1.180 + (give-DV @current-state poke-num dv-values))) 1.181 + 1.182 +(def good-DVs 1.183 + {:attack 15 1.184 + :defense 15 1.185 + :speed 15 1.186 + :special 15 1.187 + :hp 15}) 1.188 + 1.189 +(def bad-DVs 1.190 + {:attack 0 1.191 + :defense 0 1.192 + :speed 0 1.193 + :special 0 1.194 + :hp 0}) 1.195 + 1.196 + 1.197 \ No newline at end of file