rlm@192: (ns com.aurellem.gb.stats rlm@192: (:use (com.aurellem.gb gb-driver util constants)) rlm@192: (:import [com.aurellem.gb.gb_driver SaveState])) rlm@192: rlm@192: (def pokemon-1-stats-start-address 0xD18B) rlm@192: rlm@192: (defn pokemon-stats-address [poke-num] rlm@192: (+ pokemon-1-stats-start-address rlm@192: (* poke-num pokemon-record-width))) rlm@192: rlm@192: (def stats-record-size 11) rlm@192: rlm@202: (def pokemon-1-current-hp-address 0xD16B) rlm@202: rlm@202: (defn current-hp-address [poke-num] rlm@202: (+ pokemon-1-current-hp-address rlm@202: (* pokemon-record-width poke-num))) rlm@202: rlm@202: (defn read-current-hp rlm@202: ([^SaveState state poke-num] rlm@202: (let [mem (memory state) rlm@202: start (current-hp-address poke-num) rlm@202: hp-h (aget mem start) rlm@202: hp-l (aget mem (inc start))] rlm@202: (glue-bytes hp-h hp-l))) rlm@202: ([poke-num] rlm@202: (read-current-hp @current-state poke-num))) rlm@202: rlm@202: (defn set-current-hp rlm@202: ([^SaveState state poke-num new-hp] rlm@209: (set-memory-range state (current-hp-address poke-num) rlm@202: (disect-bytes-2 new-hp))) rlm@202: ([poke-num new-hp] rlm@202: (set-current-hp @current-state poke-num new-hp))) rlm@202: rlm@192: (defn read-stats rlm@192: ([^SaveState state poke-num] rlm@192: (let [start (pokemon-stats-address poke-num) rlm@192: [level rlm@192: hp-h rlm@192: hp-l rlm@192: attack-h rlm@192: attack-l rlm@192: defense-h rlm@192: defense-l rlm@192: speed-h rlm@192: speed-l rlm@192: special-h rlm@192: special-l] rlm@192: (subvec (vec (memory state)) rlm@192: start (+ start stats-record-size ))] rlm@192: {:level level rlm@202: :current-hp (read-current-hp state poke-num) rlm@192: :hp (glue-bytes hp-h hp-l) rlm@192: :attack (glue-bytes attack-h attack-l) rlm@192: :defense (glue-bytes defense-h defense-l) rlm@192: :speed (glue-bytes speed-h speed-l) rlm@192: :special (glue-bytes special-h special-l)})) rlm@192: ([poke-num] rlm@192: (read-stats @current-state poke-num))) rlm@192: rlm@192: (defn give-stats rlm@192: ([^SaveState state poke-num new-stats] rlm@192: (let [new-stats* (merge (read-stats state poke-num) rlm@192: new-stats) rlm@192: raw-stats rlm@192: (flatten rlm@192: [(:level new-stats*) rlm@192: (disect-bytes-2 (:hp new-stats*)) rlm@192: (disect-bytes-2 (:attack new-stats*)) rlm@192: (disect-bytes-2 (:defense new-stats*)) rlm@192: (disect-bytes-2 (:speed new-stats*)) rlm@192: (disect-bytes-2 (:special new-stats*))])] rlm@209: (set-current-hp rlm@202: (set-memory-range state (pokemon-stats-address poke-num) rlm@202: raw-stats) rlm@209: poke-num rlm@202: (:current-hp new-stats*)))) rlm@192: ([poke-num new-stats] rlm@192: (give-stats @current-state poke-num new-stats))) rlm@202: rlm@202: rlm@202: rlm@202: