view clojure/com/aurellem/gb/moves.clj @ 197:659764a2ea40

break for eating!
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 00:14:37 -0500
parents fd549c8f42ae
children 5055ec9de278
line wrap: on
line source
1 (ns com.aurellem.gb.moves
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (def move-code->move-name
6 {
7 0x00 :end-of-moves
8 0x01 :pound
9 0x02 :karate-chop
10 0x03 :doubleslap
11 0x04 :comet-punch
12 0x05 :mega-punch
13 0x06 :pay-day
14 0x07 :fire-punch
15 0x08 :ice-punch
16 0x09 :thunderpunch
17 0x0A :scratch
18 0x0B :vicegrip
19 0x0C :guillotine
20 0x0D :razor-wind
21 0x0E :swords-dance
22 0x0F :cut
23 0x10 :gust
24 0x11 :wing-attack
25 0x12 :whirlwind
26 0x13 :fly
27 0x14 :bind
28 0x15 :slam
29 0x16 :vine-whip
30 0x17 :stomp
31 0x18 :double-kick
32 0x19 :mega-kick
33 0x1A :jump-kick
34 0x1B :rolling-kick
35 0x1C :sand-attack
36 0x1D :headbutt
37 0x1E :horn-attack
38 0x1F :fury-attack
39 0x20 :horn-drill
40 0x21 :tackle
41 0x22 :body-slam
42 0x23 :wrap
43 0x24 :take-down
44 0x25 :thrash
45 0x26 :double-edge
46 0x27 :tail-whip
47 0x28 :poison-sting
48 0x29 :twinneedle
49 0x2A :pin-missle
50 0x2B :leer
51 0x2C :bite
52 0x2D :growl
53 0x2E :roar
54 0x2F :sing
55 0x30 :supersonic
56 0x31 :sonicboom
57 0x32 :disable
58 0x33 :acid
59 0x34 :ember
60 0x35 :flamethrower
61 0x36 :mist
62 0x37 :water-gun
63 0x38 :hydro-pump
64 0x39 :surf
65 0x3A :ice-beam
66 0x3B :blizzard
67 0x3C :psybeam
68 0x3D :bubblebeam
69 0x3E :aurora-beam
70 0x3F :hyper-beam
71 0x40 :peck
72 0x41 :drill-peck
73 0x42 :submission
74 0x43 :low-kick
75 0x44 :counter
76 0x45 :seismic-toss
77 0x46 :strength
78 0x47 :absorb
79 0x48 :mega-drain
80 0x49 :leech-seed
81 0x4A :growth
82 0x4B :razor-leaf
83 0x4C :solarbeam
84 0x4D :poisonpowder
85 0x4E :stun-spore
86 0x4F :sleep-powder
87 0x50 :petal-dance
88 0x51 :string-shot
89 0x52 :dragon-rage
90 0x53 :fire-spin
91 0x54 :thundershock
92 0x55 :thunderbolt
93 0x56 :thunder-wave
94 0x57 :thunder
95 0x58 :rock-throw
96 0x59 :earthquake
97 0x5A :fissure
98 0x5B :dig
99 0x5C :toxic
100 0x5D :confusion
101 0x5E :psychic
102 0x5F :hypnosis
103 0x60 :meditate
104 0x61 :agility
105 0x62 :quick-attack
106 0x63 :rage
107 0x64 :teleport
108 0x65 :night-shade
109 0x66 :mimic
110 0x67 :screech
111 0x68 :double-team
112 0x69 :recover
113 0x6A :harden
114 0x6B :minimize
115 0x6C :smokescreen
116 0x6D :confuse-ray
117 0x6E :withdraw
118 0x6F :defense-curl
119 0x70 :barrier
120 0x71 :light-screen
121 0x72 :haze
122 0x73 :reflect
123 0x74 :focus-energy
124 0x75 :bide
125 0x76 :metronome
126 0x77 :mirror-move
127 0x78 :selfdestruct
128 0x79 :egg-bomb
129 0x7A :lick
130 0x7B :smog
131 0x7C :sludge
132 0x7D :bone-club
133 0x7E :fire-blast
134 0x7F :waterfall
135 0x80 :clamp
136 0x81 :swift
137 0x82 :skull-bash
138 0x83 :spike-cannon
139 0x84 :constrict
140 0x85 :amnesia
141 0x86 :kinesis
142 0x87 :softboiled
143 0x88 :hi-jump-kick
144 0x89 :glare
145 0x8A :dream-eater
146 0x8B :poison-gas
147 0x8C :barrage
148 0x8D :leech-life
149 0x8E :lovely-kiss
150 0x8F :sky-attack
151 0x90 :transform
152 0x91 :bubble
153 0x92 :dizzy-punch
154 0x93 :spore
155 0x94 :flash
156 0x95 :psywave
157 0x96 :splash
158 0x97 :acid-armor
159 0x98 :crabhammer
160 0x99 :explosion
161 0x9A :fury-swipes
162 0x9B :bonemerang
163 0x9C :rest
164 0x9D :rock-slide
165 0x9E :hyper-fang
166 0x9F :sharpen
167 0xA0 :conversion
168 0xA1 :tri-attack
169 0xA2 :super-fang
170 0xA3 :slash
171 0xA4 :substitute
172 0xA5 :struggle })
174 (def move-name->move-code
175 (zipmap (vals move-code->move-name)
176 (keys move-code->move-name)))
178 (def moves-codes-pokemon-1 0xD172)
180 (defn moves-codes-start [pokemon-num]
181 (assert (<= 0 pokemon-num 5))
182 (+ moves-codes-pokemon-1
183 (* pokemon-num pokemon-record-width)))
185 (defn read-moves
186 ([^SaveState state poke-num]
187 (let [start (moves-codes-start poke-num)]
188 (vec
189 (take-while
190 (partial not= :end-of-moves)
191 (map
192 move-code->move-name
193 (subvec (vec (memory state))
194 start (+ start 4)))))))
195 ([poke-num]
196 (read-moves @current-state poke-num)))
198 (defn give-moves
199 ([^SaveState state pokemon-num moves]
200 (assert (<= (count moves) 4))
201 (set-memory-range
202 state
203 (moves-codes-start pokemon-num)
204 (map #(move-name->move-code % %)
205 (concat moves
206 (repeat (- 4 (count moves)) :end-of-moves)))))
207 ([pokemon-num moves]
208 (give-moves @current-state pokemon-num moves))
209 ([moves]
210 (give-moves 0 moves)))
212 ;; Note regarding PP of moves -- both the current PP and the
213 ;; total PP are stored in the same value.
214 ;; they are bit-packed, with the first 2 bits containing the
215 ;; number of pp-ups that have been applied, and the next
216 ;; six bits containing the current pp of the move.
217 ;; thus, a move can have up to 63 current pp and up to
218 ;; three pp-ups applied.
220 (def pokemon-1-pp-start 0xD187)
222 (defn moves-pp-start [pokemon-num]
223 (assert (<= 0 pokemon-num 5))
224 (+ pokemon-1-pp-start (* pokemon-num pokemon-record-width)))
226 (defn read-pp
227 ([^SaveState state pokemon-num move-num]
228 (assert (<= 0 move-num 3))
229 (assert (<= 0 pokemon-num 5))
230 (let [pp-raw
231 (aget (memory state)
232 (+ (moves-pp-start pokemon-num)
233 move-num))
234 pp-up
235 (bit-shift-right
236 (bit-and
237 pp-raw
238 (Integer/parseInt "11000000" 2)) 6)
239 current-pp
240 (bit-and
241 pp-raw
242 (Integer/parseInt "00111111" 2))]
243 {:pp-ups pp-up :current-pp current-pp}))
244 ([pokemon-num move-num]
245 (read-pp @current-state pokemon-num move-num)))
247 (defn give-pp
248 ([^SaveState state pokemon-num move-num pp-ups current-pp]
249 (assert (<= 0 move-num 3))
250 (assert (<= 0 pokemon-num 5))
251 (assert (<= 0 pp-ups 3))
252 (assert (<= 0 current-pp 63))
254 (set-memory
255 state
256 (+ (moves-pp-start pokemon-num)
257 move-num)
258 (+
259 (bit-shift-left pp-ups 6)
260 (bit-and (Integer/parseInt
261 "00111111" 2)
262 current-pp))))
263 ([pokemon-num move-num pp-ups current-pp]
264 (give-pp @current-state
265 pokemon-num move-num pp-ups current-pp)))
268 (def move-name->move-pp
269 {
270 :absorb 20
271 :acid 30
272 :acid-armor 40 ;; WTF happens with 3 PP-UPs??!
273 :agility 30
274 :amnesia 20
275 :aurora-beam 20
276 :barrage 20
277 :barrier 30
278 :bide 10
279 :bind 20
280 :bite 25
281 :blizzard 5
282 :body-slam 15
283 :bone-club 20
284 :bonemerang 10
285 :bubble 30
286 :bubblebeam 20
287 :clamp 10
288 :comet-punch 15
289 :confuse-ray 10
290 :confusion 25
291 :constrict 35
292 :conversion 30
293 :counter 20
294 :crabhammer 10
295 :cut 30
296 :defense-curl 40
297 :dig 10
298 :disable 20
299 :dizzy-punch 10
300 :double-edge 15
301 :double-kick 30
302 :double-team 10
303 :doubleslap 15
304 :dragon-rage 10
305 :dream-eater 15
306 :drill-peck 20
307 :earthquake 10
308 :egg-bomb 10
309 :ember 25
310 :explosion 5
311 :fire-blast 5
312 :fire-punch 15
313 :fire-spin 15
314 :fissure 5
315 :flamethrower 15
316 :flash 20
317 :fly 15
318 :focus-energy 30
319 :fury-attack 20
320 :fury-swipes 15
321 :glare 30
322 :growl 40
323 :growth 40
324 :guillotine 5
325 :gust 35
326 :harden 30
327 :haze
328 :headbutt
329 :hi-jump-kick
330 :horn-attack
331 :horn-drill
332 :hydro-pump
333 :hyper-beam
334 :hyper-fang
335 :hypnosis
336 :ice-beam
337 :ice-punch
338 :jump-kick
339 :karate-chop
340 :kinesis
341 :leech-life
342 :leech-seed
343 :leer
344 :lick
345 :light-screen
346 :lovely-kiss
347 :low-kick
348 :meditate
349 :mega-drain
350 :mega-kick
351 :mega-punch
352 :metronome
353 :mimic
354 :minimize
355 :mirror-move
356 :mist
357 :night-shade
358 :pay-day
359 :peck
360 :petal-dance
361 :pin-missle
362 :poison-gas
363 :poison-sting
364 :poisonpowder
365 :pound
366 :psybeam
367 :psychic
368 :psywave
369 :quick-attack
370 :rage
371 :razor-leaf
372 :razor-wind
373 :recover
374 :reflect
375 :rest
376 :roar
377 :rock-slide
378 :rock-throw
379 :rolling-kick
380 :sand-attack
381 :scratch
382 :screech
383 :seismic-toss
384 :selfdestruct
385 :sharpen
386 :sing
387 :skull-bash
388 :sky-attack
389 :slam
390 :slash
391 :sleep-powder
392 :sludge
393 :smog
394 :smokescreen
395 :softboiled
396 :solarbeam
397 :sonicboom
398 :spike-cannon
399 :splash
400 :spore
401 :stomp
402 :strength
403 :string-shot
404 :struggle
405 :stun-spore
406 :submission
407 :substitute
408 :super-fang
409 :supersonic
410 :surf
411 :swift
412 :swords-dance
413 :tackle
414 :tail-whip
415 :take-down
416 :teleport
417 :thrash
418 :thunder
419 :thunder-wave
420 :thunderbolt
421 :thunderpunch
422 :thundershock
423 :toxic
424 :transform
425 :tri-attack
426 :twinneedle
427 :vicegrip
428 :vine-whip
429 :water-gun
430 :waterfall
431 :whirlwind
432 :wing-attack
433 :withdraw
434 :wrap