changeset 202:1ce54929bc0c

enhanced pokemon printing to print out current HP as well as current total HP.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 03:31:49 -0500
parents 53a74450dc8a
children 85a2c2e2d318
files clojure/com/aurellem/gb/pokemon.clj clojure/com/aurellem/gb/stats.clj
diffstat 2 files changed, 63 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/gb/pokemon.clj	Fri Mar 23 02:44:45 2012 -0500
     1.2 +++ b/clojure/com/aurellem/gb/pokemon.clj	Fri Mar 23 03:31:49 2012 -0500
     1.3 @@ -238,6 +238,19 @@
     1.4    ([poke-num]
     1.5       (pokemon-info @current-state poke-num)))
     1.6  
     1.7 +(def status-message
     1.8 +  {:sleep-6 "sleeping. It will wake in six turns."
     1.9 +   :sleep-5 "sleeping. It will wake in five turns."
    1.10 +   :sleep-4 "sleeping. It will wake in four turns."
    1.11 +   :sleep-3 "sleeping. It will wake in three turns."
    1.12 +   :sleep-2 "sleeping. It will wake in two turns."
    1.13 +   :sleep-1 "sleeping. It will wake in one turn."
    1.14 +   :poisoned "poisoned."
    1.15 +   :frozen "frozen solid."
    1.16 +   :burned "burned."
    1.17 +   :paralyzed "paralyzed."})
    1.18 +
    1.19 +   
    1.20  (defn print-pokemon
    1.21    ([^SaveState state poke-num]
    1.22       (let [info (pokemon-info state poke-num)]
    1.23 @@ -257,7 +270,8 @@
    1.24          (str
    1.25           (:name info)
    1.26           (str
    1.27 -          " (" (.substring (str (:species info)) 1) ")")
    1.28 +          " [" (.toUpperCase
    1.29 +                (.substring (str (:species info)) 1)) "]")
    1.30           (str "  Lvl." (format "%-3d" (:level (:stats info)))))
    1.31          (str (:original-trainer info) " / " (:ID info)))
    1.32         
    1.33 @@ -271,24 +285,24 @@
    1.34                "+----------+----------+----------+")))
    1.35  
    1.36         (printf
    1.37 -        (str "|%-11s|  %5d   |  %5d   "
    1.38 -             "|  %5d   |  %5d   |  %5d   |\n")
    1.39 +        (str "|%-11s|   %5d  |   %5d  "
    1.40 +             "|   %5d  |   %5d  |   %5d  |\n")
    1.41          "DV Values" (:hp (:dv info)) (:attack (:dv info))
    1.42          (:defense (:dv info)) (:speed (:dv info))
    1.43          (:special (:dv info)))
    1.44  
    1.45         (let [c (:stats info)]
    1.46           (printf
    1.47 -          (str "|%-11s|  %5d   |  %5d   "
    1.48 -               "|  %5d   |  %5d   |  %5d   |\n")
    1.49 -          "Current" (:hp c) (:attack c)
    1.50 +          (str "|%-11s|%8s  |   %5d  "
    1.51 +               "|   %5d  |   %5d  |   %5d  |\n")
    1.52 +          "Current" (str (:current-hp c) "/" (:hp c)) (:attack c)
    1.53            (:defense c) (:speed c)
    1.54            (:special c)))
    1.55                
    1.56         (let [e (:experience info)]
    1.57           (printf
    1.58 -          (str "|%-11s|  %5d   |  %5d   "
    1.59 -               "|  %5d   |  %5d   |  %5d   |\n")
    1.60 +          (str "|%-11s|   %5d  |   %5d  "
    1.61 +               "|   %5d  |   %5d  |   %5d  |\n")
    1.62            "Experience" (:hp-exp e) (:attack-exp e)
    1.63            (:defense-exp e) (:speed-exp e)
    1.64            (:special-exp e)))
    1.65 @@ -311,18 +325,22 @@
    1.66         (println "+------------------+----+--------+--------+\n")
    1.67         
    1.68         (println "Total Experience:" (:main-exp (:experience info)))
    1.69 +       (if (not= :normal (:status info))
    1.70 +         (println "\n* This pokemon is currently"
    1.71 +                  (status-message (:status info))))
    1.72         (if (not= (:species info) (:species2 info))
    1.73 -         (println "\nThis pokemon has a secondary species"
    1.74 +         (println "\n* This pokemon has a secondary species"
    1.75                    (str
    1.76                     "("
    1.77                     (.substring (str (:species2 info)) 1) ")\n")
    1.78 -                  "that does not match its primary species."))
    1.79 -       (if (not= :normal (:status info))
    1.80 -         (println "\nThis pokemon is currently"
    1.81 -                  (.substring (str (:status info) ".") 1)))))
    1.82 +                  "  that does not match its primary species."))))
    1.83    ([poke-num]
    1.84       (print-pokemon @current-state poke-num)))
    1.85  
    1.86 +(defn print-team [] 
    1.87 +  (dorun (map print-pokemon (range (party-number)))))
    1.88 +
    1.89 +
    1.90  (defn give-status-all
    1.91    ([^SaveState state status]
    1.92       (reduce (fn [state num]
     2.1 --- a/clojure/com/aurellem/gb/stats.clj	Fri Mar 23 02:44:45 2012 -0500
     2.2 +++ b/clojure/com/aurellem/gb/stats.clj	Fri Mar 23 03:31:49 2012 -0500
     2.3 @@ -10,6 +10,29 @@
     2.4  
     2.5  (def stats-record-size 11)
     2.6  
     2.7 +(def pokemon-1-current-hp-address 0xD16B)
     2.8 +
     2.9 +(defn current-hp-address [poke-num]
    2.10 +  (+ pokemon-1-current-hp-address
    2.11 +     (* pokemon-record-width poke-num)))
    2.12 +
    2.13 +(defn read-current-hp
    2.14 +  ([^SaveState state poke-num]
    2.15 +     (let [mem (memory state)
    2.16 +           start (current-hp-address poke-num)
    2.17 +           hp-h (aget mem start)
    2.18 +           hp-l (aget mem (inc start))]
    2.19 +       (glue-bytes hp-h hp-l)))
    2.20 +  ([poke-num]
    2.21 +     (read-current-hp @current-state poke-num)))
    2.22 +
    2.23 +(defn set-current-hp
    2.24 +  ([^SaveState state poke-num new-hp]
    2.25 +     (set-memory state (current-hp-address poke-num)
    2.26 +                 (disect-bytes-2 new-hp)))
    2.27 +  ([poke-num new-hp]
    2.28 +     (set-current-hp @current-state poke-num new-hp)))
    2.29 +
    2.30  (defn read-stats
    2.31    ([^SaveState state poke-num]
    2.32       (let [start (pokemon-stats-address poke-num)
    2.33 @@ -27,6 +50,7 @@
    2.34             (subvec (vec (memory state))
    2.35                     start (+ start stats-record-size ))]
    2.36         {:level level
    2.37 +        :current-hp (read-current-hp state poke-num)
    2.38          :hp (glue-bytes hp-h hp-l)
    2.39          :attack (glue-bytes attack-h attack-l)
    2.40          :defense (glue-bytes defense-h defense-l)
    2.41 @@ -47,7 +71,13 @@
    2.42               (disect-bytes-2 (:defense new-stats*))
    2.43               (disect-bytes-2 (:speed new-stats*))
    2.44               (disect-bytes-2 (:special new-stats*))])]
    2.45 -       (set-memory-range state (pokemon-stats-address poke-num)
    2.46 -                         raw-stats)))
    2.47 +       (set-current-hp
    2.48 +        (set-memory-range state (pokemon-stats-address poke-num)
    2.49 +                          raw-stats)
    2.50 +        (:current-hp new-stats*))))
    2.51    ([poke-num new-stats]
    2.52       (give-stats @current-state poke-num new-stats)))
    2.53 +
    2.54 +
    2.55 +       
    2.56 +     
    2.57 \ No newline at end of file