Mercurial > vba-clojure
view clojure/com/aurellem/gb/items.clj @ 186:531e1342ff56
merged changes.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Thu, 22 Mar 2012 07:03:02 -0500 |
parents | c8ec477beeac f0c1e5574e81 |
children | 893c753f8088 |
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 0x07 :surfboard28 0x08 :safari-ball29 0x09 :pokedex30 0x0A :moon-stone31 0x0B :antidote32 0x0C :burn-heal33 0x0D :ice-heal34 0x0E :awakening35 0x0F :parlyz-heal36 0x10 :full-restore37 0x11 :max-potion38 0x12 :hyper-potion39 0x13 :super-potion40 0x14 :potion41 0x15 :boulderbadge42 0x16 :cascadebadge43 0x17 :thunderbadge44 0x18 :rainbowbadge45 0x19 :soulbadge46 0x1A :marshbadge47 0x1B :volcanobadge48 0x1C :earthbadge49 0x1D :escape-rope50 0x1E :repel51 0x1F :old-amber52 0x20 :fire-stone53 0x21 :thunderstone54 0x22 :water-stone55 0x23 :hp-up56 0x24 :protein57 0x25 :iron58 0x26 :carbos59 0x27 :calcium60 0x28 :rare-candy61 0x29 :dome-fossil62 0x2A :helix-fossil63 0x2B :secret-key64 0x2D :bike-voucher65 0x2E :x-accuracy66 0x2F :leaf-stone67 0x30 :card-key68 0x31 :nugget69 0x32 :pp-up70 0x33 :poke-doll71 0x34 :full-heal72 0x35 :revive73 0x36 :max-revive74 0x37 :guard-spec75 0x38 :super-repel76 0x39 :max-repel77 0x3A :dire-hit78 0x3B :coin79 0x3C :fresh-water80 0x3D :soda-pop81 0x3E :lemonade82 0x3F :s.s.ticket83 0x40 :gold-teeth84 0x41 :x-attack85 0x42 :x-defend86 0x43 :x-speed87 0x44 :x-special88 0x45 :coin-case89 0x46 :oaks-parcel90 0x47 :itemfinder91 0x48 :silph-scope92 0x49 :poke-flute93 0x4A :lift-key94 0x4B :exp.all95 0x4C :old-rod96 0x4D :good-rod97 0x4E :super-rod98 0x4F :pp-up99 0x50 :ether100 0x51 :max-ether101 0x52 :elixer102 0x53 :max-elixer103 0xC4 :HM01 ;; cut104 0xC5 :HM02 ;; fly105 0xC6 :HM03 ;; surf106 0xC7 :HM04 ;; strength107 0xC8 :HM05 ;; flash108 0xC9 :TM01 ;; mega punch109 0xCA :TM02 ;; razor wind110 0xCB :TM03 ;; swords dance111 0xCC :TM04 ;; whirlwind112 0xCD :TM05 ;; mega kick113 0xCE :TM06 ;; toxic114 0xCF :TM07 ;; horn drill115 0xD0 :TM08 ;; body slam116 0xD1 :TM09 ;; take down117 0xD2 :TM10 ;; double-edge118 0xD3 :TM11 ;; bubblebeam119 0xD4 :TM12 ;; water gun120 0xD5 :TM13 ;; ice beam121 0xD6 :TM14 ;; blizzard122 0xD7 :TM15 ;; hyper beam123 0xD8 :TM16 ;; pay day124 0xD9 :TM17 ;; submission125 0xDA :TM18 ;; counter126 0xDB :TM19 ;; seismic toss127 0xDC :TM20 ;; rage128 0xDD :TM21 ;; mega drain129 0xDE :TM22 ;; solarbeam130 0xDF :TM23 ;; dragon rage131 0xE0 :TM24 ;; thunderbolt132 0xE1 :TM25 ;; thunder133 0xE2 :TM26 ;; earthquake134 0xE3 :TM27 ;; fissure135 0xE4 :TM28 ;; dig136 0xE5 :TM29 ;; psychic137 0xE6 :TM30 ;; teleport138 0xE7 :TM31 ;; mimic139 0xE8 :TM32 ;; double team140 0xE9 :TM33 ;; reflect141 0xEA :TM34 ;; bide142 0xEB :TM35 ;; metronome143 0xEC :TM36 ;; self destruct144 0xED :TM37 ;; eggbomb145 0xEE :TM38 ;; fire blast146 0xEF :TM39 ;; swift147 0xF0 :TM40 ;; skull bash148 0xF1 :TM41 ;; softboiled149 0xF2 :TM42 ;; dream eater150 0xF3 :TM43 ;; sky attack151 0xF4 :TM44 ;; rest152 0xF5 :TM45 ;; thunder wave153 0xF6 :TM46 ;; psywave154 0xF7 :TM47 ;; explosion155 0xF8 :TM48 ;; rock slide156 0xF9 :TM49 ;; tri attack157 0xFA :TM50 ;; substitute158 0xFB :TM51 ;; "cut"159 0xFC :TM52 ;; "fly"160 0xFD :TM53 ;; "surf"161 0xFE :TM54 ;; "strength"162 0xFF :end-of-list-sentinel ;; also "flash"163 ))165 (def item-name->item-code166 (zipmap (vals item-code->item-name)167 (keys item-code->item-name)))169 (defn inventory [^SaveState state]170 (let [items (item-list state)]171 (map172 (fn [[item-code quantity]]173 [(item-code->item-name174 item-code175 item-code)176 quantity])177 (partition178 2179 (next (take-while (partial not= 255) items))))))181 (defn print-inventory182 ([] (print-inventory @current-state))183 ([^SaveState state]184 (println185 (let [inv (inventory state)]186 (reduce187 str188 (concat189 ["+-------------------+----------+\n"190 "|##| Item | Quantity |\n"191 "+--+----------------+----------+\n"]193 (map194 (fn [index [item-name quantity]]195 (str196 (format "|%-2d| %-14s | %3d |\n" index197 (apply str (rest (str item-name)))198 quantity)))199 (range 0 (count inv)) inv)200 ["+--+----------------+----------+\n"]))))201 state))203 (defn inventory-codes [inventory]204 (flatten205 (concat [(count inventory)]206 (map (fn [[item-name quantity]]207 [(item-name->item-code item-name item-name)208 quantity]) inventory)209 [(item-name->item-code :end-of-list-sentinel)])))211 (defn set-inv-mem [^SaveState state inv-codes]212 (set-memory-range state item-list-start213 inv-codes))216 (defn set-inventory [^SaveState state new-inventory]217 (set-inv-mem state (inventory-codes new-inventory)))219 (defn give-items220 ([^SaveState state items]221 (set-inventory state222 (concat items (inventory state))))223 ([items]224 (give-items @current-state items)))226 (defn clear-inventory227 ([^SaveState state]228 (set-inventory state []))229 ([] (clear-inventory @current-state)))