changeset 209:912496041f98

give pokemon appears to work.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 05:45:56 -0500
parents 45f1376b578c
children 565f5d17f90a
files clojure/com/aurellem/gb/moves.clj clojure/com/aurellem/gb/pokemon.clj clojure/com/aurellem/gb/stats.clj
diffstat 3 files changed, 57 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/moves.clj	Fri Mar 23 04:39:24 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/moves.clj	Fri Mar 23 05:45:56 2012 -0500
     1.3 @@ -264,6 +264,20 @@
     1.4       (give-pp @current-state
     1.5               pokemon-num move-num pp-ups current-pp)))
     1.6  
     1.7 +(defn give-moves-pps
     1.8 +  ([^SaveState state poke-num moves-pps]
     1.9 +     (let [new-moves
    1.10 +           (-> state
    1.11 +               (give-moves poke-num (map first moves-pps)))]
    1.12 +       (reduce (fn [state move-num]
    1.13 +                 (let [pp (second (nth moves-pps move-num))]
    1.14 +                   (give-pp state poke-num move-num
    1.15 +                            (:pp-ups pp)
    1.16 +                            (:current-pp    pp))))
    1.17 +               new-moves (range (count moves-pps)))))
    1.18 +  ([poke-num moves-pps]
    1.19 +     (give-moves-pps @current-state poke-num moves-pps)))
    1.20 +           
    1.21  
    1.22  (def move-name->move-pp
    1.23    {
    1.24 @@ -378,7 +392,7 @@
    1.25     :rock-throw    15
    1.26     :rolling-kick  15
    1.27     :sand-attack   15
    1.28 -   :scratch       30
    1.29 +   :scratch       35
    1.30     :screech       40
    1.31     :seismic-toss  20
    1.32     :selfdestruct   5
     2.1 --- a/clojure/com/aurellem/gb/pokemon.clj	Fri Mar 23 04:39:24 2012 -0500
     2.2 +++ b/clojure/com/aurellem/gb/pokemon.clj	Fri Mar 23 05:45:56 2012 -0500
     2.3 @@ -69,7 +69,7 @@
     2.4  (defn read-OT-name
     2.5    ([^SaveState state poke-num]
     2.6       (nth (original-trainers state) poke-num))
     2.7 -  ([poke-num] (read-OT @current-state poke-num)))
     2.8 +  ([poke-num] (read-OT-name @current-state poke-num)))
     2.9  
    2.10  (defn set-OT-name
    2.11    "Set the OT name for a pokemon.
    2.12 @@ -83,7 +83,7 @@
    2.13        (+ (* poke-num name-width) OT-start)
    2.14        (concat (str->character-codes new-name) [end-of-name-marker])))
    2.15    ([n new-name]
    2.16 -     (set-original-trainer @current-state n new-name)))
    2.17 +     (set-OT-name @current-state n new-name)))
    2.18  
    2.19  (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD226 0xD252])
    2.20  
    2.21 @@ -105,7 +105,7 @@
    2.22        (OT-ID-addresses poke-num)
    2.23        (disect-bytes-2 new-OT-num)))
    2.24    ([poke-num new-OT-num]
    2.25 -     (set-pokemon-id @current-state poke-num new-OT-num)))
    2.26 +     (set-OT-id @current-state poke-num new-OT-num)))
    2.27  
    2.28  (def unknown "[[[UNKNOWN]]]")
    2.29  
    2.30 @@ -203,7 +203,7 @@
    2.31  
    2.32  (def mint-berry-item-code-gsc 0x54)
    2.33  
    2.34 -(defn pokemon-info
    2.35 +(defn pokemon
    2.36    ([^SaveState state poke-num]
    2.37       (assert (<= 0 poke-num 5))
    2.38       (let [dv-values (read-DV state poke-num)
    2.39 @@ -236,7 +236,7 @@
    2.40          :experience experience
    2.41          }))
    2.42    ([poke-num]
    2.43 -     (pokemon-info @current-state poke-num)))
    2.44 +     (pokemon @current-state poke-num)))
    2.45  
    2.46  (def status-message
    2.47    {:sleep-6 "sleeping. It will wake in six turns."
    2.48 @@ -253,7 +253,7 @@
    2.49     
    2.50  (defn print-pokemon
    2.51    ([^SaveState state poke-num]
    2.52 -     (let [info (pokemon-info state poke-num)]
    2.53 +     (let [info (pokemon state poke-num)]
    2.54         (printf
    2.55          (str
    2.56           "##################################"
    2.57 @@ -373,15 +373,14 @@
    2.58      :hp-exp 0xFFFF}
    2.59  
    2.60     :stats
    2.61 -   ;; TODO recalculate these from a real ditto
    2.62     {:level 7
    2.63 -    :current-hp 50
    2.64 -    :hp 50
    2.65 -    :attack 50
    2.66 -    :defense 50
    2.67 -    :speed 50
    2.68 -    :special 50}
    2.69 -   :moves [[:transform {:pp-up 3 :pp 5}]]})
    2.70 +    :current-hp 30
    2.71 +    :hp 30
    2.72 +    :attack 18
    2.73 +    :defense 18
    2.74 +    :speed 18
    2.75 +    :special 18}
    2.76 +   :moves [[:transform {:pp-ups 3 :current-pp 5}]]})
    2.77  
    2.78  (defn expand-pokemon
    2.79    "Given a map describing a pokemon, fill in any missing
    2.80 @@ -401,7 +400,8 @@
    2.81        ;; same as species.
    2.82        ((fn [pokemon]
    2.83           (if (nil? (:species2 pokemon))
    2.84 -           (assoc pokemon :species2 (:species pokemon)))))
    2.85 +           (assoc pokemon :species2 (:species pokemon))
    2.86 +           pokemon)))
    2.87  
    2.88        ;; enable the date in :moves to be any combo of 
    2.89        ;; [:move-1 :move-2]
    2.90 @@ -415,11 +415,11 @@
    2.91                    (for [move moves]
    2.92                      (cond
    2.93                        (keyword? move)
    2.94 -                      [move {:pp (max-pp move) :pp-up 0}]
    2.95 +                      [move {:current-pp (max-pp move) :pp-ups 0}]
    2.96                        (vector? move)
    2.97                        [(first move)
    2.98 -                       (merge {:pp (max-pp (first move) 0)
    2.99 -                               :pp-up 0} (second move))]))))))
   2.100 +                       (merge {:current-pp (max-pp (first move) 0)
   2.101 +                               :pp-ups 0} (second move))]))))))
   2.102        ;; The game stores the pokemon's type redundantly
   2.103        ;; along with the species.  If it's not specified
   2.104        ;; then it should default to that species default type.
   2.105 @@ -429,3 +429,24 @@
   2.106                    (pokemon->type (:species pokemon)))
   2.107             pokemon)))))
   2.108  
   2.109 +(defn give-pokemon
   2.110 +  ([^SaveState state poke-num pokemon]
   2.111 +     (let [pokemon* (expand-pokemon pokemon)]
   2.112 +       (-> state
   2.113 +           ;; expand roster if necessary
   2.114 +           ((fn [state]
   2.115 +              (if (< (dec (party-number state)) poke-num)
   2.116 +                (set-party-number state (inc poke-num)) state)))
   2.117 +           (rename-pokemon poke-num (:name pokemon*))
   2.118 +           (give-DV poke-num (:dv pokemon*))
   2.119 +           (give-type poke-num (:type pokemon*))
   2.120 +           (set-species poke-num (:species pokemon*))
   2.121 +           (set-species2 poke-num (:species2 pokemon*))
   2.122 +           (set-OT-id poke-num (:ID pokemon*))
   2.123 +           (set-OT-name poke-num (:original-trainer pokemon*))
   2.124 +           (give-moves-pps poke-num (:moves pokemon*))
   2.125 +           (give-status poke-num (:status pokemon*))
   2.126 +           (give-stats  poke-num (:stats  pokemon*))
   2.127 +           (give-experience poke-num (:experience pokemon*)))))
   2.128 +  ([poke-num pokemon]
   2.129 +     (give-pokemon @current-state poke-num pokemon)))
   2.130 \ No newline at end of file
     3.1 --- a/clojure/com/aurellem/gb/stats.clj	Fri Mar 23 04:39:24 2012 -0500
     3.2 +++ b/clojure/com/aurellem/gb/stats.clj	Fri Mar 23 05:45:56 2012 -0500
     3.3 @@ -28,7 +28,7 @@
     3.4  
     3.5  (defn set-current-hp
     3.6    ([^SaveState state poke-num new-hp]
     3.7 -     (set-memory state (current-hp-address poke-num)
     3.8 +     (set-memory-range state (current-hp-address poke-num)
     3.9                   (disect-bytes-2 new-hp)))
    3.10    ([poke-num new-hp]
    3.11       (set-current-hp @current-state poke-num new-hp)))
    3.12 @@ -71,9 +71,10 @@
    3.13               (disect-bytes-2 (:defense new-stats*))
    3.14               (disect-bytes-2 (:speed new-stats*))
    3.15               (disect-bytes-2 (:special new-stats*))])]
    3.16 -       (set-current-hp
    3.17 +       (set-current-hp 
    3.18          (set-memory-range state (pokemon-stats-address poke-num)
    3.19                            raw-stats)
    3.20 +        poke-num
    3.21          (:current-hp new-stats*))))
    3.22    ([poke-num new-stats]
    3.23       (give-stats @current-state poke-num new-stats)))