Mercurial > vba-clojure
view clojure/com/aurellem/gb/pokemon.clj @ 190:9a7a46c4aa1b
extending functionality of support namespaces in prepreation of give-pokemon
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 16:34:10 -0500 |
parents | d954835b24a4 |
children | 893c753f8088 |
line wrap: on
line source
1 (ns com.aurellem.gb.pokemon2 (:use (com.aurellem.gb gb-driver util constants characters3 moves types items status dv species5 ))6 (:import [com.aurellem.gb.gb_driver SaveState]))8 (def pokemon-names-start 0xD2B4)10 (defn set-party-number11 ([^SaveState state new-party-num]12 (set-memory state 0xD162 new-party-num))13 ([new-party-num]14 (set-party-number @current-state new-party-num)))16 (def party-number-address 0xD162)18 (defn party-number19 ([^SaveState state]20 (aget (memory state) party-number-address))21 ([] (party-number @current-state)))23 (defn party-names24 ([^SaveState state]25 (let [raw-names26 (subvec (vec (memory state))27 pokemon-names-start28 (+ pokemon-names-start29 (* name-width 6)))]30 (map31 read-name32 (take33 (party-number state)34 (partition name-width35 raw-names)))))36 ([] (party-names @current-state)))38 (defn rename-pokemon39 ([^SaveState state n new-name]40 (assert (<= 0 n (dec (party-number state))))41 (assert (<= (count new-name) max-name-length))42 (set-memory-range43 state44 (+ (* n name-width) pokemon-names-start)45 (concat (str->character-codes new-name) [end-of-name-marker])))46 ([n new-name]47 (rename-pokemon @current-state n new-name)))49 (def OT-start 0xD272)51 (defn original-trainers52 ([^SaveState state]53 (let [raw-names54 (subvec (vec (memory state))55 OT-start56 (+ OT-start57 (* name-width 6)))]58 (map read-name59 (take (party-number state)60 (partition name-width raw-names)))))61 ([] (original-trainers @current-state)))63 (defn set-original-trainer64 "Set the OT name for a pokemon.65 Note that a pokemon is still considered 'yours' if66 the OT ID is the same as your own."67 ([^SaveState state poke-num new-name]68 (assert (<= 0 poke-num (dec (party-number state))))69 (assert (<= (count new-name) max-name-length))70 (set-memory-range71 state72 (+ (* poke-num name-width) OT-start)73 (concat (str->character-codes new-name) [end-of-name-marker])))74 ([n new-name]75 (set-original-trainer @current-state n new-name)))77 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252])79 (defn set-pokemon-id80 ([^SaveState state n new-id]81 (assert (<= 0 n (dec (party-number state))))82 (assert (<= 0 new-id 0xFFFF))83 (set-memory-range84 state85 (OT-ID-addresses n)86 [(bit-shift-right (bit-and new-id 0xFF00) 8)87 (bit-and new-id 0xFF)88 ]))89 ([n new-id]90 (set-pokemon-id @current-state n new-id)))92 (def unknown "[[[UNKNOWN]]]")94 (def unknown "")96 (def pokemon-1-record97 {0xD16A "Color Map" ;; 098 0xD16B "Current-HP (h)" ;; 199 0xD16C "Current-HP (l)" ;; 2100 0XD16D "Unused" ;; 3101 0xD16E "Status" ;; 4102 0xD16F "Type 1" ;; 5103 0xD170 "Type 2" ;; 6104 0xD171 "scratch/C.R." ;; 7105 0xD172 "Move 1 ID" ;; 8106 0xD173 "Move 2 ID" ;; 9107 0xD174 "Move 3 ID" ;; 10108 0xD175 "Move 4 ID" ;; 11109 0xD176 "OT-ID (h)" ;; 12110 0xD177 "OT-ID (l)" ;; 13111 0xD178 "Exp. Points (h)" ;; 14112 0xD179 "Exp. Points (m)" ;; 15113 0xD17A "Exp. Points (l)" ;; 16114 0xD17B "HP Exp. (h)" ;; 17115 0xD17C "HP Exp. (l)" ;; 18116 0xD17D "Attack Exp. (h)" ;; 19117 0xD17E "Attack Exp. (l)" ;; 20118 0xD17F "Defense Exp. (h)" ;; 21119 0xD180 "Defense Exp. (l)" ;; 22120 0xD181 "Speed Exp. (h)" ;; 23121 0xD182 "Speed Exp. (l)" ;; 24122 0xD183 "Special Exp. (h)" ;; 25123 0xD184 "Special Exp. (l)" ;; 26124 0xD185 "DV Atk/Def" ;; 27125 0xD186 "DV Speed/Spc" ;; 28126 0xD187 "PP Move 1" ;; 29127 0xD188 "PP Move 2" ;; 30128 0xD189 "PP Move 3" ;; 31129 0xD18A "PP Move 4" ;; 32130 0xD18B "Current Level" ;; 33131 0xD18C "HP Total (h)" ;; 34132 0xD18D "HP Total (l)" ;; 35133 0xD18E "Attack (h)" ;; 36134 0xD18F "Attack (l)" ;; 37135 0xD190 "Defense (h)" ;; 38136 0xD191 "Defense (l)" ;; 39137 0xD192 "Speed (h)" ;; 40138 0xD193 "Speed (l)" ;; 41139 0xD194 "Special (h)" ;; 42140 0xD195 "Special (l)" ;; 43141 })143 (defn pokemon-record144 ([^SaveState state pokemon-num]145 (assert (<= 0 pokemon-num 5))146 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]147 (subvec (vec (memory state)) base148 (+ base pokemon-record-width))))149 ([pokemon-num] (pokemon-record @current-state pokemon-num)))151 (defn set-pokemon-record152 ([^SaveState state pokemon-num new-data]153 (assert (<= 0 pokemon-num 5))154 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]155 (set-memory-range state base new-data)))156 ([pokemon-num new-data]157 (set-pokemon-record @current-state pokemon-num new-data)))159 (defn print-pokemon-record160 ([^SaveState state pokemon-num]161 (assert (<= 0 pokemon-num 5))162 (let [poke-data (pokemon-record state pokemon-num)163 backbone (sort (keys pokemon-1-record))]164 (println "Pokemon " pokemon-num " -- "165 (nth (party-names state)166 pokemon-num) \newline)168 (println " Desc. | Hex | Dec | Binary |")169 (println "-------------------+------+-----+----------+")170 (dorun171 (map172 (comp println173 (fn [desc data]174 (format "%-16s | 0x%02X | %3d | %s |"175 desc data data176 (let [s (Integer/toBinaryString data)]177 (apply178 str179 (concat (repeat (- 8 (count s)) "0" )180 s))))))181 (map pokemon-1-record backbone)182 poke-data))))183 ([pokemon-num]184 (print-pokemon-record @current-state pokemon-num)))186 (def mint-berry-item-code-gsc 0x54)188 (defn pokemon-info [^SaveState state poke-num]189 (assert (<= 0 poke-num 5))190 (let [dv-values (read-DV state poke-num)191 type (read-type state poke-num)192 species (read-species state poke-num)194 ]199 ))