Mercurial > vba-clojure
diff clojure/com/aurellem/gb/hxc.clj @ 259:b2f9a0cb13e3
Added hardcoded evolution data.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Mon, 26 Mar 2012 18:34:06 -0500 |
parents | 2b6bd03feb4f |
children | a44a2c459aeb |
line wrap: on
line diff
1.1 --- a/clojure/com/aurellem/gb/hxc.clj Mon Mar 26 18:01:39 2012 -0500 1.2 +++ b/clojure/com/aurellem/gb/hxc.clj Mon Mar 26 18:34:06 2012 -0500 1.3 @@ -9,6 +9,23 @@ 1.4 1.5 ; ************* HANDWRITTEN CONSTANTS 1.6 1.7 + 1.8 + 1.9 +(defn low-high 1.10 + [low high] 1.11 + (+ low (* 256 high))) 1.12 + 1.13 + 1.14 +(defn format-name 1.15 + "Convert the string of alphabetic/space characters into a keyword by 1.16 + replacing spaces with hyphens and converting to lowercase." 1.17 + [s] 1.18 + (keyword (.toLowerCase 1.19 + (apply str 1.20 + (map #(if (= % \space) "-" %) s))))) 1.21 + 1.22 + 1.23 + 1.24 (def pkmn-types 1.25 [:normal 1.26 :fighting 1.27 @@ -53,7 +70,7 @@ 1.28 "0x19 chance of burn" 1.29 "0x19 chance of freeze" 1.30 "0x19 chance of paralyze" 1.31 - "user faints; opponent defense halved." 1.32 + "user faints; opponent defense halved during attack." 1.33 "leech half of inflicted damage ONLY if sleeping opponent." 1.34 "imitate last attack" 1.35 "user atk +1" 1.36 @@ -141,7 +158,7 @@ 1.37 ;; ************** HARDCODED DATA 1.38 1.39 (defn hxc-thunk 1.40 - "Creates a thunk (unary fn) that grabs data in a certain region of rom and 1.41 + "Creates a thunk (nullary fn) that grabs data in a certain region of rom and 1.42 splits it into a collection by 0x50. If rom is not supplied, uses the 1.43 original rom data." 1.44 [start length] 1.45 @@ -179,6 +196,78 @@ 1.46 ROM@27E77" 1.47 (hxc-thunk-words 0x27E77 196)) 1.48 1.49 + 1.50 +(def hxc-pokedex-text 1.51 + "The hardcoded pokedex entries in memory. List begins at 1.52 +ROM@B8000, shortly before move names." 1.53 + (hxc-thunk-words 0xB8000 14754)) 1.54 + 1.55 + 1.56 +;; In red/blue, pokemon are in internal order. 1.57 +;; In yellow, pokemon are in pokedex order. 1.58 + 1.59 +(defn hxc-pokedex-stats 1.60 + ;; uses hxc-pokedex-text to count pokemon 1.61 + ;; since hxc-pokenames includes several missingno" 1.62 + ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom)) 1.63 + ([rom] 1.64 + (let [poketext (hxc-pokedex-text) 1.65 + pkmn-count (count poketext) 1.66 + ] 1.67 + ((fn capture-stats 1.68 + [n stats data] 1.69 + (if (zero? n) stats 1.70 + (let [[species 1.71 + [_ 1.72 + height-ft 1.73 + height-in 1.74 + weight-1 1.75 + weight-2 1.76 + _ 1.77 + dex-ptr-1 1.78 + dex-ptr-2 1.79 + dex-bank 1.80 + _ 1.81 + & data]] 1.82 + (split-with (partial not= 0x50) data)] 1.83 + (recur (dec n) 1.84 + (assoc stats 1.85 + (- pkmn-count n) 1.86 + {:species 1.87 + (character-codes->str species) 1.88 + :height-ft 1.89 + height-ft 1.90 + :height-in 1.91 + height-in 1.92 + :weight 1.93 + (/ (low-high weight-1 weight-2) 10.) 1.94 + 1.95 + ;; :text 1.96 + ;; (character-codes->str 1.97 + ;; (take-while 1.98 + ;; (partial not= 0x50) 1.99 + ;; (drop 1.100 + ;; (+ 0xB8000 1.101 + ;; -0x4000 1.102 + ;; (low-high dex-ptr-1 dex-ptr-2)) 1.103 + ;; rom))) 1.104 + }) 1.105 + 1.106 + data) 1.107 + 1.108 + 1.109 + ))) 1.110 + 1.111 + pkmn-count 1.112 + {} 1.113 + (drop 0x40687 rom))) )) 1.114 + 1.115 + 1.116 + 1.117 + 1.118 + 1.119 + 1.120 + 1.121 (def hxc-places 1.122 "The hardcoded place names in memory. List begins at 1.123 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated." 1.124 @@ -198,10 +287,7 @@ 1.125 (hxc-dialog com.aurellem.gb.gb-driver/original-rom))) 1.126 1.127 1.128 -(def hxc-pokedex 1.129 - "The hardcoded pokedex entries in memory. List begins at 1.130 -ROM@B8000, shortly before move names." 1.131 - (hxc-thunk-words 0xB8000 14754)) 1.132 + 1.133 1.134 (def hxc-move-names 1.135 "The hardcoded move names in memory. List begins at ROM@BC000" 1.136 @@ -217,11 +303,7 @@ 1.137 ([rom] 1.138 (let [names (vec (hxc-move-names rom)) 1.139 move-count (count names) 1.140 - move-size 6 1.141 - format-name (fn [s] 1.142 - (keyword (.toLowerCase 1.143 - (apply str 1.144 - (map #(if (= % \space) "-" %) s)))))] 1.145 + move-size 6] 1.146 (zipmap (map format-name names) 1.147 (map 1.148 (fn [[idx effect power type accuracy pp]] 1.149 @@ -287,6 +369,22 @@ 1.150 (drop 0xE8000 1.151 rom)))))))) 1.152 1.153 + 1.154 + 1.155 + 1.156 +(defn internal-id 1.157 + ([rom] 1.158 + (zipmap 1.159 + (map format-name (hxc-pokenames rom)) 1.160 + (range))) 1.161 + ([] 1.162 + (internal-id com.aurellem.gb.gb-driver/original-rom))) 1.163 + 1.164 + 1.165 + 1.166 + 1.167 + 1.168 + 1.169 (defn hxc-advantage 1.170 "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here), 1.171 the multiplier is 1." 1.172 @@ -303,7 +401,92 @@ 1.173 1.174 1.175 1.176 +(defn format-evo 1.177 + [[method x y z & _]] 1.178 + (cond (= 0 method) 1.179 + {:method :none} 1.180 + (= 1 method) 1.181 + {:method :level-up 1.182 + :min-level x 1.183 + :into y} 1.184 + (= 2 method) 1.185 + {:method :item 1.186 + :item-id x 1.187 + :min-level y 1.188 + :into z} 1.189 + (= 3 method) 1.190 + {:method :trade 1.191 + :min-level x 1.192 + :into y})) 1.193 1.194 +(defn format-evo* 1.195 + [[method x y z & _]] 1.196 + (cond (= 0 method) 1.197 + {:method :none} 1.198 + (= 1 method) 1.199 + {:method :level-up 1.200 + :min-level x 1.201 + :into (format-name (nth (hxc-pokenames) (dec y)))} 1.202 + (= 2 method) 1.203 + {:method :item 1.204 + :item (format-name (nth (hxc-items) (dec x))) 1.205 + :min-level y 1.206 + :into (format-name (nth (hxc-pokenames) (dec z)))} 1.207 + (= 3 method) 1.208 + {:method :trade 1.209 + :min-level x 1.210 + :into (format-name (nth (hxc-pokenames) (dec y)))})) 1.211 + 1.212 +(defn hxc-evolution 1.213 + ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom)) 1.214 + ([rom] 1.215 + (let [names (hxc-pokenames rom) 1.216 + pkmn-count (count names) 1.217 + evo-data (drop 0x33fef rom) 1.218 + ptrs 1.219 + (map (fn [[a b]](low-high a b)) 1.220 + (partition 2 1.221 + (take (* 2 pkmn-count) 1.222 + (drop 0x3b1e5 rom)))) 1.223 + ] 1.224 + (apply assoc {} 1.225 + (interleave 1.226 + (map format-name (hxc-pokenames)) 1.227 + (map 1.228 + (comp 1.229 + format-evo 1.230 + (partial take 5) 1.231 + #(drop % rom) 1.232 + (partial + 0x34000)) 1.233 + ptrs))) 1.234 + 1.235 + ))) 1.236 + 1.237 + 1.238 +(defn hxc-evolution* 1.239 + ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom)) 1.240 + ([rom] 1.241 + (let [names (hxc-pokenames rom) 1.242 + pkmn-count (count names) 1.243 + evo-data (drop 0x33fef rom) 1.244 + ptrs 1.245 + (map (fn [[a b]](low-high a b)) 1.246 + (partition 2 1.247 + (take (* 2 pkmn-count) 1.248 + (drop 0x3b1e5 rom)))) 1.249 + ] 1.250 + (apply assoc {} 1.251 + (interleave 1.252 + (map format-name (hxc-pokenames)) 1.253 + (map 1.254 + (comp 1.255 + format-evo* 1.256 + (partial take 5) 1.257 + #(drop % rom) 1.258 + (partial + 0x34000)) 1.259 + ptrs))) 1.260 + 1.261 + ))) 1.262 1.263 1.264 1.265 @@ -384,4 +567,8 @@ 1.266 (def hxc-species 1.267 (map character-codes->str 1.268 (take-nth 4 dex)))) 1.269 -) 1.270 \ No newline at end of file 1.271 +) 1.272 + 1.273 + 1.274 + 1.275 +