changeset 223:3dfb9dd3db9d

pokedex manipulation functions complete.
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 03:35:21 -0500
parents c9a855de1d07
children 10e26e7ceedb
files clojure/com/aurellem/gb/pokedex.clj clojure/com/aurellem/gb/species.clj
diffstat 2 files changed, 39 insertions(+), 176 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/pokedex.clj	Sat Mar 24 03:10:56 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/pokedex.clj	Sat Mar 24 03:35:21 2012 -0500
     1.3 @@ -10,7 +10,7 @@
     1.4    (+ (if capture?
     1.5         pokedex-captured-start-address
     1.6         pokedex-seen-start-address)
     1.7 -     (int (/ species-num 8))))
     1.8 +     (int (/ (dec species-num) 8))))
     1.9    
    1.10  (defn read-pokedex
    1.11    ([^SaveState state capture? species-num]
    1.12 @@ -25,7 +25,7 @@
    1.13             current-bits
    1.14             (aget (memory state)
    1.15                   (pokedex-offset capture? species-num))
    1.16 -           bit-offset (rem species-num 8)]
    1.17 +           bit-offset (rem (dec species-num) 8)]
    1.18         (set-memory
    1.19          state target
    1.20          (if set?
    1.21 @@ -33,28 +33,36 @@
    1.22            (bit-clear current-bits bit-offset))))))
    1.23  
    1.24  (defn read-pokedex-seen
    1.25 -  ([^SaveState state species-num]
    1.26 -     (read-pokedex state false species-num))
    1.27 -  ([species-num]
    1.28 -     (read-pokedex-seen @current-state species-num)))
    1.29 +  ([^SaveState state species-or-num]
    1.30 +     (read-pokedex state false
    1.31 +                   (species-name->pokedex-num
    1.32 +                    species-or-num species-or-num)))
    1.33 +  ([species-or-num]
    1.34 +     (read-pokedex-seen @current-state species-or-num)))
    1.35  
    1.36  (defn set-pokedex-seen
    1.37 -  ([^SaveState state species-num]
    1.38 -     (set-pokedex state false species-num))
    1.39 -  ([species-num]
    1.40 -     (set-pokedex-seen @current-state species-num)))
    1.41 +  ([^SaveState state species-or-num seen?]
    1.42 +     (set-pokedex state false seen?
    1.43 +                  (species-name->pokedex-num
    1.44 +                   species-or-num species-or-num)))
    1.45 +  ([species-or-num seen?]
    1.46 +     (set-pokedex-seen @current-state species-or-num seen?)))
    1.47  
    1.48  (defn read-pokedex-captured
    1.49 -  ([^SaveState state species-num]
    1.50 -     (read-pokedex state true species-num))
    1.51 -  ([species-num]
    1.52 -     (read-pokedex-captured @current-state species-num)))
    1.53 +  ([^SaveState state species-or-num]
    1.54 +     (read-pokedex state true
    1.55 +                   (species-name->pokedex-num
    1.56 +                    species-or-num species-or-num)))
    1.57 +  ([species-or-num]
    1.58 +     (read-pokedex-captured @current-state species-or-num)))
    1.59  
    1.60  (defn set-pokedex-captured
    1.61 -  ([^SaveState state species-num]
    1.62 -     (set-pokedex state true species-num))
    1.63 -  ([species-num]
    1.64 -     (set-pokedex-captured @current-state species-num)))
    1.65 +  ([^SaveState state species-or-num captured?]
    1.66 +     (set-pokedex state true captured?
    1.67 +                  (species-name->pokedex-num
    1.68 +                   species-or-num species-or-num)))
    1.69 +  ([species-or-num captured?]
    1.70 +     (set-pokedex-captured @current-state species-or-num captured?)))
    1.71  
    1.72  (defn print-pokedex
    1.73    ([^SaveState state]
    1.74 @@ -71,6 +79,14 @@
    1.75         (map #(if % "   X   " "       ")
    1.76              (map read-pokedex-captured (range 152)))))
    1.77       (println "+-----------+-------+-------+"))
    1.78 +  ([] (print-pokedex @current-state)))
    1.79  
    1.80 -  ([] (print-pokedex @current-state)))
    1.81 -     
    1.82 \ No newline at end of file
    1.83 +(defn give-full-pokedex
    1.84 +  ([^SaveState state]
    1.85 +     (reduce
    1.86 +      (fn [state n]
    1.87 +        (-> state
    1.88 +            (set-pokedex-seen n true)
    1.89 +            (set-pokedex-captured n true)))
    1.90 +      state (range 1 152)))
    1.91 +  ([] (give-full-pokedex @current-state)))
     2.1 --- a/clojure/com/aurellem/gb/species.clj	Sat Mar 24 03:10:56 2012 -0500
     2.2 +++ b/clojure/com/aurellem/gb/species.clj	Sat Mar 24 03:35:21 2012 -0500
     2.3 @@ -368,159 +368,6 @@
     2.4     150     :mewtwo         
     2.5     151     :mew})
     2.6           
     2.7 -
     2.8 -
     2.9 -
    2.10 -
    2.11 -
    2.12 -           
    2.13 -           
    2.14 -           
    2.15 -           
    2.16 -           
    2.17 -           
    2.18 -           
    2.19 -           
    2.20 -           
    2.21 -           
    2.22 -           
    2.23 -           
    2.24 -           
    2.25 -           
    2.26 -           
    2.27 -           
    2.28 -           
    2.29 -           
    2.30 -           
    2.31 -           
    2.32 -           
    2.33 -           
    2.34 -           
    2.35 -           
    2.36 -           
    2.37 -           
    2.38 -           
    2.39 -           
    2.40 -           
    2.41 -           
    2.42 -           
    2.43 -           
    2.44 -           
    2.45 -           
    2.46 -           
    2.47 -           
    2.48 -           
    2.49 -           
    2.50 -           
    2.51 -           
    2.52 -           
    2.53 -           
    2.54 -           
    2.55 -           
    2.56 -           
    2.57 -           
    2.58 -           
    2.59 -           
    2.60 -           
    2.61 -           
    2.62 -           
    2.63 -           
    2.64 -           
    2.65 -           
    2.66 -           
    2.67 -           
    2.68 -           
    2.69 -           
    2.70 -           
    2.71 -           
    2.72 -           
    2.73 -           
    2.74 -           
    2.75 -           
    2.76 -           
    2.77 -           
    2.78 -           
    2.79 -           
    2.80 -           
    2.81 -           
    2.82 -           
    2.83 -           
    2.84 -           
    2.85 -           
    2.86 -           
    2.87 -           
    2.88 -           
    2.89 -           
    2.90 -           
    2.91 -           
    2.92 -           
    2.93 -           
    2.94 -           
    2.95 -           
    2.96 -           
    2.97 -           
    2.98 -           
    2.99 -           
   2.100 -           
   2.101 -           
   2.102 -           
   2.103 -           
   2.104 -           
   2.105 -           
   2.106 -           
   2.107 -           
   2.108 -           
   2.109 -           
   2.110 -           
   2.111 -           
   2.112 -           
   2.113 -           
   2.114 -           
   2.115 -           
   2.116 -           
   2.117 -           
   2.118 -           
   2.119 -           
   2.120 -           
   2.121 -           
   2.122 -           
   2.123 -           
   2.124 -           
   2.125 -           
   2.126 -           
   2.127 -           
   2.128 -           
   2.129 -           
   2.130 -           
   2.131 -           
   2.132 -           
   2.133 -           
   2.134 -           
   2.135 -           
   2.136 -           
   2.137 -           
   2.138 -           
   2.139 -           
   2.140 -           
   2.141 -           
   2.142 -           
   2.143 -           
   2.144 -           
   2.145 -           
   2.146 -           
   2.147 -           
   2.148 -           
   2.149 -           
   2.150 -           
   2.151 -           
   2.152 -           
   2.153 -           
   2.154 -           
   2.155 -           
   2.156 -           
   2.157 -           
   2.158 -           
   2.159 -           
   2.160 -           
   2.161 -           
   2.162 -           
   2.163 \ No newline at end of file
   2.164 +(def species-name->pokedex-num
   2.165 +  (zipmap (vals pokedex-num->species-name)
   2.166 +          (keys pokedex-num->species-name)))