view clojure/com/aurellem/items.clj @ 107:ad96e9464d6a

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