diff clojure/com/aurellem/gb/pokemon.clj @ 192:fd549c8f42ae

fixed compilation problems, added more functionality to pokemon-info
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Mar 2012 22:35:57 -0500
parents 893c753f8088
children da1a5ed61a8d
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/pokemon.clj	Thu Mar 22 20:10:09 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/pokemon.clj	Thu Mar 22 22:35:57 2012 -0500
     1.3 @@ -1,7 +1,7 @@
     1.4  (ns com.aurellem.gb.pokemon
     1.5    (:use (com.aurellem.gb gb-driver util constants characters
     1.6                           moves types items status dv species
     1.7 -                         experience
     1.8 +                         experience stats
     1.9                           ))
    1.10    (:import [com.aurellem.gb.gb_driver SaveState]))
    1.11  
    1.12 @@ -66,7 +66,12 @@
    1.13                    (partition name-width raw-names)))))
    1.14    ([] (original-trainers @current-state)))
    1.15  
    1.16 -(defn set-original-trainer
    1.17 +(defn read-OT-name
    1.18 +  ([^SaveState state poke-num]
    1.19 +     (nth (original-trainers state) poke-num))
    1.20 +  ([poke-num] (read-OT @current-state poke-num)))
    1.21 +
    1.22 +(defn set-OT-name
    1.23    "Set the OT name for a pokemon.
    1.24     Note that a pokemon is still considered 'yours' if
    1.25     the OT ID is the same as your own."
    1.26 @@ -82,18 +87,25 @@
    1.27  
    1.28  (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252])
    1.29  
    1.30 -(defn set-pokemon-id
    1.31 -  ([^SaveState state n new-id]
    1.32 -     (assert (<= 0 n (dec (party-number state))))
    1.33 -     (assert (<= 0 new-id 0xFFFF))
    1.34 +(defn read-OT-id
    1.35 +  ([^SaveState state poke-num]
    1.36 +     (let [mem (memory state)
    1.37 +           start (OT-ID-addresses poke-num)]
    1.38 +     (glue-bytes
    1.39 +      (aget mem start)
    1.40 +      (aget mem (inc start)))))
    1.41 +  ([poke-num] (read-OT-id @current-state poke-num)))
    1.42 +
    1.43 +(defn set-OT-id
    1.44 +  ([^SaveState state poke-num new-OT-num]
    1.45 +     (assert (<= 0 poke-num 5))
    1.46 +     (assert (<= 0 new-OT-num 0xFFFF))
    1.47       (set-memory-range 
    1.48        state
    1.49 -      (OT-ID-addresses n)
    1.50 -      [(bit-shift-right (bit-and new-id 0xFF00) 8)
    1.51 -       (bit-and new-id 0xFF)
    1.52 -       ]))
    1.53 -  ([n new-id]
    1.54 -     (set-pokemon-id @current-state n new-id)))
    1.55 +      (OT-ID-addresses poke-num)
    1.56 +      (disect-bytes-2 new-OT-num)))
    1.57 +  ([poke-num new-OT-num]
    1.58 +     (set-pokemon-id @current-state poke-num new-OT-num)))
    1.59  
    1.60  (def unknown "[[[UNKNOWN]]]")
    1.61  
    1.62 @@ -204,7 +216,10 @@
    1.63                            (range (count moves)))
    1.64             nickname (pokemon-nickname state poke-num)
    1.65             status (read-status state poke-num)
    1.66 +           stats (read-stats state poke-num)
    1.67             experience (read-experience state poke-num)
    1.68 +           OT-name (read-OT-name state poke-num)
    1.69 +           ID (read-OT-id state poke-num)
    1.70             ]
    1.71  
    1.72         {:name nickname
    1.73 @@ -212,12 +227,26 @@
    1.74          :species2 species2
    1.75          :type type
    1.76          :dv dv-values
    1.77 +        :original-trainer OT-name
    1.78 +        :ID ID
    1.79 +        
    1.80          :moves (zipmap moves moves-pp)
    1.81  
    1.82          :satus status
    1.83 +        :stats stats
    1.84          :experience experience
    1.85 +
    1.86          }
    1.87         ))
    1.88    ([poke-num]
    1.89       (pokemon-info @current-state poke-num)))
    1.90              
    1.91 +
    1.92 +(defn give-status-all
    1.93 +  ([^SaveState state status]
    1.94 +     (reduce (fn [state num]
    1.95 +               (give-status state num status))
    1.96 +             state
    1.97 +             (range (party-number state))))
    1.98 +  ([status]
    1.99 +     (give-status-all @current-state status)))