diff clojure/com/aurellem/gb/moves.clj @ 190:9a7a46c4aa1b

extending functionality of support namespaces in prepreation of give-pokemon
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Mar 2012 16:34:10 -0500
parents 9c3769060201
children 893c753f8088
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/moves.clj	Thu Mar 22 15:58:39 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/moves.clj	Thu Mar 22 16:34:10 2012 -0500
     1.3 @@ -4,6 +4,7 @@
     1.4  
     1.5  (def move-code->move-name
     1.6    {
     1.7 +   0x00   :end-of-moves
     1.8     0x01   :pound
     1.9     0x02   :karate-chop
    1.10     0x03   :doubleslap
    1.11 @@ -170,6 +171,10 @@
    1.12     0xA4   :substitute
    1.13     0xA5   :struggle})
    1.14  
    1.15 +(def move-name->move-code
    1.16 +  (zipmap (vals move-code->move-name)
    1.17 +          (keys move-code->move-name)))
    1.18 +
    1.19  (def moves-codes-pokemon-1 0xD172)
    1.20  
    1.21  (defn moves-codes-start [pokemon-num]
    1.22 @@ -177,9 +182,20 @@
    1.23    (+ moves-codes-pokemon-1
    1.24       (* pokemon-num pokemon-record-width)))
    1.25  
    1.26 -(def move-name->move-code
    1.27 -  (zipmap (vals move-code->move-name)
    1.28 -          (keys move-code->move-name)))
    1.29 +(defn read-moves
    1.30 +  ([^SaveState state poke-num]
    1.31 +     (let [start (moves-codes-start poke-num)]
    1.32 +       (vec
    1.33 +        (take-while
    1.34 +         (partial not= (move-name->move-code :end-of-moves))
    1.35 +         (map
    1.36 +          move-code->move-name
    1.37 +          (subvec (vec (memory state))
    1.38 +                  start (+ start (num-moves state poke-num))))))))
    1.39 +  ([poke-num]
    1.40 +     (read-moves @current-state poke-num)))
    1.41 +             
    1.42 +
    1.43  
    1.44  (defn give-moves
    1.45    ([^SaveState state pokemon-num moves]
    1.46 @@ -247,3 +263,4 @@
    1.47    ([pokemon-num move-num pp-ups current-pp]
    1.48       (give-pp @current-state
    1.49               pokemon-num move-num pp-ups current-pp)))
    1.50 +