view clojure/com/aurellem/items.clj @ 101:37711ff4a7bc

filled out functions for the rest of the registers.
author Robert McIntyre <rlm@mit.edu>
date Mon, 12 Mar 2012 12:41:55 -0500
parents 2090bcb78f44
children 4d9ce3188655
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 1 :master-ball
22 2 :ultra-ball
23 3 :great-ball
24 4 :poke-ball
25 5 :town-map
26 6 :bicycle
27 8 :safari-ball
28 9 :pokedex
29 10 :moon-stone
30 11 :antidote
31 12 :burn-heal
32 13 :ice-heal
33 14 :awakening
34 15 :parlyz-heal
35 16 :full-restore
36 17 :max-potion
37 18 :hyper-potion
38 19 :super-potion
39 20 :potion
40 21 :boulderbadge
41 22 :cascadebadge
42 23 :thunderbadge
43 24 :rainbowbadge
44 25 :soulbadge
45 26 :marshbadge
46 27 :volcanobadge
47 28 :earthbadge
48 29 :escape-rope
49 30 :repel
50 31 :old-amber
51 32 :fire-stone
52 33 :thunderstone
53 34 :water-stone
54 35 :hp-up
55 36 :protein
56 37 :iron
57 38 :carbos
58 39 :calcium
59 40 :rare-candy
60 41 :dome-fossil
61 42 :helix-fossil
62 43 :secret-key
63 45 :bike-voucher
64 46 :x-accuracy
65 47 :leaf-stone
66 48 :card-key
67 49 :nugget
68 50 :pp-up
69 51 :poke-doll
70 52 :full-heal
71 53 :revive
72 54 :max-revive
73 55 :guard-spec
74 56 :super-repel
75 57 :max-repel
76 58 :dire-hit
77 59 :coin
78 60 :fresh-water
79 61 :soda-pop
80 62 :lemonade
81 63 :s.s.ticket
82 64 :gold-teeth
83 65 :x-attach
84 66 :x-defend
85 67 :x-speed
86 68 :x-special
87 69 :coin-case
88 70 :oaks-parcel
89 71 :itemfinder
90 72 :silph-scope
91 73 :poke-flute
92 74 :lift-key
93 75 :exp.all
94 76 :old-rod
95 77 :good-rod
96 78 :super-rod
97 79 :pp-up
98 80 :ether
99 81 :max-ether
100 82 :elixer
101 83 :max-elixer
102 196 :HM01
103 197 :HM02
104 198 :HM03
105 199 :HM04
106 200 :HM05
107 201 :TM01
108 202 :TM02
109 203 :TM03
110 204 :TM04
111 205 :TM05
112 206 :TM06
113 207 :TM07
114 208 :TM08
115 209 :TM09
116 210 :TM10
117 211 :TM11
118 212 :TM12
119 213 :TM13
120 214 :TM13
121 215 :TM15
122 216 :TM16
123 217 :TM17
124 218 :TM18
125 219 :TM19
126 220 :TM20
127 221 :TM21
128 222 :TM22
129 223 :TM23
130 224 :TM24
131 225 :TM25
132 226 :TM26
133 227 :TM27
134 228 :TM28
135 229 :TM29
136 230 :TM30
137 231 :TM31
138 232 :TM32
139 233 :TM33
140 234 :TM34
141 235 :TM35
142 236 :TM36
143 237 :TM37
144 238 :TM38
145 239 :TM39
146 240 :TM40
147 241 :TM41
148 242 :TM42
149 243 :TM43
150 244 :TM44
151 245 :TM45
152 246 :TM46
153 247 :TM47
154 248 :TM48
155 249 :TM49
156 250 :TM50
157 251 :TM51
158 252 :TM52
159 253 :TM53
160 254 :TM54
161 255 :end-of-list-sentinel))
163 (def item-name->item-code
164 (zipmap (vals item-code->item-name)
165 (keys item-code->item-name)))
167 (defn inventory [^SaveState state]
168 (let [items (item-list state)]
169 (map
170 (fn [[item-code quantity]]
171 [(item-code->item-name item-code)
172 quantity])
173 (partition
174 2
175 (next (take-while (partial not= 255) items))))))
177 (defn print-inventory [^SaveState state]
178 (println
179 (let [inv (inventory state)]
180 (reduce
181 str
182 (concat
183 ["+-------------------+----------+\n"
184 "|##| Item | Quantity |\n"
185 "+--+----------------+----------+\n"]
187 (map
188 (fn [index [item-name quantity]]
189 (str
190 (format "|%-2d| %-14s | %3d |\n" index
191 (apply str (rest (str item-name)))
192 quantity)))
193 (range 0 (count inv)) inv)
194 ["+--+----------------+----------+\n"])))))
196 (defn inventory-codes [inventory]
197 (flatten
198 (concat [(count inventory)]
199 (map (fn [[item-name quantity]]
200 [(item-name->item-code item-name)
201 quantity]) inventory)
202 [(item-name->item-code :end-of-list-sentinel)])))
204 (defn set-inventory [^SaveState state new-inventory]
205 (set-state! state)
206 (let [mem (memory state)
207 inv (inventory-codes new-inventory)]
209 (dorun (map (fn [index val]
210 (aset mem index val))
211 (range item-list-start
212 (+ item-list-start (count inv))) inv))
213 (write-memory! mem)
214 (update-state)))