Mercurial > vba-clojure
view clojure/com/aurellem/items.clj @ 100:2090bcb78f44
created functions to get and set register values
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 12 Mar 2012 12:37:04 -0500 |
parents | 9fad96094950 |
children | 4d9ce3188655 |
line wrap: on
line source
1 (ns com.aurellem.items2 (:use (com.aurellem gb-driver vbm title))3 ;; this is bullshit4 (:import [com.aurellem.gb_driver SaveState]))6 (defn game-name []7 (map char (subvec (vec (memory)) 0x134 0x142)))9 (def item-list-start 0xD31C)11 (defn item-list [^SaveState state]12 (subvec13 (vec (memory state))14 item-list-start15 (+ item-list-start 150)))17 (def item-hack-3 (read-state 77557))19 (def item-code->item-name20 (hash-map21 1 :master-ball22 2 :ultra-ball23 3 :great-ball24 4 :poke-ball25 5 :town-map26 6 :bicycle27 8 :safari-ball28 9 :pokedex29 10 :moon-stone30 11 :antidote31 12 :burn-heal32 13 :ice-heal33 14 :awakening34 15 :parlyz-heal35 16 :full-restore36 17 :max-potion37 18 :hyper-potion38 19 :super-potion39 20 :potion40 21 :boulderbadge41 22 :cascadebadge42 23 :thunderbadge43 24 :rainbowbadge44 25 :soulbadge45 26 :marshbadge46 27 :volcanobadge47 28 :earthbadge48 29 :escape-rope49 30 :repel50 31 :old-amber51 32 :fire-stone52 33 :thunderstone53 34 :water-stone54 35 :hp-up55 36 :protein56 37 :iron57 38 :carbos58 39 :calcium59 40 :rare-candy60 41 :dome-fossil61 42 :helix-fossil62 43 :secret-key63 45 :bike-voucher64 46 :x-accuracy65 47 :leaf-stone66 48 :card-key67 49 :nugget68 50 :pp-up69 51 :poke-doll70 52 :full-heal71 53 :revive72 54 :max-revive73 55 :guard-spec74 56 :super-repel75 57 :max-repel76 58 :dire-hit77 59 :coin78 60 :fresh-water79 61 :soda-pop80 62 :lemonade81 63 :s.s.ticket82 64 :gold-teeth83 65 :x-attach84 66 :x-defend85 67 :x-speed86 68 :x-special87 69 :coin-case88 70 :oaks-parcel89 71 :itemfinder90 72 :silph-scope91 73 :poke-flute92 74 :lift-key93 75 :exp.all94 76 :old-rod95 77 :good-rod96 78 :super-rod97 79 :pp-up98 80 :ether99 81 :max-ether100 82 :elixer101 83 :max-elixer102 196 :HM01103 197 :HM02104 198 :HM03105 199 :HM04106 200 :HM05107 201 :TM01108 202 :TM02109 203 :TM03110 204 :TM04111 205 :TM05112 206 :TM06113 207 :TM07114 208 :TM08115 209 :TM09116 210 :TM10117 211 :TM11118 212 :TM12119 213 :TM13120 214 :TM13121 215 :TM15122 216 :TM16123 217 :TM17124 218 :TM18125 219 :TM19126 220 :TM20127 221 :TM21128 222 :TM22129 223 :TM23130 224 :TM24131 225 :TM25132 226 :TM26133 227 :TM27134 228 :TM28135 229 :TM29136 230 :TM30137 231 :TM31138 232 :TM32139 233 :TM33140 234 :TM34141 235 :TM35142 236 :TM36143 237 :TM37144 238 :TM38145 239 :TM39146 240 :TM40147 241 :TM41148 242 :TM42149 243 :TM43150 244 :TM44151 245 :TM45152 246 :TM46153 247 :TM47154 248 :TM48155 249 :TM49156 250 :TM50157 251 :TM51158 252 :TM52159 253 :TM53160 254 :TM54161 255 :end-of-list-sentinel))163 (def item-name->item-code164 (zipmap (vals item-code->item-name)165 (keys item-code->item-name)))167 (defn inventory [^SaveState state]168 (let [items (item-list state)]169 (map170 (fn [[item-code quantity]]171 [(item-code->item-name item-code)172 quantity])173 (partition174 2175 (next (take-while (partial not= 255) items))))))177 (defn print-inventory [^SaveState state]178 (println179 (let [inv (inventory state)]180 (reduce181 str182 (concat183 ["+-------------------+----------+\n"184 "|##| Item | Quantity |\n"185 "+--+----------------+----------+\n"]187 (map188 (fn [index [item-name quantity]]189 (str190 (format "|%-2d| %-14s | %3d |\n" index191 (apply str (rest (str item-name)))192 quantity)))193 (range 0 (count inv)) inv)194 ["+--+----------------+----------+\n"])))))196 (defn inventory-codes [inventory]197 (flatten198 (concat [(count inventory)]199 (map (fn [[item-name quantity]]200 [(item-name->item-code item-name)201 quantity]) inventory)202 [(item-name->item-code :end-of-list-sentinel)])))204 (defn set-inventory [^SaveState state new-inventory]205 (set-state! state)206 (let [mem (memory state)207 inv (inventory-codes new-inventory)]209 (dorun (map (fn [index val]210 (aset mem index val))211 (range item-list-start212 (+ item-list-start (count inv))) inv))213 (write-memory! mem)214 (update-state)))