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