changeset 259:b2f9a0cb13e3

Added hardcoded evolution data.
author Dylan Holmes <ocsenave@gmail.com>
date Mon, 26 Mar 2012 18:34:06 -0500
parents 2a46422902be
children 1b5c33614b0d
files clojure/com/aurellem/gb/characters.clj clojure/com/aurellem/gb/hxc.clj clojure/com/aurellem/world/practice.clj
diffstat 3 files changed, 235 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/characters.clj	Mon Mar 26 18:01:39 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/characters.clj	Mon Mar 26 18:34:06 2012 -0500
     1.3 @@ -62,16 +62,16 @@
     1.4     0x0 "" ;; separator character?
     1.5     0x58 "\n"
     1.6     ;;0x00   "<";;"end-of-name-sentinel" ;; begin messsage
     1.7 -   ;;0x49   "\n //" ;; ocsenave: pagebreak pokedex
     1.8 -   ;;0x4E   "\n..." ; ocsenave: clearscroll pokedex page
     1.9 -   ;;0x4F   "\n" ; newline
    1.10 -   ;;0x50   "#";;"end-of-pokemon-name-sentinel"
    1.11 -   ;;0x51   "\n\n" ;; ocsenave: clear screen
    1.12 +   0x49   "\n //" ;; ocsenave: pagebreak pokedex
    1.13 +   0x4E   "\n..." ; ocsenave: clearscroll pokedex page
    1.14 +   0x4F   "\n" ; newline
    1.15 +   0x50   "#";;"end-of-pokemon-name-sentinel"
    1.16 +   0x51   "\n\n" ;; ocsenave: clear screen
    1.17     0x52 "[RED]" ;;ocsenave: placeholder for your name?
    1.18     0x54   "[POKE]"
    1.19 -   ;;0x55   "_" ;; ocsenave: breaking space?
    1.20 -   ;0x57   ">" ;; ocsenave: end message
    1.21 -   ;0x5F   ">" ;; ocsenave: end pokedex entry??
    1.22 +   0x55   "_" ;; ocsenave: breaking space?
    1.23 +   0x57   ">" ;; ocsenave: end message
    1.24 +   0x5F   ">" ;; ocsenave: end pokedex entry??
    1.25     0x60   "A-bold"
    1.26     0x61   "B-bold"
    1.27     0x62   "C-bold"
     2.1 --- a/clojure/com/aurellem/gb/hxc.clj	Mon Mar 26 18:01:39 2012 -0500
     2.2 +++ b/clojure/com/aurellem/gb/hxc.clj	Mon Mar 26 18:34:06 2012 -0500
     2.3 @@ -9,6 +9,23 @@
     2.4  
     2.5  ; ************* HANDWRITTEN CONSTANTS
     2.6  
     2.7 +
     2.8 +
     2.9 +(defn low-high
    2.10 +  [low high]
    2.11 +  (+ low (* 256 high)))
    2.12 +  
    2.13 +
    2.14 +(defn format-name
    2.15 +  "Convert the string of alphabetic/space characters into a keyword by
    2.16 +  replacing spaces with hyphens and converting to lowercase."
    2.17 +  [s]
    2.18 +  (keyword (.toLowerCase
    2.19 +            (apply str
    2.20 +                   (map #(if (= % \space) "-" %) s)))))
    2.21 +
    2.22 +  
    2.23 +
    2.24  (def pkmn-types
    2.25    [:normal
    2.26     :fighting
    2.27 @@ -53,7 +70,7 @@
    2.28     "0x19 chance of burn"
    2.29     "0x19 chance of freeze"
    2.30     "0x19 chance of paralyze"
    2.31 -   "user faints; opponent defense halved."
    2.32 +   "user faints; opponent defense halved during attack."
    2.33     "leech half of inflicted damage ONLY if sleeping opponent."
    2.34     "imitate last attack"
    2.35     "user atk +1"
    2.36 @@ -141,7 +158,7 @@
    2.37  ;; ************** HARDCODED DATA
    2.38  
    2.39  (defn hxc-thunk
    2.40 -  "Creates a thunk (unary fn) that grabs data in a certain region of rom and
    2.41 +  "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
    2.42  splits it into a collection by 0x50. If rom is not supplied, uses the
    2.43    original rom data."
    2.44    [start length]
    2.45 @@ -179,6 +196,78 @@
    2.46  ROM@27E77"
    2.47    (hxc-thunk-words 0x27E77 196))
    2.48  
    2.49 +
    2.50 +(def hxc-pokedex-text
    2.51 +  "The hardcoded pokedex entries in memory. List begins at
    2.52 +ROM@B8000, shortly before move names."
    2.53 +  (hxc-thunk-words 0xB8000 14754))
    2.54 +
    2.55 +
    2.56 +;; In red/blue, pokemon are in internal order.
    2.57 +;; In yellow, pokemon are in pokedex order.
    2.58 +
    2.59 +(defn hxc-pokedex-stats
    2.60 +  ;; uses hxc-pokedex-text to count pokemon
    2.61 +  ;; since hxc-pokenames includes several missingno"
    2.62 +  ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
    2.63 +  ([rom]
    2.64 +     (let [poketext (hxc-pokedex-text)
    2.65 +           pkmn-count (count poketext)
    2.66 +           ]
    2.67 +     ((fn capture-stats
    2.68 +        [n stats data]
    2.69 +        (if (zero? n) stats
    2.70 +            (let [[species
    2.71 +                   [_
    2.72 +                    height-ft
    2.73 +                    height-in
    2.74 +                    weight-1
    2.75 +                    weight-2
    2.76 +                    _
    2.77 +                    dex-ptr-1
    2.78 +                    dex-ptr-2
    2.79 +                    dex-bank
    2.80 +                    _
    2.81 +                    & data]]
    2.82 +                  (split-with (partial not= 0x50) data)]
    2.83 +              (recur (dec n)
    2.84 +                     (assoc stats
    2.85 +                       (- pkmn-count n)
    2.86 +                       {:species
    2.87 +                        (character-codes->str species)
    2.88 +                        :height-ft
    2.89 +                        height-ft
    2.90 +                        :height-in
    2.91 +                        height-in
    2.92 +                        :weight
    2.93 +                        (/ (low-high weight-1 weight-2) 10.)
    2.94 +                        
    2.95 +                    ;;    :text
    2.96 +                    ;;    (character-codes->str
    2.97 +                    ;;     (take-while
    2.98 +                    ;;      (partial not= 0x50)
    2.99 +                    ;;      (drop
   2.100 +                    ;;       (+ 0xB8000
   2.101 +                    ;;          -0x4000
   2.102 +                    ;;          (low-high dex-ptr-1 dex-ptr-2))
   2.103 +                    ;;       rom)))
   2.104 +                        })
   2.105 +                     
   2.106 +                     data)
   2.107 +              
   2.108 +              
   2.109 +              )))
   2.110 +      
   2.111 +      pkmn-count
   2.112 +      {}
   2.113 +      (drop 0x40687 rom)))       ))
   2.114 +
   2.115 +
   2.116 +
   2.117 +
   2.118 +
   2.119 +
   2.120 +
   2.121  (def hxc-places
   2.122    "The hardcoded place names in memory. List begins at
   2.123  ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
   2.124 @@ -198,10 +287,7 @@
   2.125       (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
   2.126  
   2.127  
   2.128 -(def hxc-pokedex
   2.129 -  "The hardcoded pokedex entries in memory. List begins at
   2.130 -ROM@B8000, shortly before move names."
   2.131 -  (hxc-thunk-words 0xB8000 14754))
   2.132 +
   2.133  
   2.134  (def hxc-move-names
   2.135    "The hardcoded move names in memory. List begins at ROM@BC000"
   2.136 @@ -217,11 +303,7 @@
   2.137    ([rom]
   2.138       (let [names (vec (hxc-move-names rom))
   2.139             move-count (count names)
   2.140 -           move-size 6
   2.141 -           format-name (fn [s]
   2.142 -                      (keyword (.toLowerCase
   2.143 -                                (apply str
   2.144 -                                       (map #(if (= % \space) "-" %) s)))))]
   2.145 +           move-size 6]
   2.146         (zipmap (map format-name names)
   2.147                 (map
   2.148                  (fn [[idx effect power type accuracy pp]]
   2.149 @@ -287,6 +369,22 @@
   2.150                                    (drop 0xE8000
   2.151                                          rom))))))))
   2.152  
   2.153 +
   2.154 +
   2.155 +
   2.156 +(defn internal-id
   2.157 +  ([rom]
   2.158 +     (zipmap 
   2.159 +      (map format-name (hxc-pokenames rom))
   2.160 +      (range)))
   2.161 +  ([]
   2.162 +     (internal-id com.aurellem.gb.gb-driver/original-rom)))
   2.163 +  
   2.164 +
   2.165 +
   2.166 +
   2.167 +
   2.168 +
   2.169  (defn hxc-advantage
   2.170    "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here),
   2.171  the multiplier is 1."
   2.172 @@ -303,7 +401,92 @@
   2.173  
   2.174  
   2.175  
   2.176 +(defn format-evo
   2.177 +  [[method x y z & _]]
   2.178 +   (cond (= 0 method)
   2.179 +         {:method :none}
   2.180 +         (= 1 method)
   2.181 +         {:method :level-up
   2.182 +          :min-level x
   2.183 +          :into y}
   2.184 +         (= 2 method)
   2.185 +         {:method :item
   2.186 +          :item-id x
   2.187 +          :min-level y
   2.188 +          :into z}
   2.189 +         (= 3 method)
   2.190 +         {:method :trade
   2.191 +          :min-level x
   2.192 +          :into y}))
   2.193  
   2.194 +(defn format-evo*
   2.195 +  [[method x y z & _]]
   2.196 +  (cond (= 0 method)
   2.197 +        {:method :none}
   2.198 +        (= 1 method)
   2.199 +        {:method :level-up
   2.200 +         :min-level x
   2.201 +         :into (format-name (nth (hxc-pokenames) (dec y)))}
   2.202 +        (= 2 method)
   2.203 +        {:method :item
   2.204 +         :item (format-name (nth (hxc-items)  (dec x)))
   2.205 +         :min-level y
   2.206 +         :into (format-name (nth (hxc-pokenames) (dec z)))}
   2.207 +        (= 3 method)
   2.208 +        {:method :trade
   2.209 +         :min-level x
   2.210 +         :into (format-name (nth (hxc-pokenames) (dec y)))}))
   2.211 +
   2.212 +(defn hxc-evolution
   2.213 +  ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
   2.214 +  ([rom]
   2.215 +     (let [names (hxc-pokenames rom)
   2.216 +           pkmn-count (count names)
   2.217 +           evo-data (drop 0x33fef rom) 
   2.218 +           ptrs
   2.219 +           (map (fn [[a b]](low-high a b))
   2.220 +                (partition 2
   2.221 +                           (take (* 2 pkmn-count)
   2.222 +                                 (drop 0x3b1e5 rom))))
   2.223 +           ]
   2.224 +       (apply assoc {}
   2.225 +               (interleave
   2.226 +                (map format-name (hxc-pokenames))
   2.227 +                (map
   2.228 +                 (comp
   2.229 +                  format-evo
   2.230 +                  (partial take 5)
   2.231 +                  #(drop % rom)
   2.232 +                  (partial + 0x34000))
   2.233 +                 ptrs)))
   2.234 +
   2.235 +       )))
   2.236 +
   2.237 +
   2.238 +(defn hxc-evolution*
   2.239 +  ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
   2.240 +  ([rom]
   2.241 +     (let [names (hxc-pokenames rom)
   2.242 +           pkmn-count (count names)
   2.243 +           evo-data (drop 0x33fef rom) 
   2.244 +           ptrs
   2.245 +           (map (fn [[a b]](low-high a b))
   2.246 +                (partition 2
   2.247 +                           (take (* 2 pkmn-count)
   2.248 +                                 (drop 0x3b1e5 rom))))
   2.249 +           ]
   2.250 +       (apply assoc {}
   2.251 +               (interleave
   2.252 +                (map format-name (hxc-pokenames))
   2.253 +                (map
   2.254 +                 (comp
   2.255 +                  format-evo*
   2.256 +                  (partial take 5)
   2.257 +                  #(drop % rom)
   2.258 +                  (partial + 0x34000))
   2.259 +                 ptrs)))
   2.260 +
   2.261 +       )))
   2.262  
   2.263  
   2.264  
   2.265 @@ -384,4 +567,8 @@
   2.266    (def hxc-species
   2.267      (map character-codes->str
   2.268           (take-nth 4 dex))))
   2.269 -)
   2.270 \ No newline at end of file
   2.271 +)
   2.272 +
   2.273 +
   2.274 +
   2.275 +
     3.1 --- a/clojure/com/aurellem/world/practice.clj	Mon Mar 26 18:01:39 2012 -0500
     3.2 +++ b/clojure/com/aurellem/world/practice.clj	Mon Mar 26 18:34:06 2012 -0500
     3.3 @@ -1,6 +1,4 @@
     3.4  (ns com.aurellem.world.practice
     3.5 -  (:use (com.aurellem.gb gb-driver))
     3.6 -
     3.7   (:use (com.aurellem.gb saves util constants gb-driver vbm items assembly characters))
     3.8   (:use (com.aurellem.run title))
     3.9   (:use (com.aurellem.exp pokemon))
    3.10 @@ -18,7 +16,9 @@
    3.11        (recur (step state) (dec n))))
    3.12  
    3.13  
    3.14 -(defn view-memory* [state start length]
    3.15 +(defn view-memory*
    3.16 +  "View a region of indexable memory in the given state."
    3.17 +  [state start length]
    3.18    ((comp vec map)
    3.19     #((comp  aget) (memory state) %)
    3.20     (range start (+ start length))))
    3.21 @@ -181,19 +181,34 @@
    3.22                      (drop (inc m) list)
    3.23                      sub))))))
    3.24  
    3.25 +
    3.26 +
    3.27 +(defn search-rom
    3.28 +  "Search for the given codes in ROM, returning short snippets of
    3.29 +text around the results."
    3.30 +  ([codes k]
    3.31 +     (search-rom com.aurellem.gb.gb-driver/original-rom codes k))
    3.32 +  ([rom codes k]
    3.33 +     (map
    3.34 +      (fn [n]
    3.35 +        [(hex n)
    3.36 +         (take k (drop n rom))])
    3.37 +      
    3.38 +      (find-sublists
    3.39 +       rom
    3.40 +       codes))))
    3.41 +
    3.42  (defn spelling-bee
    3.43    "Search for the given string in ROM, returning short snippets of
    3.44 -text around the results."
    3.45 -  [str k]
    3.46 -  (let [rom (rom(root))]
    3.47 -    (map
    3.48 -     (fn [n]
    3.49 -       [(hex n)
    3.50 -        (character-codes->str (take k (drop n rom)))])
    3.51 +  text around the results."
    3.52 +  ([str k]
    3.53 +     (spelling-bee com.aurellem.gb.gb-driver/original-rom str k))
    3.54 +  ([rom str k]
    3.55 +     (map
    3.56 +      (fn [[address snip]]
    3.57 +        [address (character-codes->str snip)]
    3.58 +        (search-rom rom (str->character-codes str) k)))))
    3.59       
    3.60 -     (find-sublists
    3.61 -      rom
    3.62 -      (str->character-codes str)))))
    3.63  
    3.64  
    3.65