Mercurial > vba-clojure
view clojure/com/aurellem/gb/items.clj @ 447:eea3b257ef59
removed some tracks.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 03 May 2012 06:22:34 -0500 |
parents | 79252378fd22 |
children | 716752719a78 |
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)15 (defn item-list16 ([^SaveState state]17 (subvec18 (vec (memory state))19 item-list-start20 (+ item-list-start 255)))21 ([] (item-list @current-state)))23 (defn nth-item24 ([^SaveState state n]25 (let [mem (memory state)]26 [(aget mem (+ item-list-start 1 (* 2 n)))27 (aget mem (+ item-list-start 2 (* 2 n)))]))28 ([n] (nth-item @current-state n)))31 (defn nth-pc-item32 ([^SaveState state n]33 (let [mem (memory state)]34 [(aget mem (+ pc-item-list-start 1 (* 2 n)))35 (aget mem (+ pc-item-list-start 2 (* 2 n)))]))36 ([n] (nth-pc-item @current-state n)))39 (def item-code->item-name40 (hash-map41 0x01 :master-ball42 0x02 :ultra-ball43 0x03 :great-ball44 0x04 :poke-ball45 0x05 :town-map46 0x06 :bicycle47 0x07 :surfboard48 0x08 :safari-ball49 0x09 :pokedex50 0x0A :moon-stone51 0x0B :antidote52 0x0C :burn-heal53 0x0D :ice-heal54 0x0E :awakening55 0x0F :parlyz-heal56 0x10 :full-restore57 0x11 :max-potion58 0x12 :hyper-potion59 0x13 :super-potion60 0x14 :potion61 0x15 :boulderbadge62 0x16 :cascadebadge63 0x17 :thunderbadge64 0x18 :rainbowbadge65 0x19 :soulbadge66 0x1A :marshbadge67 0x1B :volcanobadge68 0x1C :earthbadge69 0x1D :escape-rope70 0x1E :repel71 0x1F :old-amber72 0x20 :fire-stone73 0x21 :thunderstone74 0x22 :water-stone75 0x23 :hp-up76 0x24 :protein77 0x25 :iron78 0x26 :carbos79 0x27 :calcium80 0x28 :rare-candy81 0x29 :dome-fossil82 0x2A :helix-fossil83 0x2B :secret-key84 0x2D :bike-voucher85 0x2E :x-accuracy86 0x2F :leaf-stone87 0x30 :card-key88 0x31 :nugget89 0x32 :pp-up-glitched90 0x33 :poke-doll91 0x34 :full-heal92 0x35 :revive93 0x36 :max-revive94 0x37 :guard-spec95 0x38 :super-repel96 0x39 :max-repel97 0x3A :dire-hit98 0x3B :coin99 0x3C :fresh-water100 0x3D :soda-pop101 0x3E :lemonade102 0x3F :s.s.ticket103 0x40 :gold-teeth104 0x41 :x-attack105 0x42 :x-defend106 0x43 :x-speed107 0x44 :x-special108 0x45 :coin-case109 0x46 :oaks-parcel110 0x47 :itemfinder111 0x48 :silph-scope112 0x49 :poke-flute113 0x4A :lift-key114 0x4B :exp.all115 0x4C :old-rod116 0x4D :good-rod117 0x4E :super-rod118 0x4F :pp-up119 0x50 :ether120 0x51 :max-ether121 0x52 :elixer122 0x53 :max-elixer123 0xC4 :HM01 ;; cut124 0xC5 :HM02 ;; fly125 0xC6 :HM03 ;; surf126 0xC7 :HM04 ;; strength127 0xC8 :HM05 ;; flash128 0xC9 :TM01 ;; mega punch129 0xCA :TM02 ;; razor wind130 0xCB :TM03 ;; swords dance131 0xCC :TM04 ;; whirlwind132 0xCD :TM05 ;; mega kick133 0xCE :TM06 ;; toxic134 0xCF :TM07 ;; horn drill135 0xD0 :TM08 ;; body slam136 0xD1 :TM09 ;; take down137 0xD2 :TM10 ;; double-edge138 0xD3 :TM11 ;; bubblebeam139 0xD4 :TM12 ;; water gun140 0xD5 :TM13 ;; ice beam141 0xD6 :TM14 ;; blizzard142 0xD7 :TM15 ;; hyper beam143 0xD8 :TM16 ;; pay day144 0xD9 :TM17 ;; submission145 0xDA :TM18 ;; counter146 0xDB :TM19 ;; seismic toss147 0xDC :TM20 ;; rage148 0xDD :TM21 ;; mega drain149 0xDE :TM22 ;; solarbeam150 0xDF :TM23 ;; dragon rage151 0xE0 :TM24 ;; thunderbolt152 0xE1 :TM25 ;; thunder153 0xE2 :TM26 ;; earthquake154 0xE3 :TM27 ;; fissure155 0xE4 :TM28 ;; dig156 0xE5 :TM29 ;; psychic157 0xE6 :TM30 ;; teleport158 0xE7 :TM31 ;; mimic159 0xE8 :TM32 ;; double team160 0xE9 :TM33 ;; reflect161 0xEA :TM34 ;; bide162 0xEB :TM35 ;; metronome163 0xEC :TM36 ;; self destruct164 0xED :TM37 ;; egg bomb165 0xEE :TM38 ;; fire blast166 0xEF :TM39 ;; swift167 0xF0 :TM40 ;; skull bash168 0xF1 :TM41 ;; softboiled169 0xF2 :TM42 ;; dream eater170 0xF3 :TM43 ;; sky attack171 0xF4 :TM44 ;; rest172 0xF5 :TM45 ;; thunder wave173 0xF6 :TM46 ;; psywave174 0xF7 :TM47 ;; explosion175 0xF8 :TM48 ;; rock slide176 0xF9 :TM49 ;; tri attack177 0xFA :TM50 ;; substitute178 0xFB :TM51 ;; "cut"179 0xFC :TM52 ;; "fly"180 0xFD :TM53 ;; "surf"181 0xFE :TM54 ;; "strength"182 0xFF :TM55 ;; "flash" (also end-of-list-sentinel)183 ))185 (def item-name->item-code186 (zipmap (vals item-code->item-name)187 (keys item-code->item-name)))189 (defn raw-inventory->inventory190 [raw-inventory]191 (map192 (fn [[item-code quantity]]193 [(item-code->item-name194 item-code195 item-code)196 quantity])197 (partition198 2199 raw-inventory)))201 (defn total-held-items [state]202 (aget (memory state) item-list-start))204 (defn inventory205 ([^SaveState state]206 (let [items (item-list state)]207 (raw-inventory->inventory208 (take (* 2 (total-held-items state)) (next items)))))209 ([] (inventory @current-state)))211 (defn print-inventory212 ([] (print-inventory @current-state))213 ([^SaveState state]214 (println215 (let [inv (inventory state)]216 (reduce217 str218 (concat219 ["+-------------------+----------+\n"220 "|##| Item | Quantity |\n"221 "+--+----------------+----------+\n"]223 (map224 (fn [index [item-name quantity]]225 (str226 (format "|%-2d| %-14s | %3d |\n" index227 (apply str (rest (str item-name)))228 quantity)))229 (range 0 (count inv)) inv)230 ["+--+----------------+----------+\n"]))))231 state))233 (defn inventory-codes [inventory]234 (flatten235 (concat [(count inventory)]236 (map (fn [[item-name quantity]]237 [(item-name->item-code item-name item-name)238 quantity]) inventory)239 [(item-name->item-code :TM55)])))241 (defn set-inv-mem [^SaveState state inv-codes]242 (set-memory-range state item-list-start243 inv-codes))246 (defn set-inventory [^SaveState state new-inventory]247 (set-inv-mem state (inventory-codes new-inventory)))249 (defn give-items250 ([^SaveState state items]251 (set-inventory state252 (concat items (inventory state))))253 ([items]254 (give-items @current-state items)))256 (defn clear-inventory257 ([^SaveState state]258 (set-inventory state []))259 ([] (clear-inventory @current-state)))