changeset 148:06426d25c65b

can now get/set pokemon OT name
author Robert McIntyre <rlm@mit.edu>
date Mon, 19 Mar 2012 23:14:21 -0500
parents 279e9ee6fccb
children 79ffbd639b41
files clojure/com/aurellem/exp/pokemon.clj clojure/com/aurellem/gb/characters.clj
diffstat 2 files changed, 55 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/exp/pokemon.clj	Mon Mar 19 22:42:36 2012 -0500
     1.2 +++ b/clojure/com/aurellem/exp/pokemon.clj	Mon Mar 19 23:14:21 2012 -0500
     1.3 @@ -92,14 +92,14 @@
     1.4  (def max-name-length 10)
     1.5  (def name-width 11)
     1.6  
     1.7 -(defn read-pokemon-name [codes]
     1.8 +(defn read-name [codes]
     1.9    (character-codes->str
    1.10     (take-while
    1.11      (partial not= end-of-name-marker) codes)))
    1.12      
    1.13  
    1.14  (defn sixth-pokemon-name [^SaveState state]
    1.15 -  (read-pokemon-name
    1.16 +  (read-name
    1.17      (subvec (vec (memory state))
    1.18              sixth-pokemon-name-start
    1.19              (+ (inc max-name-length)
    1.20 @@ -127,16 +127,12 @@
    1.21    ([begin end]
    1.22       (print-text @current-state begin end)))
    1.23  
    1.24 -
    1.25 -
    1.26 -
    1.27  (defn examine-name-memory []
    1.28    (print-text
    1.29     named-A
    1.30     (- sixth-pokemon-name-start 100)
    1.31     (+ sixth-pokemon-name-start 100)))
    1.32  
    1.33 -
    1.34  ;; results:
    1.35  ;; 0xD287:  end-of-name-sentinel
    1.36  ;; 0xD288:  R
    1.37 @@ -436,13 +432,62 @@
    1.38             (subvec (vec (memory state))
    1.39                     pokemon-names-start
    1.40                     (+ pokemon-names-start
    1.41 -                      (*  name-width 6)))]
    1.42 +                      (* name-width 6)))]
    1.43         (map
    1.44 -        read-pokemon-name
    1.45 +        read-name
    1.46          (take
    1.47           (party-number state)
    1.48            (partition name-width
    1.49                     raw-names)))))
    1.50    ([] (party-names @current-state)))
    1.51  
    1.52 -  
    1.53 \ No newline at end of file
    1.54 +
    1.55 +(defn rename-pokemon
    1.56 +  ([^SaveState state n new-name]
    1.57 +     (assert (<= 0 n (dec (party-number state))))
    1.58 +     (assert (<= (count new-name) max-name-length))
    1.59 +     (set-memory-range
    1.60 +      state
    1.61 +      (+ (* n name-width) pokemon-names-start)
    1.62 +      (concat (str->character-codes new-name) [end-of-name-marker])))
    1.63 +  ([n new-name]
    1.64 +     (rename-pokemon @current-state n new-name)))
    1.65 +                      
    1.66 +
    1.67 +;; on further analysis, it appears that the original
    1.68 +;; trainer info for each pokemon is also stored together,
    1.69 +;; starting at 0xD272 and continuing to 0xD2B3, with
    1.70 +;; 11 bytes reserved for each OT name.
    1.71 +
    1.72 +(def OT-start 0xD272)
    1.73 +
    1.74 +(defn original-trainers
    1.75 +  ([^SaveState state]
    1.76 +     (let [raw-names
    1.77 +           (subvec (vec (memory state))
    1.78 +                   OT-start
    1.79 +                   (+ OT-start
    1.80 +                      (* name-width 6)))]
    1.81 +       (map read-name
    1.82 +            (take (party-number state)
    1.83 +                  (partition name-width raw-names)))))
    1.84 +  ([] (original-trainers @current-state)))
    1.85 +       
    1.86 +(defn set-original-trainer
    1.87 +  "Set the OT name for a pokemon.
    1.88 +   Note that a pokemon is still considered 'yours' if
    1.89 +   the OT ID is the same as your own."
    1.90 +  ([^SaveState state n new-name]
    1.91 +     (assert (<= 0 n (dec (party-number state))))
    1.92 +     (assert (<= (count new-name) max-name-length))
    1.93 +     (set-memory-range
    1.94 +      state
    1.95 +      (+ (* n name-width) OT-start)
    1.96 +      (concat (str->character-codes new-name) [end-of-name-marker])))
    1.97 +  ([n new-name]
    1.98 +     (set-original-trainer @current-state n new-name)))
    1.99 +
   1.100 +;; PIKACHU stops following if you set it's OT to another name
   1.101 +;; and then back to you own.
   1.102 +;; But not if you set it to your own name, obviously.
   1.103 +     
   1.104 \ No newline at end of file
     2.1 --- a/clojure/com/aurellem/gb/characters.clj	Mon Mar 19 22:42:36 2012 -0500
     2.2 +++ b/clojure/com/aurellem/gb/characters.clj	Mon Mar 19 23:14:21 2012 -0500
     2.3 @@ -79,6 +79,7 @@
     2.4     0xE0   "'"
     2.5     0xE1   "PK"
     2.6     0xE2   "MN"
     2.7 +   0xE3   "-"
     2.8     0xE6   "?"
     2.9     0xE7   "!"
    2.10     0xE8   "."