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.items
2 (:use (com.aurellem gb-driver vbm title))
3 ;; this is bullshit
4 (: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 (subvec
13 (vec (memory state))
14 item-list-start
15 (+ item-list-start 150)))
17 (def item-hack-3 (read-state 77557))
19 (def item-code->item-name
20 (hash-map
21 0x01 :master-ball
22 0x02 :ultra-ball
23 0x03 :great-ball
24 0x04 :poke-ball
25 0x05 :town-map
26 0x06 :bicycle
27 0x08 :safari-ball
28 0x09 :pokedex
29 0x0A :moon-stone
30 0x0B :antidote
31 0x0C :burn-heal
32 0x0D :ice-heal
33 0x0E :awakening
34 0x0F :parlyz-heal
35 0x10 :full-restore
36 0x11 :max-potion
37 0x12 :hyper-potion
38 0x13 :super-potion
39 0x14 :potion
40 0x15 :boulderbadge
41 0x16 :cascadebadge
42 0x17 :thunderbadge
43 0x18 :rainbowbadge
44 0x19 :soulbadge
45 0x1A :marshbadge
46 0x1B :volcanobadge
47 0x1C :earthbadge
48 0x1D :escape-rope
49 0x1E :repel
50 0x1F :old-amber
51 0x20 :fire-stone
52 0x21 :thunderstone
53 0x22 :water-stone
54 0x23 :hp-up
55 0x24 :protein
56 0x25 :iron
57 0x26 :carbos
58 0x27 :calcium
59 0x28 :rare-candy
60 0x29 :dome-fossil
61 0x2A :helix-fossil
62 0x2B :secret-key
63 0x2D :bike-voucher
64 0x2E :x-accuracy
65 0x2F :leaf-stone
66 0x30 :card-key
67 0x31 :nugget
68 0x32 :pp-up
69 0x33 :poke-doll
70 0x34 :full-heal
71 0x35 :revive
72 0x36 :max-revive
73 0x37 :guard-spec
74 0x38 :super-repel
75 0x39 :max-repel
76 0x3A :dire-hit
77 0x3B :coin
78 0x3C :fresh-water
79 0x3D :soda-pop
80 0x3E :lemonade
81 0x3F :s.s.ticket
82 0x40 :gold-teeth
83 0x41 :x-attach
84 0x42 :x-defend
85 0x43 :x-speed
86 0x44 :x-special
87 0x45 :coin-case
88 0x46 :oaks-parcel
89 0x47 :itemfinder
90 0x48 :silph-scope
91 0x49 :poke-flute
92 0x4A :lift-key
93 0x4B :exp.all
94 0x4C :old-rod
95 0x4D :good-rod
96 0x4E :super-rod
97 0x4F :pp-up
98 0x50 :ether
99 0x51 :max-ether
100 0x52 :elixer
101 0x53 :max-elixer
102 0xC4 :HM01 ;; cut
103 0xC5 :HM02 ;; fly
104 0xC6 :HM03 ;; surf
105 0xC7 :HM04 ;; strength
106 0xC8 :HM05 ;; flash
107 0xC9 :TM01 ;; mega punch
108 0xCA :TM02 ;; razor wind
109 0xCB :TM03 ;; swords dance
110 0xCC :TM04 ;; whirlwind
111 0xCD :TM05 ;; mega kick
112 0xCE :TM06 ;; toxic
113 0xCF :TM07 ;; horn drill
114 0xD0 :TM08 ;; body slam
115 0xD1 :TM09 ;; take down
116 0xD2 :TM10 ;; double-edge
117 0xD3 :TM11 ;; bubblebeam
118 0xD4 :TM12 ;; water gun
119 0xD5 :TM13 ;; ice beam
120 0xD6 :TM14 ;; blizzard
121 0xD7 :TM15 ;; hyper beam
122 0xD8 :TM16 ;; pay day
123 0xD9 :TM17 ;; submission
124 0xDA :TM18 ;; counter
125 0xDB :TM19 ;; seismic toss
126 0xDC :TM20 ;; rage
127 0xDD :TM21 ;; mega drain
128 0xDE :TM22 ;; solarbeam
129 0xDF :TM23 ;; dragon rage
130 0xE0 :TM24 ;; thunderbolt
131 0xE1 :TM25 ;; thunder
132 0xE2 :TM26 ;; earthquake
133 0xE3 :TM27 ;; fissure
134 0xE4 :TM28 ;; dig
135 0xE5 :TM29 ;; psychic
136 0xE6 :TM30 ;; teleport
137 0xE7 :TM31 ;; mimic
138 0xE8 :TM32 ;; double team
139 0xE9 :TM33 ;; reflect
140 0xEA :TM34 ;; bide
141 0xEB :TM35 ;; metronome
142 0xEC :TM36 ;; self destruct
143 0xED :TM37 ;; eggbomb
144 0xEE :TM38 ;; fire blast
145 0xEF :TM39 ;; swift
146 0xF0 :TM40 ;; skull bash
147 0xF1 :TM41 ;; softboiled
148 0xF2 :TM42 ;; dream eater
149 0xF3 :TM43 ;; sky attack
150 0xF4 :TM44 ;; rest
151 0xF5 :TM45 ;; thunder wave
152 0xF6 :TM46 ;; psywave
153 0xF7 :TM47 ;; explosion
154 0xF8 :TM48 ;; rock slide
155 0xF9 :TM49 ;; tri attack
156 0xFA :TM50 ;; substitute
157 0xFB :TM51 ;; "cut"
158 0xFC :TM52 ;; "fly"
159 0xFD :TM53 ;; "surf"
160 0xFE :TM54 ;; "strength"
161 0xFF :end-of-list-sentinel
162 ))
164 (def item-name->item-code
165 (zipmap (vals item-code->item-name)
166 (keys item-code->item-name)))
168 (defn inventory [^SaveState state]
169 (let [items (item-list state)]
170 (map
171 (fn [[item-code quantity]]
172 [(item-code->item-name
173 item-code
174 (str ":0x" (.toUpperCase (Integer/toHexString item-code))))
175 quantity])
176 (partition
177 2
178 (next (take-while (partial not= 255) items))))))
180 (defn print-inventory
181 ([] (print-inventory @current-state))
182 ([^SaveState state]
183 (println
184 (let [inv (inventory state)]
185 (reduce
186 str
187 (concat
188 ["+-------------------+----------+\n"
189 "|##| Item | Quantity |\n"
190 "+--+----------------+----------+\n"]
192 (map
193 (fn [index [item-name quantity]]
194 (str
195 (format "|%-2d| %-14s | %3d |\n" index
196 (apply str (rest (str item-name)))
197 quantity)))
198 (range 0 (count inv)) inv)
199 ["+--+----------------+----------+\n"]))))
200 state))
202 (defn inventory-codes [inventory]
203 (flatten
204 (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-start
216 (+ 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-start
229 (+ item-list-start (count inv))) inv))
230 (write-memory! mem)
231 (update-state)))
233 (defn give
234 ([^SaveState state items]
235 (set-inventory state
236 (concat items (inventory state))))
237 ([items]
238 (give @current-state items)))
240 (defn clear-inventory
241 ([^SaveState state]
242 (set-inventory state []))
243 ([] (clear-inventory @current-state)))
245 (def gliched-tms
246 [[:TM51 1]
247 [:TM52 1]
248 [:TM53 1]
249 [:TM54 1]])
251 (def good-items
252 [[: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-badges
266 [[:cascadebadge 1]
267 [:thunderbadge 1]
268 [:rainbowbadge 1]
269 [:soulbadge 1]
270 ])