Mercurial > vba-clojure
view clojure/com/aurellem/items.clj @ 106:3a60bb14a64a
better functional assembly interface; removed frame numbers from SaveStates
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 14 Mar 2012 21:37:37 -0500 |
parents | 2f8089eacab9 |
children | ad96e9464d6a |
line wrap: on
line source
1 (ns com.aurellem.items2 (:use (com.aurellem gb-driver vbm title))3 ;; this is bullshit4 (:import [com.aurellem.gb_driver SaveState]))6 (defn game-name []7 (map char (subvec (vec (memory)) 0x134 0x142)))9 (def item-list-start 0xD31C)11 (defn item-list [^SaveState state]12 (subvec13 (vec (memory state))14 item-list-start15 (+ item-list-start 150)))17 (def item-hack-3 (read-state 77557))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-attach84 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-sentinel162 ))164 (def item-name->item-code165 (zipmap (vals item-code->item-name)166 (keys item-code->item-name)))168 (defn inventory [^SaveState state]169 (let [items (item-list state)]170 (map171 (fn [[item-code quantity]]172 [(item-code->item-name173 item-code174 (str ":0x" (.toUpperCase (Integer/toHexString item-code))))175 quantity])176 (partition177 2178 (next (take-while (partial not= 255) items))))))180 (defn print-inventory181 ([] (print-inventory @current-state))182 ([^SaveState state]183 (println184 (let [inv (inventory state)]185 (reduce186 str187 (concat188 ["+-------------------+----------+\n"189 "|##| Item | Quantity |\n"190 "+--+----------------+----------+\n"]192 (map193 (fn [index [item-name quantity]]194 (str195 (format "|%-2d| %-14s | %3d |\n" index196 (apply str (rest (str item-name)))197 quantity)))198 (range 0 (count inv)) inv)199 ["+--+----------------+----------+\n"]))))200 state))202 (defn inventory-codes [inventory]203 (flatten204 (concat [(count inventory)]205 (map (fn [[item-name quantity]]206 [(item-name->item-code item-name)207 quantity]) inventory)208 [(item-name->item-code :end-of-list-sentinel)])))210 (defn set-inv-mem [^SaveState state inv-codes]211 (set-state! state)212 (let [mem (memory state)]213 (dorun (map (fn [index val]214 (aset mem index val))215 (range item-list-start216 (+ item-list-start (count inv-codes))) inv-codes))217 (write-memory! mem)218 (update-state)))221 (defn set-inventory [^SaveState state new-inventory]222 (set-state! state)223 (let [mem (memory state)224 inv (inventory-codes new-inventory)]226 (dorun (map (fn [index val]227 (aset mem index val))228 (range item-list-start229 (+ item-list-start (count inv))) inv))230 (write-memory! mem)231 (update-state)))233 (defn give234 ([^SaveState state items]235 (set-inventory state236 (concat items (inventory state))))237 ([items]238 (give @current-state items)))240 (defn clear-inventory241 ([^SaveState state]242 (set-inventory state []))243 ([] (clear-inventory @current-state)))245 (def gliched-tms246 [[:TM51 1]247 [:TM52 1]248 [:TM53 1]249 [:TM54 1]])251 (def good-items252 [[:bicycle 1]253 [:ultra-ball 15]254 [:pp-up 1]255 [:master-ball 5]256 [:rare-candy 99]257 [:full-restore 25]258 [:max-revive 8]259 [:max-repel 40]260 [:TM25 1]261 [:TM11 1]262 [:TM15 1]263 ])265 (def some-badges266 [[:cascadebadge 1]267 [:thunderbadge 1]268 [:rainbowbadge 1]269 [:soulbadge 1]270 ])