Mercurial > vba-clojure
view clojure/com/aurellem/items.clj @ 118:be4ec0e60c16
mode 0 of bootstrapping state machine complete
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 16 Mar 2012 20:03:10 -0500 |
parents | ad96e9464d6a |
children |
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-code->item-name18 (hash-map19 0x01 :master-ball20 0x02 :ultra-ball21 0x03 :great-ball22 0x04 :poke-ball23 0x05 :town-map24 0x06 :bicycle25 0x08 :safari-ball26 0x09 :pokedex27 0x0A :moon-stone28 0x0B :antidote29 0x0C :burn-heal30 0x0D :ice-heal31 0x0E :awakening32 0x0F :parlyz-heal33 0x10 :full-restore34 0x11 :max-potion35 0x12 :hyper-potion36 0x13 :super-potion37 0x14 :potion38 0x15 :boulderbadge39 0x16 :cascadebadge40 0x17 :thunderbadge41 0x18 :rainbowbadge42 0x19 :soulbadge43 0x1A :marshbadge44 0x1B :volcanobadge45 0x1C :earthbadge46 0x1D :escape-rope47 0x1E :repel48 0x1F :old-amber49 0x20 :fire-stone50 0x21 :thunderstone51 0x22 :water-stone52 0x23 :hp-up53 0x24 :protein54 0x25 :iron55 0x26 :carbos56 0x27 :calcium57 0x28 :rare-candy58 0x29 :dome-fossil59 0x2A :helix-fossil60 0x2B :secret-key61 0x2D :bike-voucher62 0x2E :x-accuracy63 0x2F :leaf-stone64 0x30 :card-key65 0x31 :nugget66 0x32 :pp-up67 0x33 :poke-doll68 0x34 :full-heal69 0x35 :revive70 0x36 :max-revive71 0x37 :guard-spec72 0x38 :super-repel73 0x39 :max-repel74 0x3A :dire-hit75 0x3B :coin76 0x3C :fresh-water77 0x3D :soda-pop78 0x3E :lemonade79 0x3F :s.s.ticket80 0x40 :gold-teeth81 0x41 :x-attach82 0x42 :x-defend83 0x43 :x-speed84 0x44 :x-special85 0x45 :coin-case86 0x46 :oaks-parcel87 0x47 :itemfinder88 0x48 :silph-scope89 0x49 :poke-flute90 0x4A :lift-key91 0x4B :exp.all92 0x4C :old-rod93 0x4D :good-rod94 0x4E :super-rod95 0x4F :pp-up96 0x50 :ether97 0x51 :max-ether98 0x52 :elixer99 0x53 :max-elixer100 0xC4 :HM01 ;; cut101 0xC5 :HM02 ;; fly102 0xC6 :HM03 ;; surf103 0xC7 :HM04 ;; strength104 0xC8 :HM05 ;; flash105 0xC9 :TM01 ;; mega punch106 0xCA :TM02 ;; razor wind107 0xCB :TM03 ;; swords dance108 0xCC :TM04 ;; whirlwind109 0xCD :TM05 ;; mega kick110 0xCE :TM06 ;; toxic111 0xCF :TM07 ;; horn drill112 0xD0 :TM08 ;; body slam113 0xD1 :TM09 ;; take down114 0xD2 :TM10 ;; double-edge115 0xD3 :TM11 ;; bubblebeam116 0xD4 :TM12 ;; water gun117 0xD5 :TM13 ;; ice beam118 0xD6 :TM14 ;; blizzard119 0xD7 :TM15 ;; hyper beam120 0xD8 :TM16 ;; pay day121 0xD9 :TM17 ;; submission122 0xDA :TM18 ;; counter123 0xDB :TM19 ;; seismic toss124 0xDC :TM20 ;; rage125 0xDD :TM21 ;; mega drain126 0xDE :TM22 ;; solarbeam127 0xDF :TM23 ;; dragon rage128 0xE0 :TM24 ;; thunderbolt129 0xE1 :TM25 ;; thunder130 0xE2 :TM26 ;; earthquake131 0xE3 :TM27 ;; fissure132 0xE4 :TM28 ;; dig133 0xE5 :TM29 ;; psychic134 0xE6 :TM30 ;; teleport135 0xE7 :TM31 ;; mimic136 0xE8 :TM32 ;; double team137 0xE9 :TM33 ;; reflect138 0xEA :TM34 ;; bide139 0xEB :TM35 ;; metronome140 0xEC :TM36 ;; self destruct141 0xED :TM37 ;; eggbomb142 0xEE :TM38 ;; fire blast143 0xEF :TM39 ;; swift144 0xF0 :TM40 ;; skull bash145 0xF1 :TM41 ;; softboiled146 0xF2 :TM42 ;; dream eater147 0xF3 :TM43 ;; sky attack148 0xF4 :TM44 ;; rest149 0xF5 :TM45 ;; thunder wave150 0xF6 :TM46 ;; psywave151 0xF7 :TM47 ;; explosion152 0xF8 :TM48 ;; rock slide153 0xF9 :TM49 ;; tri attack154 0xFA :TM50 ;; substitute155 0xFB :TM51 ;; "cut"156 0xFC :TM52 ;; "fly"157 0xFD :TM53 ;; "surf"158 0xFE :TM54 ;; "strength"159 0xFF :end-of-list-sentinel))161 (def item-name->item-code162 (zipmap (vals item-code->item-name)163 (keys item-code->item-name)))165 (defn inventory [^SaveState state]166 (let [items (item-list state)]167 (map168 (fn [[item-code quantity]]169 [(item-code->item-name170 item-code171 (str ":0x" (.toUpperCase (Integer/toHexString item-code))))172 quantity])173 (partition174 2175 (next (take-while (partial not= 255) items))))))177 (defn print-inventory178 ([] (print-inventory @current-state))179 ([^SaveState state]180 (println181 (let [inv (inventory state)]182 (reduce183 str184 (concat185 ["+-------------------+----------+\n"186 "|##| Item | Quantity |\n"187 "+--+----------------+----------+\n"]189 (map190 (fn [index [item-name quantity]]191 (str192 (format "|%-2d| %-14s | %3d |\n" index193 (apply str (rest (str item-name)))194 quantity)))195 (range 0 (count inv)) inv)196 ["+--+----------------+----------+\n"]))))197 state))199 (defn inventory-codes [inventory]200 (flatten201 (concat [(count inventory)]202 (map (fn [[item-name quantity]]203 [(item-name->item-code item-name)204 quantity]) inventory)205 [(item-name->item-code :end-of-list-sentinel)])))207 (defn set-inv-mem [^SaveState state inv-codes]208 (set-state! state)209 (let [mem (memory state)]210 (dorun (map (fn [index val]211 (aset mem index val))212 (range item-list-start213 (+ item-list-start (count inv-codes))) inv-codes))214 (write-memory! mem)215 (update-state)))218 (defn set-inventory [^SaveState state new-inventory]219 (set-state! state)220 (let [mem (memory state)221 inv (inventory-codes new-inventory)]223 (dorun (map (fn [index val]224 (aset mem index val))225 (range item-list-start226 (+ item-list-start (count inv))) inv))227 (write-memory! mem)228 (update-state)))230 (defn give231 ([^SaveState state items]232 (set-inventory state233 (concat items (inventory state))))234 ([items]235 (give @current-state items)))237 (defn clear-inventory238 ([^SaveState state]239 (set-inventory state []))240 ([] (clear-inventory @current-state)))242 (def gliched-tms243 [[:TM51 1]244 [:TM52 1]245 [:TM53 1]246 [:TM54 1]])248 (def good-items249 [[:bicycle 1]250 [:ultra-ball 15]251 [:pp-up 1]252 [:master-ball 5]253 [:rare-candy 99]254 [:full-restore 25]255 [:max-revive 8]256 [:max-repel 40]257 [:TM25 1]258 [:TM11 1]259 [:TM15 1]260 ])262 (def some-badges263 [[:cascadebadge 1]264 [:thunderbadge 1]265 [:rainbowbadge 1]266 [:soulbadge 1]267 ])