Mercurial > vba-clojure
view clojure/com/aurellem/gb/pokemon.clj @ 180:4f5ea93cbaca
determined location of pokemon types; added functions for reading/setting them.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 01:25:39 -0500 |
parents | d63886d63b2f |
children | f0c1e5574e81 |
line wrap: on
line source
1 (ns com.aurellem.gb.pokemon2 (:use (com.aurellem.gb gb-driver util constants characters))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def pokemon-names-start 0xD2B4)7 (defn set-party-number8 ([^SaveState state new-party-num]9 (set-memory state 0xD162 new-party-num))10 ([new-party-num]11 (set-party-number @current-state new-party-num)))13 (def party-number-address 0xD162)15 (defn party-number16 ([^SaveState state]17 (aget (memory state) party-number-address))18 ([] (party-number @current-state)))20 (defn party-names21 ([^SaveState state]22 (let [raw-names23 (subvec (vec (memory state))24 pokemon-names-start25 (+ pokemon-names-start26 (* name-width 6)))]27 (map28 read-name29 (take30 (party-number state)31 (partition name-width32 raw-names)))))33 ([] (party-names @current-state)))35 (defn rename-pokemon36 ([^SaveState state n new-name]37 (assert (<= 0 n (dec (party-number state))))38 (assert (<= (count new-name) max-name-length))39 (set-memory-range40 state41 (+ (* n name-width) pokemon-names-start)42 (concat (str->character-codes new-name) [end-of-name-marker])))43 ([n new-name]44 (rename-pokemon @current-state n new-name)))46 (def OT-start 0xD272)48 (defn original-trainers49 ([^SaveState state]50 (let [raw-names51 (subvec (vec (memory state))52 OT-start53 (+ OT-start54 (* name-width 6)))]55 (map read-name56 (take (party-number state)57 (partition name-width raw-names)))))58 ([] (original-trainers @current-state)))60 (defn set-original-trainer61 "Set the OT name for a pokemon.62 Note that a pokemon is still considered 'yours' if63 the OT ID is the same as your own."64 ([^SaveState state poke-num new-name]65 (assert (<= 0 poke-num (dec (party-number state))))66 (assert (<= (count new-name) max-name-length))67 (set-memory-range68 state69 (+ (* poke-num name-width) OT-start)70 (concat (str->character-codes new-name) [end-of-name-marker])))71 ([n new-name]72 (set-original-trainer @current-state n new-name)))74 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252])76 (defn set-pokemon-id77 ([^SaveState state n new-id]78 (assert (<= 0 n (dec (party-number state))))79 (assert (<= 0 new-id 0xFFFF))80 (set-memory-range81 state82 (OT-ID-addresses n)83 [(bit-shift-right (bit-and new-id 0xFF00) 8)84 (bit-and new-id 0xFF)85 ]))86 ([n new-id]87 (set-pokemon-id @current-state n new-id)))89 (def unknown "[[[UNKNOWN]]]")91 (def unknown "")93 (def pokemon-1-info94 {0xD16A "Color Map" ;; 095 0xD16B "Current-HP (h)" ;; 196 0xD16C "Current-HP (l)" ;; 297 0XD16D unknown ;; 398 0xD16E "Status" ;; 499 0xD16F unknown ;; 5100 0xD170 unknown ;; 6101 0xD171 unknown ;; 7102 0xD172 "Move 1 ID" ;; 8103 0xD173 "Move 2 ID" ;; 9104 0xD174 "Move 3 ID" ;; 10105 0xD175 "Move 4 ID" ;; 11106 0xD176 "OT-ID (h)" ;; 12107 0xD177 "OT-ID (l)" ;; 13108 0xD178 "Exp. Points (h)" ;; 14109 0xD179 "Exp. Points (m)" ;; 15110 0xD17A "Exp. Points (l)" ;; 16111 0xD17B "HP Exp. (h)" ;; 17112 0xD17C "HP Exp. (l)" ;; 18113 0xD17D "Attack Exp. (h)" ;; 19114 0xD17E "Attack Exp. (l)" ;; 20115 0xD17F "Defense Exp. (h)" ;; 21116 0xD180 "Defense Exp. (l)" ;; 22117 0xD181 "Speed Exp. (h)" ;; 23118 0xD182 "Speed Exp. (l)" ;; 24119 0xD183 "Special Exp. (h)" ;; 25120 0xD184 "Special Exp. (l)" ;; 26121 0xD185 "DV Atk/Def" ;; 27122 0xD186 "DV Speed/Spc" ;; 28123 0xD187 "PP Move 1" ;; 29124 0xD188 "PP Move 2" ;; 30125 0xD189 "PP Move 3" ;; 31126 0xD18A "PP Move 4" ;; 32127 0xD18B "Current Level" ;; 33128 0xD18C "HP Total (h)" ;; 34129 0xD18D "HP Total (l)" ;; 35130 0xD18E "Attack (h)" ;; 36131 0xD18F "Attack (l)" ;; 37132 0xD190 "Defense (h)" ;; 38133 0xD191 "Defense (l)" ;; 39134 0xD192 "Speed (h)" ;; 40135 0xD193 "Speed (l)" ;; 41136 0xD194 "Special (h)" ;; 42137 0xD195 "Special (l)" ;; 43138 })140 (defn pokemon-data141 ([^SaveState state pokemon-num]142 (assert (<= 0 pokemon-num 5))143 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]144 (subvec (vec (memory state)) base145 (+ base pokemon-record-width))))146 ([pokemon-num] (pokemon-data @current-state pokemon-num)))148 (defn set-pokemon-data149 ([^SaveState state pokemon-num new-data]150 (assert (<= 0 pokemon-num 5))151 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]152 (set-memory-range state base new-data)))153 ([pokemon-num new-data]154 (set-pokemon-data @current-state pokemon-num new-data)))156 (defn print-pokemon-data157 ([^SaveState state pokemon-num]158 (assert (<= 0 pokemon-num 5))159 (let [poke-data (pokemon-data state pokemon-num)160 backbone (sort (keys pokemon-1-info))]161 (println "Pokemon " pokemon-num " -- "162 (nth (party-names state)163 pokemon-num) \newline)165 (println " Desc. | Hex | Dec | Binary |")166 (println "-------------------+------+-----+----------+")167 (dorun168 (map169 (comp println170 (fn [desc data]171 (format "%-16s | 0x%02X | %3d | %s |"172 desc data data173 (let [s (Integer/toBinaryString data)]174 (apply175 str176 (concat (repeat (- 8 (count s)) "0" )177 s))))))178 (map pokemon-1-info backbone)179 poke-data))))180 ([pokemon-num]181 (print-pokemon-data @current-state pokemon-num)))