# HG changeset patch # User Robert McIntyre # Date 1332491509 18000 # Node ID 1ce54929bc0c1a74a4e070724123cc916564faf3 # Parent 53a74450dc8a8db8e5a54473ec7160a84a1ff4d0 enhanced pokemon printing to print out current HP as well as current total HP. diff -r 53a74450dc8a -r 1ce54929bc0c clojure/com/aurellem/gb/pokemon.clj --- a/clojure/com/aurellem/gb/pokemon.clj Fri Mar 23 02:44:45 2012 -0500 +++ b/clojure/com/aurellem/gb/pokemon.clj Fri Mar 23 03:31:49 2012 -0500 @@ -238,6 +238,19 @@ ([poke-num] (pokemon-info @current-state poke-num))) +(def status-message + {:sleep-6 "sleeping. It will wake in six turns." + :sleep-5 "sleeping. It will wake in five turns." + :sleep-4 "sleeping. It will wake in four turns." + :sleep-3 "sleeping. It will wake in three turns." + :sleep-2 "sleeping. It will wake in two turns." + :sleep-1 "sleeping. It will wake in one turn." + :poisoned "poisoned." + :frozen "frozen solid." + :burned "burned." + :paralyzed "paralyzed."}) + + (defn print-pokemon ([^SaveState state poke-num] (let [info (pokemon-info state poke-num)] @@ -257,7 +270,8 @@ (str (:name info) (str - " (" (.substring (str (:species info)) 1) ")") + " [" (.toUpperCase + (.substring (str (:species info)) 1)) "]") (str " Lvl." (format "%-3d" (:level (:stats info))))) (str (:original-trainer info) " / " (:ID info))) @@ -271,24 +285,24 @@ "+----------+----------+----------+"))) (printf - (str "|%-11s| %5d | %5d " - "| %5d | %5d | %5d |\n") + (str "|%-11s| %5d | %5d " + "| %5d | %5d | %5d |\n") "DV Values" (:hp (:dv info)) (:attack (:dv info)) (:defense (:dv info)) (:speed (:dv info)) (:special (:dv info))) (let [c (:stats info)] (printf - (str "|%-11s| %5d | %5d " - "| %5d | %5d | %5d |\n") - "Current" (:hp c) (:attack c) + (str "|%-11s|%8s | %5d " + "| %5d | %5d | %5d |\n") + "Current" (str (:current-hp c) "/" (:hp c)) (:attack c) (:defense c) (:speed c) (:special c))) (let [e (:experience info)] (printf - (str "|%-11s| %5d | %5d " - "| %5d | %5d | %5d |\n") + (str "|%-11s| %5d | %5d " + "| %5d | %5d | %5d |\n") "Experience" (:hp-exp e) (:attack-exp e) (:defense-exp e) (:speed-exp e) (:special-exp e))) @@ -311,18 +325,22 @@ (println "+------------------+----+--------+--------+\n") (println "Total Experience:" (:main-exp (:experience info))) + (if (not= :normal (:status info)) + (println "\n* This pokemon is currently" + (status-message (:status info)))) (if (not= (:species info) (:species2 info)) - (println "\nThis pokemon has a secondary species" + (println "\n* This pokemon has a secondary species" (str "(" (.substring (str (:species2 info)) 1) ")\n") - "that does not match its primary species.")) - (if (not= :normal (:status info)) - (println "\nThis pokemon is currently" - (.substring (str (:status info) ".") 1))))) + " that does not match its primary species.")))) ([poke-num] (print-pokemon @current-state poke-num))) +(defn print-team [] + (dorun (map print-pokemon (range (party-number))))) + + (defn give-status-all ([^SaveState state status] (reduce (fn [state num] diff -r 53a74450dc8a -r 1ce54929bc0c clojure/com/aurellem/gb/stats.clj --- a/clojure/com/aurellem/gb/stats.clj Fri Mar 23 02:44:45 2012 -0500 +++ b/clojure/com/aurellem/gb/stats.clj Fri Mar 23 03:31:49 2012 -0500 @@ -10,6 +10,29 @@ (def stats-record-size 11) +(def pokemon-1-current-hp-address 0xD16B) + +(defn current-hp-address [poke-num] + (+ pokemon-1-current-hp-address + (* pokemon-record-width poke-num))) + +(defn read-current-hp + ([^SaveState state poke-num] + (let [mem (memory state) + start (current-hp-address poke-num) + hp-h (aget mem start) + hp-l (aget mem (inc start))] + (glue-bytes hp-h hp-l))) + ([poke-num] + (read-current-hp @current-state poke-num))) + +(defn set-current-hp + ([^SaveState state poke-num new-hp] + (set-memory state (current-hp-address poke-num) + (disect-bytes-2 new-hp))) + ([poke-num new-hp] + (set-current-hp @current-state poke-num new-hp))) + (defn read-stats ([^SaveState state poke-num] (let [start (pokemon-stats-address poke-num) @@ -27,6 +50,7 @@ (subvec (vec (memory state)) start (+ start stats-record-size ))] {:level level + :current-hp (read-current-hp state poke-num) :hp (glue-bytes hp-h hp-l) :attack (glue-bytes attack-h attack-l) :defense (glue-bytes defense-h defense-l) @@ -47,7 +71,13 @@ (disect-bytes-2 (:defense new-stats*)) (disect-bytes-2 (:speed new-stats*)) (disect-bytes-2 (:special new-stats*))])] - (set-memory-range state (pokemon-stats-address poke-num) - raw-stats))) + (set-current-hp + (set-memory-range state (pokemon-stats-address poke-num) + raw-stats) + (:current-hp new-stats*)))) ([poke-num new-stats] (give-stats @current-state poke-num new-stats))) + + + + \ No newline at end of file