diff clojure/com/aurellem/gb/pokemon.clj @ 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
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/pokemon.clj	Fri Mar 23 04:39:24 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/pokemon.clj	Fri Mar 23 05:45:56 2012 -0500
     1.3 @@ -69,7 +69,7 @@
     1.4  (defn read-OT-name
     1.5    ([^SaveState state poke-num]
     1.6       (nth (original-trainers state) poke-num))
     1.7 -  ([poke-num] (read-OT @current-state poke-num)))
     1.8 +  ([poke-num] (read-OT-name @current-state poke-num)))
     1.9  
    1.10  (defn set-OT-name
    1.11    "Set the OT name for a pokemon.
    1.12 @@ -83,7 +83,7 @@
    1.13        (+ (* poke-num name-width) OT-start)
    1.14        (concat (str->character-codes new-name) [end-of-name-marker])))
    1.15    ([n new-name]
    1.16 -     (set-original-trainer @current-state n new-name)))
    1.17 +     (set-OT-name @current-state n new-name)))
    1.18  
    1.19  (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD226 0xD252])
    1.20  
    1.21 @@ -105,7 +105,7 @@
    1.22        (OT-ID-addresses poke-num)
    1.23        (disect-bytes-2 new-OT-num)))
    1.24    ([poke-num new-OT-num]
    1.25 -     (set-pokemon-id @current-state poke-num new-OT-num)))
    1.26 +     (set-OT-id @current-state poke-num new-OT-num)))
    1.27  
    1.28  (def unknown "[[[UNKNOWN]]]")
    1.29  
    1.30 @@ -203,7 +203,7 @@
    1.31  
    1.32  (def mint-berry-item-code-gsc 0x54)
    1.33  
    1.34 -(defn pokemon-info
    1.35 +(defn pokemon
    1.36    ([^SaveState state poke-num]
    1.37       (assert (<= 0 poke-num 5))
    1.38       (let [dv-values (read-DV state poke-num)
    1.39 @@ -236,7 +236,7 @@
    1.40          :experience experience
    1.41          }))
    1.42    ([poke-num]
    1.43 -     (pokemon-info @current-state poke-num)))
    1.44 +     (pokemon @current-state poke-num)))
    1.45  
    1.46  (def status-message
    1.47    {:sleep-6 "sleeping. It will wake in six turns."
    1.48 @@ -253,7 +253,7 @@
    1.49     
    1.50  (defn print-pokemon
    1.51    ([^SaveState state poke-num]
    1.52 -     (let [info (pokemon-info state poke-num)]
    1.53 +     (let [info (pokemon state poke-num)]
    1.54         (printf
    1.55          (str
    1.56           "##################################"
    1.57 @@ -373,15 +373,14 @@
    1.58      :hp-exp 0xFFFF}
    1.59  
    1.60     :stats
    1.61 -   ;; TODO recalculate these from a real ditto
    1.62     {:level 7
    1.63 -    :current-hp 50
    1.64 -    :hp 50
    1.65 -    :attack 50
    1.66 -    :defense 50
    1.67 -    :speed 50
    1.68 -    :special 50}
    1.69 -   :moves [[:transform {:pp-up 3 :pp 5}]]})
    1.70 +    :current-hp 30
    1.71 +    :hp 30
    1.72 +    :attack 18
    1.73 +    :defense 18
    1.74 +    :speed 18
    1.75 +    :special 18}
    1.76 +   :moves [[:transform {:pp-ups 3 :current-pp 5}]]})
    1.77  
    1.78  (defn expand-pokemon
    1.79    "Given a map describing a pokemon, fill in any missing
    1.80 @@ -401,7 +400,8 @@
    1.81        ;; same as species.
    1.82        ((fn [pokemon]
    1.83           (if (nil? (:species2 pokemon))
    1.84 -           (assoc pokemon :species2 (:species pokemon)))))
    1.85 +           (assoc pokemon :species2 (:species pokemon))
    1.86 +           pokemon)))
    1.87  
    1.88        ;; enable the date in :moves to be any combo of 
    1.89        ;; [:move-1 :move-2]
    1.90 @@ -415,11 +415,11 @@
    1.91                    (for [move moves]
    1.92                      (cond
    1.93                        (keyword? move)
    1.94 -                      [move {:pp (max-pp move) :pp-up 0}]
    1.95 +                      [move {:current-pp (max-pp move) :pp-ups 0}]
    1.96                        (vector? move)
    1.97                        [(first move)
    1.98 -                       (merge {:pp (max-pp (first move) 0)
    1.99 -                               :pp-up 0} (second move))]))))))
   1.100 +                       (merge {:current-pp (max-pp (first move) 0)
   1.101 +                               :pp-ups 0} (second move))]))))))
   1.102        ;; The game stores the pokemon's type redundantly
   1.103        ;; along with the species.  If it's not specified
   1.104        ;; then it should default to that species default type.
   1.105 @@ -429,3 +429,24 @@
   1.106                    (pokemon->type (:species pokemon)))
   1.107             pokemon)))))
   1.108  
   1.109 +(defn give-pokemon
   1.110 +  ([^SaveState state poke-num pokemon]
   1.111 +     (let [pokemon* (expand-pokemon pokemon)]
   1.112 +       (-> state
   1.113 +           ;; expand roster if necessary
   1.114 +           ((fn [state]
   1.115 +              (if (< (dec (party-number state)) poke-num)
   1.116 +                (set-party-number state (inc poke-num)) state)))
   1.117 +           (rename-pokemon poke-num (:name pokemon*))
   1.118 +           (give-DV poke-num (:dv pokemon*))
   1.119 +           (give-type poke-num (:type pokemon*))
   1.120 +           (set-species poke-num (:species pokemon*))
   1.121 +           (set-species2 poke-num (:species2 pokemon*))
   1.122 +           (set-OT-id poke-num (:ID pokemon*))
   1.123 +           (set-OT-name poke-num (:original-trainer pokemon*))
   1.124 +           (give-moves-pps poke-num (:moves pokemon*))
   1.125 +           (give-status poke-num (:status pokemon*))
   1.126 +           (give-stats  poke-num (:stats  pokemon*))
   1.127 +           (give-experience poke-num (:experience pokemon*)))))
   1.128 +  ([poke-num pokemon]
   1.129 +     (give-pokemon @current-state poke-num pokemon)))
   1.130 \ No newline at end of file