changeset 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 d954835b24a4
children 893c753f8088
files clojure/com/aurellem/gb/moves.clj clojure/com/aurellem/gb/pokemon.clj clojure/com/aurellem/gb/species.clj clojure/com/aurellem/gb/types.clj
diffstat 4 files changed, 60 insertions(+), 13 deletions(-) [+]
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 +
     2.1 --- a/clojure/com/aurellem/gb/pokemon.clj	Thu Mar 22 15:58:39 2012 -0500
     2.2 +++ b/clojure/com/aurellem/gb/pokemon.clj	Thu Mar 22 16:34:10 2012 -0500
     2.3 @@ -1,5 +1,8 @@
     2.4  (ns com.aurellem.gb.pokemon
     2.5 -  (:use (com.aurellem.gb gb-driver util constants characters))
     2.6 +  (:use (com.aurellem.gb gb-driver util constants characters
     2.7 +                         moves types items status dv species
     2.8 +
     2.9 +                         ))
    2.10    (:import [com.aurellem.gb.gb_driver SaveState]))
    2.11  
    2.12  (def pokemon-names-start 0xD2B4)
    2.13 @@ -179,3 +182,18 @@
    2.14           poke-data))))
    2.15    ([pokemon-num]
    2.16       (print-pokemon-record @current-state pokemon-num)))
    2.17 +
    2.18 +(def mint-berry-item-code-gsc 0x54)
    2.19 +
    2.20 +(defn pokemon-info [^SaveState state poke-num]
    2.21 +  (assert (<= 0 poke-num 5))
    2.22 +  (let [dv-values (read-DV state poke-num)
    2.23 +        type (read-type state poke-num)
    2.24 +        species (read-species state poke-num)
    2.25 +        
    2.26 +        ]
    2.27 +
    2.28 +       
    2.29 +
    2.30 +
    2.31 +    ))
     3.1 --- a/clojure/com/aurellem/gb/species.clj	Thu Mar 22 15:58:39 2012 -0500
     3.2 +++ b/clojure/com/aurellem/gb/species.clj	Thu Mar 22 16:34:10 2012 -0500
     3.3 @@ -161,16 +161,28 @@
     3.4    (zipmap (vals species-code->species-name)
     3.5            (keys species-code->species-name)))
     3.6  
     3.7 +(defn pokemon-species-data-address [poke-num]
     3.8 +  (+ species-ID-1 poke-num))
     3.9 +
    3.10 +(defn read-species
    3.11 +  ([^SaveState state poke-num]
    3.12 +     (assert (<= 0 poke-num 5))
    3.13 +     (species-code->species-name
    3.14 +      (aget (memory state)
    3.15 +            (pokemon-species-data-address poke-num))))
    3.16 +  ([poke-num]
    3.17 +     (read-species @current-state poke-num)))
    3.18 +
    3.19  (defn set-species
    3.20 -  ([^SaveState state pokemon-num species-name]
    3.21 -     (assert (<= 0 pokemon-num 5))
    3.22 +  ([^SaveState state poke-num species-name]
    3.23 +     (assert (<= 0 poke-num 5))
    3.24       (let [species-code (species-name->species-code
    3.25                           species-name
    3.26                           species-name)]
    3.27         
    3.28 -       (set-memory state (+ species-ID-1 pokemon-num)
    3.29 +       (set-memory state (pokemon-species-data-address poke-num)
    3.30                     species-code)))
    3.31 -  ([pokemon-num species-name]
    3.32 -     (set-species @current-state pokemon-num species-name)))
    3.33 +  ([poke-num species-name]
    3.34 +     (set-species @current-state poke-num species-name)))
    3.35  
    3.36  
     4.1 --- a/clojure/com/aurellem/gb/types.clj	Thu Mar 22 15:58:39 2012 -0500
     4.2 +++ b/clojure/com/aurellem/gb/types.clj	Thu Mar 22 16:34:10 2012 -0500
     4.3 @@ -23,10 +23,10 @@
     4.4    (zipmap (vals type-code->type-name)
     4.5            (keys type-code->type-name)))
     4.6  
     4.7 -(def pokemon-1-types-start-address 0xD16F)
     4.8 +(def pokemon-1-type-start-address 0xD16F)
     4.9  
    4.10  (defn pokemon-type-start-address [poke-num]
    4.11 -  (+ pokemon-1-types-start-address
    4.12 +  (+ pokemon-1-type-start-address
    4.13       (* pokemon-record-width poke-num)))
    4.14  
    4.15  (defn give-type
    4.16 @@ -43,7 +43,7 @@
    4.17    ([poke-num types]
    4.18       (give-type @current-state poke-num types)))
    4.19  
    4.20 -(defn read-types
    4.21 +(defn read-type
    4.22    ([^SaveState state poke-num]
    4.23       (assert (<= 0 poke-num 5))
    4.24       (let [types-start (pokemon-type-start-address poke-num)
    4.25 @@ -54,5 +54,5 @@
    4.26           [(type-code->type-name type-1)]
    4.27           (mapv type-code->type-name [type-1 type-2]))))
    4.28    ([poke-num]
    4.29 -     (read-types @current-state poke-num)))
    4.30 +     (read-type @current-state poke-num)))
    4.31                     
    4.32 \ No newline at end of file