Mercurial > vba-clojure
view clojure/com/aurellem/gb/items.clj @ 499:8b8053ccb33c
generated graphical representation of the gb color map.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 12 Jun 2012 03:36:47 -0500 |
parents | 716752719a78 |
children |
line wrap: on
line source
1 (ns com.aurellem.gb.items2 (:use (com.aurellem.gb gb-driver util))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (defn game-name6 "return pokemon-yellow header information"7 []8 (map char (subvec (vec (memory)) 0x134 0x142)))10 (def item-list-start 0xD31C)11 (def pc-item-list-start 0xD539)12 (def pc-item-list-width 101)14 (defn item-list15 ([^SaveState state]16 (subvec17 (vec (memory state))18 item-list-start19 (+ item-list-start 255)))20 ([] (item-list @current-state)))22 (defn nth-item23 ([^SaveState state n]24 (let [mem (memory state)]25 [(aget mem (+ item-list-start 1 (* 2 n)))26 (aget mem (+ item-list-start 2 (* 2 n)))]))27 ([n] (nth-item @current-state n)))29 (defn nth-pc-item30 ([^SaveState state n]31 (let [mem (memory state)]32 [(aget mem (+ pc-item-list-start 1 (* 2 n)))33 (aget mem (+ pc-item-list-start 2 (* 2 n)))]))34 ([n] (nth-pc-item @current-state n)))36 (def item-code->item-name37 (hash-map38 0x01 :master-ball39 0x02 :ultra-ball40 0x03 :great-ball41 0x04 :poke-ball42 0x05 :town-map43 0x06 :bicycle44 0x07 :surfboard45 0x08 :safari-ball46 0x09 :pokedex47 0x0A :moon-stone48 0x0B :antidote49 0x0C :burn-heal50 0x0D :ice-heal51 0x0E :awakening52 0x0F :parlyz-heal53 0x10 :full-restore54 0x11 :max-potion55 0x12 :hyper-potion56 0x13 :super-potion57 0x14 :potion58 0x15 :boulderbadge59 0x16 :cascadebadge60 0x17 :thunderbadge61 0x18 :rainbowbadge62 0x19 :soulbadge63 0x1A :marshbadge64 0x1B :volcanobadge65 0x1C :earthbadge66 0x1D :escape-rope67 0x1E :repel68 0x1F :old-amber69 0x20 :fire-stone70 0x21 :thunderstone71 0x22 :water-stone72 0x23 :hp-up73 0x24 :protein74 0x25 :iron75 0x26 :carbos76 0x27 :calcium77 0x28 :rare-candy78 0x29 :dome-fossil79 0x2A :helix-fossil80 0x2B :secret-key81 0x2D :bike-voucher82 0x2E :x-accuracy83 0x2F :leaf-stone84 0x30 :card-key85 0x31 :nugget86 0x32 :pp-up-glitched87 0x33 :poke-doll88 0x34 :full-heal89 0x35 :revive90 0x36 :max-revive91 0x37 :guard-spec92 0x38 :super-repel93 0x39 :max-repel94 0x3A :dire-hit95 0x3B :coin96 0x3C :fresh-water97 0x3D :soda-pop98 0x3E :lemonade99 0x3F :s.s.ticket100 0x40 :gold-teeth101 0x41 :x-attack102 0x42 :x-defend103 0x43 :x-speed104 0x44 :x-special105 0x45 :coin-case106 0x46 :oaks-parcel107 0x47 :itemfinder108 0x48 :silph-scope109 0x49 :poke-flute110 0x4A :lift-key111 0x4B :exp.all112 0x4C :old-rod113 0x4D :good-rod114 0x4E :super-rod115 0x4F :pp-up116 0x50 :ether117 0x51 :max-ether118 0x52 :elixer119 0x53 :max-elixer120 0xC4 :HM01 ;; cut121 0xC5 :HM02 ;; fly122 0xC6 :HM03 ;; surf123 0xC7 :HM04 ;; strength124 0xC8 :HM05 ;; flash125 0xC9 :TM01 ;; mega punch126 0xCA :TM02 ;; razor wind127 0xCB :TM03 ;; swords dance128 0xCC :TM04 ;; whirlwind129 0xCD :TM05 ;; mega kick130 0xCE :TM06 ;; toxic131 0xCF :TM07 ;; horn drill132 0xD0 :TM08 ;; body slam133 0xD1 :TM09 ;; take down134 0xD2 :TM10 ;; double-edge135 0xD3 :TM11 ;; bubblebeam136 0xD4 :TM12 ;; water gun137 0xD5 :TM13 ;; ice beam138 0xD6 :TM14 ;; blizzard139 0xD7 :TM15 ;; hyper beam140 0xD8 :TM16 ;; pay day141 0xD9 :TM17 ;; submission142 0xDA :TM18 ;; counter143 0xDB :TM19 ;; seismic toss144 0xDC :TM20 ;; rage145 0xDD :TM21 ;; mega drain146 0xDE :TM22 ;; solarbeam147 0xDF :TM23 ;; dragon rage148 0xE0 :TM24 ;; thunderbolt149 0xE1 :TM25 ;; thunder150 0xE2 :TM26 ;; earthquake151 0xE3 :TM27 ;; fissure152 0xE4 :TM28 ;; dig153 0xE5 :TM29 ;; psychic154 0xE6 :TM30 ;; teleport155 0xE7 :TM31 ;; mimic156 0xE8 :TM32 ;; double team157 0xE9 :TM33 ;; reflect158 0xEA :TM34 ;; bide159 0xEB :TM35 ;; metronome160 0xEC :TM36 ;; self destruct161 0xED :TM37 ;; egg bomb162 0xEE :TM38 ;; fire blast163 0xEF :TM39 ;; swift164 0xF0 :TM40 ;; skull bash165 0xF1 :TM41 ;; softboiled166 0xF2 :TM42 ;; dream eater167 0xF3 :TM43 ;; sky attack168 0xF4 :TM44 ;; rest169 0xF5 :TM45 ;; thunder wave170 0xF6 :TM46 ;; psywave171 0xF7 :TM47 ;; explosion172 0xF8 :TM48 ;; rock slide173 0xF9 :TM49 ;; tri attack174 0xFA :TM50 ;; substitute175 0xFB :TM51 ;; "cut"176 0xFC :TM52 ;; "fly"177 0xFD :TM53 ;; "surf"178 0xFE :TM54 ;; "strength"179 0xFF :TM55 ;; "flash" (also end-of-list-sentinel)180 ))182 (def item-name->item-code183 (zipmap (vals item-code->item-name)184 (keys item-code->item-name)))186 (defn raw-inventory->inventory187 [raw-inventory]188 (map189 (fn [[item-code quantity]]190 [(item-code->item-name191 item-code192 item-code)193 quantity])194 (partition195 2196 raw-inventory)))198 (defn total-held-items [state]199 (aget (memory state) item-list-start))201 (defn inventory202 ([^SaveState state]203 (let [items (item-list state)]204 (raw-inventory->inventory205 (take (* 2 (total-held-items state)) (next items)))))206 ([] (inventory @current-state)))208 (defn print-inventory209 ([] (print-inventory @current-state))210 ([^SaveState state]211 (println212 (let [inv (inventory state)]213 (reduce214 str215 (concat216 ["+-------------------+----------+\n"217 "|##| Item | Quantity |\n"218 "+--+----------------+----------+\n"]220 (map221 (fn [index [item-name quantity]]222 (str223 (format "|%-2d| %-14s | %3d |\n" index224 (apply str (rest (str item-name)))225 quantity)))226 (range 0 (count inv)) inv)227 ["+--+----------------+----------+\n"]))))228 state))230 (defn inventory-codes [inventory]231 (flatten232 (concat [(count inventory)]233 (map (fn [[item-name quantity]]234 [(item-name->item-code item-name item-name)235 quantity]) inventory)236 [(item-name->item-code :TM55)])))238 (defn set-inv-mem [^SaveState state inv-codes]239 (set-memory-range state item-list-start240 inv-codes))243 (defn set-inventory [^SaveState state new-inventory]244 (set-inv-mem state (inventory-codes new-inventory)))246 (defn give-items247 ([^SaveState state items]248 (set-inventory state249 (concat items (inventory state))))250 ([items]251 (give-items @current-state items)))253 (defn clear-inventory254 ([^SaveState state]255 (set-inventory state []))256 ([] (clear-inventory @current-state)))