Mercurial > vba-clojure
view clojure/com/aurellem/gb/stats.clj @ 261:1b5c33614b0d
merge
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 26 Mar 2012 19:57:25 -0500 |
parents | 912496041f98 |
children |
line wrap: on
line source
1 (ns com.aurellem.gb.stats2 (:use (com.aurellem.gb gb-driver util constants))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def pokemon-1-stats-start-address 0xD18B)7 (defn pokemon-stats-address [poke-num]8 (+ pokemon-1-stats-start-address9 (* poke-num pokemon-record-width)))11 (def stats-record-size 11)13 (def pokemon-1-current-hp-address 0xD16B)15 (defn current-hp-address [poke-num]16 (+ pokemon-1-current-hp-address17 (* pokemon-record-width poke-num)))19 (defn read-current-hp20 ([^SaveState state poke-num]21 (let [mem (memory state)22 start (current-hp-address poke-num)23 hp-h (aget mem start)24 hp-l (aget mem (inc start))]25 (glue-bytes hp-h hp-l)))26 ([poke-num]27 (read-current-hp @current-state poke-num)))29 (defn set-current-hp30 ([^SaveState state poke-num new-hp]31 (set-memory-range state (current-hp-address poke-num)32 (disect-bytes-2 new-hp)))33 ([poke-num new-hp]34 (set-current-hp @current-state poke-num new-hp)))36 (defn read-stats37 ([^SaveState state poke-num]38 (let [start (pokemon-stats-address poke-num)39 [level40 hp-h41 hp-l42 attack-h43 attack-l44 defense-h45 defense-l46 speed-h47 speed-l48 special-h49 special-l]50 (subvec (vec (memory state))51 start (+ start stats-record-size ))]52 {:level level53 :current-hp (read-current-hp state poke-num)54 :hp (glue-bytes hp-h hp-l)55 :attack (glue-bytes attack-h attack-l)56 :defense (glue-bytes defense-h defense-l)57 :speed (glue-bytes speed-h speed-l)58 :special (glue-bytes special-h special-l)}))59 ([poke-num]60 (read-stats @current-state poke-num)))62 (defn give-stats63 ([^SaveState state poke-num new-stats]64 (let [new-stats* (merge (read-stats state poke-num)65 new-stats)66 raw-stats67 (flatten68 [(:level new-stats*)69 (disect-bytes-2 (:hp new-stats*))70 (disect-bytes-2 (:attack new-stats*))71 (disect-bytes-2 (:defense new-stats*))72 (disect-bytes-2 (:speed new-stats*))73 (disect-bytes-2 (:special new-stats*))])]74 (set-current-hp75 (set-memory-range state (pokemon-stats-address poke-num)76 raw-stats)77 poke-num78 (:current-hp new-stats*))))79 ([poke-num new-stats]80 (give-stats @current-state poke-num new-stats)))