diff clojure/com/aurellem/gb/hxc.clj @ 276:18336ab5d6ea

merge.
author Robert McIntyre <rlm@mit.edu>
date Tue, 27 Mar 2012 12:37:48 -0500
parents 69184558fcf3
children ca1afcef3542
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/hxc.clj	Tue Mar 27 12:36:48 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/hxc.clj	Tue Mar 27 12:37:48 2012 -0500
     1.3 @@ -27,15 +27,15 @@
     1.4    
     1.5  
     1.6  (def pkmn-types
     1.7 -  [:normal
     1.8 -   :fighting
     1.9 -   :flying
    1.10 -   :poison
    1.11 -   :ground
    1.12 -   :rock
    1.13 -   :bird
    1.14 -   :bug
    1.15 -   :ghost
    1.16 +  [:normal    ;;0
    1.17 +   :fighting  ;;1
    1.18 +   :flying    ;;2
    1.19 +   :poison    ;;3
    1.20 +   :ground    ;;4
    1.21 +   :rock      ;;5
    1.22 +   :bird      ;;6
    1.23 +   :bug       ;;7
    1.24 +   :ghost     ;;8
    1.25     :A
    1.26     :B
    1.27     :C
    1.28 @@ -47,13 +47,13 @@
    1.29     :I
    1.30     :J
    1.31     :K
    1.32 -   :fire
    1.33 -   :water
    1.34 -   :grass
    1.35 -   :electric
    1.36 -   :psychic
    1.37 -   :ice
    1.38 -   :dragon
    1.39 +   :fire     ;;20 (0x14)
    1.40 +   :water    ;;21 (0x15)
    1.41 +   :grass    ;;22 (0x16)
    1.42 +   :electric ;;23 (0x17)
    1.43 +   :psychic  ;;24 (0x18)
    1.44 +   :ice      ;;25 (0x19)
    1.45 +   :dragon   ;;26 (0x1A)
    1.46     ])
    1.47  
    1.48  
    1.49 @@ -203,10 +203,12 @@
    1.50    (hxc-thunk-words 0xB8000 14754))
    1.51  
    1.52  
    1.53 -;; In red/blue, pokemon are in internal order.
    1.54 -;; In yellow, pokemon are in pokedex order.
    1.55 +;; In red/blue, pokedex stats are in internal order.
    1.56 +;; In yellow, pokedex stats are in pokedex order.
    1.57  
    1.58  (defn hxc-pokedex-stats
    1.59 +  "The hardcoded pokedex stats (species height weight) in memory. List
    1.60 +begins at ROM@40687"
    1.61    ;; uses hxc-pokedex-text to count pokemon
    1.62    ;; since hxc-pokenames includes several missingno"
    1.63    ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
    1.64 @@ -554,6 +556,101 @@
    1.65  
    1.66  
    1.67  
    1.68 +(defn hxc-pokemon-base
    1.69 +  ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
    1.70 +  ([rom]
    1.71 +     (let [entry-size 28
    1.72 +           pkmn-count (count (hxc-pokedex-text rom))
    1.73 +           types (apply assoc {}
    1.74 +                        (interleave
    1.75 +                         (range)
    1.76 +                         pkmn-types)) ;;!! softcoded
    1.77 +           moves (apply assoc {}
    1.78 +                        (interleave
    1.79 +                         (range)
    1.80 +                         (map format-name
    1.81 +                              (hxc-move-names rom))))
    1.82 +           ]
    1.83 +       (map
    1.84 +        
    1.85 +        (fn [[n
    1.86 +              rating-hp
    1.87 +              rating-atk
    1.88 +              rating-def
    1.89 +              rating-speed
    1.90 +              rating-special
    1.91 +              type-1
    1.92 +              type-2
    1.93 +              rarity
    1.94 +              rating-xp
    1.95 +              pic-dimensions
    1.96 +              ptr-pic-obverse-1
    1.97 +              ptr-pic-obverse-2
    1.98 +              ptr-pic-reverse-1
    1.99 +              ptr-pic-reverse-2
   1.100 +              move-1
   1.101 +              move-2
   1.102 +              move-3
   1.103 +              move-4
   1.104 +              growth-rate
   1.105 +              &
   1.106 +              TMs|HMs]]
   1.107 +          (let
   1.108 +              [base-moves
   1.109 +               (mapv moves
   1.110 +                ((comp
   1.111 +                  ;; since the game uses zero as a delimiter,
   1.112 +                  ;; it must also increment all move indices by 1.
   1.113 +                  ;; heren we decrement to correct this.
   1.114 +                  (partial map dec)
   1.115 +                  (partial take-while (comp not zero?)))
   1.116 +                 [move-1 move-2 move-3 move-4]))
   1.117 +
   1.118 +               types
   1.119 +               (set (list (types type-1)
   1.120 +                          (types type-2)))
   1.121 +               TMs|HMs
   1.122 +               (map
   1.123 +                (comp
   1.124 +                 (partial map first)
   1.125 +                 (partial remove (comp zero? second)))
   1.126 +                (split-at
   1.127 +                 50
   1.128 +                 (map vector
   1.129 +                      (rest(range))
   1.130 +                      (reduce concat
   1.131 +                              (map
   1.132 +                               #(take 8
   1.133 +                                      (concat (bit-list %)
   1.134 +                                              (repeat 0)))
   1.135 +                               
   1.136 +                                TMs|HMs)))))
   1.137 +               
   1.138 +               TMs  (vec (first TMs|HMs))
   1.139 +               HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
   1.140 +
   1.141 +               
   1.142 +               ]
   1.143 +
   1.144 +          
   1.145 +          {:dex# n
   1.146 +           :base-moves base-moves
   1.147 +           :types types
   1.148 +           :TMs TMs
   1.149 +           :HMs HMs
   1.150 +           :base-hp rating-hp
   1.151 +           :base-atk rating-atk
   1.152 +           :base-def rating-def
   1.153 +           :base-speed rating-speed
   1.154 +           :base-special rating-special
   1.155 +           }))
   1.156 +              
   1.157 +             (partition entry-size
   1.158 +                        (take (* entry-size pkmn-count)
   1.159 +                              (drop 0x383DE
   1.160 +                                    rom)))))))
   1.161 +
   1.162 +
   1.163  ;; ********************** MANIPULATION FNS
   1.164  
   1.165  
   1.166 @@ -627,4 +724,3 @@
   1.167  
   1.168  
   1.169  
   1.170 -