Mercurial > vba-clojure
view clojure/com/aurellem/gb/items.clj @ 274:210b465e4720
refactored walking code from buy-initial-objects to its own function.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 27 Mar 2012 11:30:58 -0500 |
parents | b7f682bb3090 |
children | 93e74ed34305 |
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)12 (defn item-list13 ([^SaveState state]14 (subvec15 (vec (memory state))16 item-list-start17 (+ item-list-start 255)))18 ([] (item-list @current-state)))20 (def item-code->item-name21 (hash-map22 0x01 :master-ball23 0x02 :ultra-ball24 0x03 :great-ball25 0x04 :poke-ball26 0x05 :town-map27 0x06 :bicycle28 0x07 :surfboard29 0x08 :safari-ball30 0x09 :pokedex31 0x0A :moon-stone32 0x0B :antidote33 0x0C :burn-heal34 0x0D :ice-heal35 0x0E :awakening36 0x0F :parlyz-heal37 0x10 :full-restore38 0x11 :max-potion39 0x12 :hyper-potion40 0x13 :super-potion41 0x14 :potion42 0x15 :boulderbadge43 0x16 :cascadebadge44 0x17 :thunderbadge45 0x18 :rainbowbadge46 0x19 :soulbadge47 0x1A :marshbadge48 0x1B :volcanobadge49 0x1C :earthbadge50 0x1D :escape-rope51 0x1E :repel52 0x1F :old-amber53 0x20 :fire-stone54 0x21 :thunderstone55 0x22 :water-stone56 0x23 :hp-up57 0x24 :protein58 0x25 :iron59 0x26 :carbos60 0x27 :calcium61 0x28 :rare-candy62 0x29 :dome-fossil63 0x2A :helix-fossil64 0x2B :secret-key65 0x2D :bike-voucher66 0x2E :x-accuracy67 0x2F :leaf-stone68 0x30 :card-key69 0x31 :nugget70 0x32 :pp-up-glitched71 0x33 :poke-doll72 0x34 :full-heal73 0x35 :revive74 0x36 :max-revive75 0x37 :guard-spec76 0x38 :super-repel77 0x39 :max-repel78 0x3A :dire-hit79 0x3B :coin80 0x3C :fresh-water81 0x3D :soda-pop82 0x3E :lemonade83 0x3F :s.s.ticket84 0x40 :gold-teeth85 0x41 :x-attack86 0x42 :x-defend87 0x43 :x-speed88 0x44 :x-special89 0x45 :coin-case90 0x46 :oaks-parcel91 0x47 :itemfinder92 0x48 :silph-scope93 0x49 :poke-flute94 0x4A :lift-key95 0x4B :exp.all96 0x4C :old-rod97 0x4D :good-rod98 0x4E :super-rod99 0x4F :pp-up100 0x50 :ether101 0x51 :max-ether102 0x52 :elixer103 0x53 :max-elixer104 0xC4 :HM01 ;; cut105 0xC5 :HM02 ;; fly106 0xC6 :HM03 ;; surf107 0xC7 :HM04 ;; strength108 0xC8 :HM05 ;; flash109 0xC9 :TM01 ;; mega punch110 0xCA :TM02 ;; razor wind111 0xCB :TM03 ;; swords dance112 0xCC :TM04 ;; whirlwind113 0xCD :TM05 ;; mega kick114 0xCE :TM06 ;; toxic115 0xCF :TM07 ;; horn drill116 0xD0 :TM08 ;; body slam117 0xD1 :TM09 ;; take down118 0xD2 :TM10 ;; double-edge119 0xD3 :TM11 ;; bubblebeam120 0xD4 :TM12 ;; water gun121 0xD5 :TM13 ;; ice beam122 0xD6 :TM14 ;; blizzard123 0xD7 :TM15 ;; hyper beam124 0xD8 :TM16 ;; pay day125 0xD9 :TM17 ;; submission126 0xDA :TM18 ;; counter127 0xDB :TM19 ;; seismic toss128 0xDC :TM20 ;; rage129 0xDD :TM21 ;; mega drain130 0xDE :TM22 ;; solarbeam131 0xDF :TM23 ;; dragon rage132 0xE0 :TM24 ;; thunderbolt133 0xE1 :TM25 ;; thunder134 0xE2 :TM26 ;; earthquake135 0xE3 :TM27 ;; fissure136 0xE4 :TM28 ;; dig137 0xE5 :TM29 ;; psychic138 0xE6 :TM30 ;; teleport139 0xE7 :TM31 ;; mimic140 0xE8 :TM32 ;; double team141 0xE9 :TM33 ;; reflect142 0xEA :TM34 ;; bide143 0xEB :TM35 ;; metronome144 0xEC :TM36 ;; self destruct145 0xED :TM37 ;; eggbomb146 0xEE :TM38 ;; fire blast147 0xEF :TM39 ;; swift148 0xF0 :TM40 ;; skull bash149 0xF1 :TM41 ;; softboiled150 0xF2 :TM42 ;; dream eater151 0xF3 :TM43 ;; sky attack152 0xF4 :TM44 ;; rest153 0xF5 :TM45 ;; thunder wave154 0xF6 :TM46 ;; psywave155 0xF7 :TM47 ;; explosion156 0xF8 :TM48 ;; rock slide157 0xF9 :TM49 ;; tri attack158 0xFA :TM50 ;; substitute159 0xFB :TM51 ;; "cut"160 0xFC :TM52 ;; "fly"161 0xFD :TM53 ;; "surf"162 0xFE :TM54 ;; "strength"163 0xFF :end-of-list-sentinel ;; also "flash"164 ))166 (def item-name->item-code167 (zipmap (vals item-code->item-name)168 (keys item-code->item-name)))170 (defn inventory [^SaveState state]171 (let [items (item-list state)]172 (map173 (fn [[item-code quantity]]174 [(item-code->item-name175 item-code176 item-code)177 quantity])178 (partition179 2180 (next (take-while (partial not= 255) items))))))182 (defn print-inventory183 ([] (print-inventory @current-state))184 ([^SaveState state]185 (println186 (let [inv (inventory state)]187 (reduce188 str189 (concat190 ["+-------------------+----------+\n"191 "|##| Item | Quantity |\n"192 "+--+----------------+----------+\n"]194 (map195 (fn [index [item-name quantity]]196 (str197 (format "|%-2d| %-14s | %3d |\n" index198 (apply str (rest (str item-name)))199 quantity)))200 (range 0 (count inv)) inv)201 ["+--+----------------+----------+\n"]))))202 state))204 (defn inventory-codes [inventory]205 (flatten206 (concat [(count inventory)]207 (map (fn [[item-name quantity]]208 [(item-name->item-code item-name item-name)209 quantity]) inventory)210 [(item-name->item-code :end-of-list-sentinel)])))212 (defn set-inv-mem [^SaveState state inv-codes]213 (set-memory-range state item-list-start214 inv-codes))217 (defn set-inventory [^SaveState state new-inventory]218 (set-inv-mem state (inventory-codes new-inventory)))220 (defn give-items221 ([^SaveState state items]222 (set-inventory state223 (concat items (inventory state))))224 ([items]225 (give-items @current-state items)))227 (defn clear-inventory228 ([^SaveState state]229 (set-inventory state []))230 ([] (clear-inventory @current-state)))