Mercurial > vba-clojure
view clojure/com/aurellem/gb/items.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 | 8665160f0f3d |
children | 4ea8ff49af87 c8ec477beeac |
line wrap: on
line source
1 (ns com.aurellem.gb.items2 (:use (com.aurellem.gb gb-driver util))3 ;; this is bullshit4 (:import [com.aurellem.gb.gb_driver SaveState]))6 (defn game-name []7 (map char (subvec (vec (memory)) 0x134 0x142)))9 (def item-list-start 0xD31C)11 (defn item-list12 ([^SaveState state]13 (subvec14 (vec (memory state))15 item-list-start16 (+ item-list-start 255)))17 ([] (item-list @current-state)))19 (def item-code->item-name20 (hash-map21 0x01 :master-ball22 0x02 :ultra-ball23 0x03 :great-ball24 0x04 :poke-ball25 0x05 :town-map26 0x06 :bicycle27 0x08 :safari-ball28 0x09 :pokedex29 0x0A :moon-stone30 0x0B :antidote31 0x0C :burn-heal32 0x0D :ice-heal33 0x0E :awakening34 0x0F :parlyz-heal35 0x10 :full-restore36 0x11 :max-potion37 0x12 :hyper-potion38 0x13 :super-potion39 0x14 :potion40 0x15 :boulderbadge41 0x16 :cascadebadge42 0x17 :thunderbadge43 0x18 :rainbowbadge44 0x19 :soulbadge45 0x1A :marshbadge46 0x1B :volcanobadge47 0x1C :earthbadge48 0x1D :escape-rope49 0x1E :repel50 0x1F :old-amber51 0x20 :fire-stone52 0x21 :thunderstone53 0x22 :water-stone54 0x23 :hp-up55 0x24 :protein56 0x25 :iron57 0x26 :carbos58 0x27 :calcium59 0x28 :rare-candy60 0x29 :dome-fossil61 0x2A :helix-fossil62 0x2B :secret-key63 0x2D :bike-voucher64 0x2E :x-accuracy65 0x2F :leaf-stone66 0x30 :card-key67 0x31 :nugget68 0x32 :pp-up69 0x33 :poke-doll70 0x34 :full-heal71 0x35 :revive72 0x36 :max-revive73 0x37 :guard-spec74 0x38 :super-repel75 0x39 :max-repel76 0x3A :dire-hit77 0x3B :coin78 0x3C :fresh-water79 0x3D :soda-pop80 0x3E :lemonade81 0x3F :s.s.ticket82 0x40 :gold-teeth83 0x41 :x-attack84 0x42 :x-defend85 0x43 :x-speed86 0x44 :x-special87 0x45 :coin-case88 0x46 :oaks-parcel89 0x47 :itemfinder90 0x48 :silph-scope91 0x49 :poke-flute92 0x4A :lift-key93 0x4B :exp.all94 0x4C :old-rod95 0x4D :good-rod96 0x4E :super-rod97 0x4F :pp-up98 0x50 :ether99 0x51 :max-ether100 0x52 :elixer101 0x53 :max-elixer102 0xC4 :HM01 ;; cut103 0xC5 :HM02 ;; fly104 0xC6 :HM03 ;; surf105 0xC7 :HM04 ;; strength106 0xC8 :HM05 ;; flash107 0xC9 :TM01 ;; mega punch108 0xCA :TM02 ;; razor wind109 0xCB :TM03 ;; swords dance110 0xCC :TM04 ;; whirlwind111 0xCD :TM05 ;; mega kick112 0xCE :TM06 ;; toxic113 0xCF :TM07 ;; horn drill114 0xD0 :TM08 ;; body slam115 0xD1 :TM09 ;; take down116 0xD2 :TM10 ;; double-edge117 0xD3 :TM11 ;; bubblebeam118 0xD4 :TM12 ;; water gun119 0xD5 :TM13 ;; ice beam120 0xD6 :TM14 ;; blizzard121 0xD7 :TM15 ;; hyper beam122 0xD8 :TM16 ;; pay day123 0xD9 :TM17 ;; submission124 0xDA :TM18 ;; counter125 0xDB :TM19 ;; seismic toss126 0xDC :TM20 ;; rage127 0xDD :TM21 ;; mega drain128 0xDE :TM22 ;; solarbeam129 0xDF :TM23 ;; dragon rage130 0xE0 :TM24 ;; thunderbolt131 0xE1 :TM25 ;; thunder132 0xE2 :TM26 ;; earthquake133 0xE3 :TM27 ;; fissure134 0xE4 :TM28 ;; dig135 0xE5 :TM29 ;; psychic136 0xE6 :TM30 ;; teleport137 0xE7 :TM31 ;; mimic138 0xE8 :TM32 ;; double team139 0xE9 :TM33 ;; reflect140 0xEA :TM34 ;; bide141 0xEB :TM35 ;; metronome142 0xEC :TM36 ;; self destruct143 0xED :TM37 ;; eggbomb144 0xEE :TM38 ;; fire blast145 0xEF :TM39 ;; swift146 0xF0 :TM40 ;; skull bash147 0xF1 :TM41 ;; softboiled148 0xF2 :TM42 ;; dream eater149 0xF3 :TM43 ;; sky attack150 0xF4 :TM44 ;; rest151 0xF5 :TM45 ;; thunder wave152 0xF6 :TM46 ;; psywave153 0xF7 :TM47 ;; explosion154 0xF8 :TM48 ;; rock slide155 0xF9 :TM49 ;; tri attack156 0xFA :TM50 ;; substitute157 0xFB :TM51 ;; "cut"158 0xFC :TM52 ;; "fly"159 0xFD :TM53 ;; "surf"160 0xFE :TM54 ;; "strength"161 0xFF :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-name172 item-code173 (str ":0x" (.toUpperCase (Integer/toHexString item-code))))174 quantity])175 (partition176 2177 (next (take-while (partial not= 255) items))))))179 (defn print-inventory180 ([] (print-inventory @current-state))181 ([^SaveState state]182 (println183 (let [inv (inventory state)]184 (reduce185 str186 (concat187 ["+-------------------+----------+\n"188 "|##| Item | Quantity |\n"189 "+--+----------------+----------+\n"]191 (map192 (fn [index [item-name quantity]]193 (str194 (format "|%-2d| %-14s | %3d |\n" index195 (apply str (rest (str item-name)))196 quantity)))197 (range 0 (count inv)) inv)198 ["+--+----------------+----------+\n"]))))199 state))201 (defn inventory-codes [inventory]202 (flatten203 (concat [(count inventory)]204 (map (fn [[item-name quantity]]205 [(item-name->item-code item-name)206 quantity]) inventory)207 [(item-name->item-code :end-of-list-sentinel)])))209 (defn set-inv-mem [^SaveState state inv-codes]210 (set-memory-range state item-list-start211 inv-codes))214 (defn set-inventory [^SaveState state new-inventory]215 (set-inv-mem state (inventory-codes new-inventory)))217 (defn give-items218 ([^SaveState state items]219 (set-inventory state220 (concat items (inventory state))))221 ([items]222 (give-items @current-state items)))224 (defn clear-inventory225 ([^SaveState state]226 (set-inventory state []))227 ([] (clear-inventory @current-state)))