view clojure/com/aurellem/exp/moves.clj @ 161:cd7979aa544e

emabled setting pokemon moves and PP
author Robert McIntyre <rlm@mit.edu>
date Tue, 20 Mar 2012 17:13:12 -0500
parents d92f7d68445a
children 34b518fc7404
line wrap: on
line source
1 (ns com.aurellem.exp.moves
2 (:use (com.aurellem.gb gb-driver items util pokemon))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (defn move-state []
6 (read-state "view-pika-attacks"))
8 (defn view-move [n]
9 (run-moves
10 (set-memory (move-state) 0xD19E n)
11 (concat [[:a]]
12 (repeat 200 [])
13 [[:a]]
14 (repeat 200 []))))
16 (defn iterate-moves []
17 (dorun
18 (map (fn [n] (println n)
19 (view-move n)
20 (Thread/sleep 5000))
21 (range (inc 0xFF)))))
23 (def moves-codes-pokemon-1 0xD172)
25 (defn moves-codes-start [pokemon-num]
26 (assert (<= 0 pokemon-num 5))
27 (+ moves-codes-pokemon-1
28 (* pokemon-num pokemon-record-width)))
31 ;; 000 00 : null
32 ;; 001 01 : pound
33 ;; 002 02 : karate-chop
34 ;; 003 03 : doubleslap
35 ;; 004 04 : comet-punch
36 ;; 005 05 : mega-punch
37 ;; 006 06 : pay-day
38 ;; 007 07 : fire-punch
39 ;; 008 08 : ice-punch
40 ;; 009 09 : thunderpunch
41 ;; 010 0A : scratch
42 ;; 011 0B : vicegrip
43 ;; 012 0C : guillotine
44 ;; 013 0D : razor-wind
45 ;; 014 0E : swords-dance
46 ;; 015 0F : cut
47 ;; 016 10 : gust
48 ;; 017 11 : wing-attack
49 ;; 018 12 : whirlwind
50 ;; 019 13 : fly
51 ;; 020 14 : bind
52 ;; 021 15 : slam
53 ;; 022 16 : vine-whip
54 ;; 023 17 : stomp
55 ;; 024 18 : double-kick
56 ;; 025 19 : mega-kick
57 ;; 026 1A : jump-kick
58 ;; 027 1B : rolling-kick
59 ;; 028 1C : sand-attack
60 ;; 029 1D : headbutt
61 ;; 030 1E : horn-attack
62 ;; 031 1F : fury-attack
63 ;; 032 20 : horn-drill
64 ;; 033 21 : tackle
65 ;; 034 22 : body-slam
66 ;; 035 23 : wrap
67 ;; 036 24 : take-down
68 ;; 037 25 : thrash
69 ;; 038 26 : double-edge
70 ;; 039 27 : tail-whip
71 ;; 040 28 : poison-sting
72 ;; 041 29 : twinneedle
73 ;; 042 2A : pin-missle
74 ;; 043 2B : leer
75 ;; 044 2C : bite
76 ;; 045 2D : growl
77 ;; 046 2E : roar
78 ;; 047 2F : sing
79 ;; 048 30 : supersonic
80 ;; 049 31 : sonicboom
81 ;; 050 32 : disable
82 ;; 051 33 : acid
83 ;; 052 34 : ember
84 ;; 053 35 : flamethrower
85 ;; 054 36 : mist
86 ;; 055 37 : water-gun
87 ;; 056 38 : hydro-pump
88 ;; 057 39 : surf
89 ;; 058 3A : ice-beam
90 ;; 059 3B : blizzard
91 ;; 060 3C : psybeam
92 ;; 061 3D : bubblebeam
93 ;; 062 3E : aurora-beam
94 ;; 063 3F : hyper-beam
95 ;; 064 40 : peck
96 ;; 065 41 : drill-peck
97 ;; 066 42 : submission
98 ;; 067 43 : low-kick
99 ;; 068 44 : counter
100 ;; 069 45 : seismic-toss
101 ;; 070 46 : strength
102 ;; 071 47 : absorb
103 ;; 072 48 : mega-drain
104 ;; 073 49 : leech-seed
105 ;; 074 4A : growth
106 ;; 075 4B : razor-leaf
107 ;; 076 4C : solarbeam
108 ;; 077 4D : poisonpowder
109 ;; 078 4E : stun-spore
110 ;; 079 4F : sleep-powder
111 ;; 080 50 : petal-dance
112 ;; 081 51 : string-shot
113 ;; 082 52 : dragon-rage
114 ;; 083 53 : fire-spin
115 ;; 084 54 : thundershock
116 ;; 085 55 : thunderbolt
117 ;; 086 56 : thunder-wave
118 ;; 087 57 : thunder
119 ;; 088 58 : rock-throw
120 ;; 089 59 : earthquake
121 ;; 090 5A : fissure
122 ;; 091 5B : dig
123 ;; 092 5C : toxic
124 ;; 093 5D : confusion
125 ;; 094 5E : psychic
126 ;; 095 5F : hypnosis
127 ;; 096 60 : meditate
128 ;; 097 61 : agility
129 ;; 098 62 : quick-attack
130 ;; 099 63 : rage
131 ;; 100 64 : teleport
132 ;; 101 65 : night-shade
133 ;; 102 66 : mimic
134 ;; 103 67 : screech
135 ;; 104 68 : double-team
136 ;; 105 69 : recover
137 ;; 106 6A : harden
138 ;; 107 6B : minimize
139 ;; 108 6C : smokescreen
140 ;; 109 6D : confuse-ray
141 ;; 110 6E : withdraw
142 ;; 111 6F : defense-curl
143 ;; 112 70 : barrier
144 ;; 113 71 : light-screen
145 ;; 114 72 : haze
146 ;; 115 73 : reflect
147 ;; 116 74 : focus-energy
148 ;; 117 75 : bide
149 ;; 118 76 : metronome
150 ;; 119 77 : mirror-move
151 ;; 120 78 : selfdestruct
152 ;; 121 79 : egg-bomb
153 ;; 122 7A : lick
154 ;; 123 7B : smog
155 ;; 124 7C : sludge
156 ;; 125 7D : bone-club
157 ;; 126 7E : fire-blast
158 ;; 127 7F : waterfall
159 ;; 128 80 : clamp
160 ;; 129 81 : swift
161 ;; 130 82 : skull-bash
162 ;; 131 83 : spike-cannon
163 ;; 132 84 : constrict
164 ;; 133 85 : amnesia
165 ;; 134 86 : kinesis
166 ;; 135 87 : softboiled
167 ;; 136 88 : hi-jump-kick
168 ;; 137 89 : glare
169 ;; 138 8A : dream-eater
170 ;; 139 8B : poison-gas
171 ;; 140 8C : barrage
172 ;; 141 8D : leech-life
173 ;; 142 8E : lovely-kiss
174 ;; 143 8F : sky-attack
175 ;; 144 90 : transform
176 ;; 145 91 : bubble
177 ;; 146 92 : dizzy-punch
178 ;; 147 93 : spore
179 ;; 148 94 : flash
180 ;; 149 95 : psywave
181 ;; 150 96 : splash
182 ;; 151 97 : acid-armor
183 ;; 152 98 : crabhammer
184 ;; 153 99 : explosion
185 ;; 154 9A : fury-swipes
186 ;; 155 9B : bonemerang
187 ;; 156 9C : rest
188 ;; 157 9D : rock-slide
189 ;; 158 9E : hyper-fang
190 ;; 159 9F : sharpen
191 ;; 160 A0 : conversion
192 ;; 161 A1 : tri-attack
193 ;; 162 A2 : super-fang
194 ;; 163 A3 : slash
195 ;; 164 A4 : substitute
196 ;; 165 A5 : struggle
197 ;; 166 A6 : null
198 ;; 167 A7 : null
199 ;; 168 A8 : null
200 ;; 169 A9 : trash
201 ;; 170 AA : trash
202 ;; 171 AB : trash
203 ;; 172 AC : trash
204 ;; 173 AD : trash
205 ;; 174 AE : trash
206 ;; 175 AF : null
207 ;; 176 B0 : trash
208 ;; 177 B1 : trash
209 ;; 178 B2 : trash
210 ;; 179 B3 : trash
211 ;; 180 B4 : AA
212 ;; 181 B5 : trash
213 ;; 182 B6 : QQ
214 ;; 183 B7 : null
215 ;; 184 B8 : null
216 ;; 185 B9 : null
217 ;; 186 BA : null
218 ;; 187 BB : null
219 ;; 188 BC : null
220 ;; 189 BD : null
221 ;; 190 BE : trash
222 ;; 191 BF : null
223 ;; 192 C0 : null
224 ;; 193 C1 : null
225 ;; 194 C2 : null
226 ;; 195 C3 : null
227 ;; 196 C4 : HM01
228 ;; 197 C5 : HM02
229 ;; 198 C6 : HM03
230 ;; 199 C7 : HM04
231 ;; 200 C8 : HM05
232 ;; 201 C9 : TM01
233 ;; 202 CA : TM02
234 ;; 203 CB : TM03
235 ;; 204 CC : TM04
236 ;; 205 CD : TM05
237 ;; 206 CE : TM06
238 ;; 207 CF : TM07
239 ;; 208 D0 : TM08
240 ;; 209 D1 : TM09
241 ;; 210 D2 : TM10
242 ;; 211 D3 : TM11
243 ;; 212 D4 : TM12
244 ;; 213 D5 : TM13
245 ;; 214 D6 : TM14
246 ;; 215 D7 : TM15
247 ;; 216 D8 : TM16
248 ;; 217 D9 : TM17
249 ;; 218 DA : TM18
250 ;; 219 DB : TM19
251 ;; 220 DC : TM20
252 ;; 221 DD : TM21
253 ;; 222 DE : TM22
254 ;; 223 DF : TM23
255 ;; 224 E0 : TM24
256 ;; 225 E1 : TM25
257 ;; 226 E2 : TM26
258 ;; 227 E3 : TM27
259 ;; 228 E4 : TM28
260 ;; 229 E5 : TM29
261 ;; 230 E6 : TM30
262 ;; 231 E7 : TM31
263 ;; 232 E8 : TM32
264 ;; 233 E9 : TM33
265 ;; 234 EA : TM34
266 ;; 235 EB : TM35
267 ;; 236 EC : TM36
268 ;; 237 ED : TM37
269 ;; 238 EE : TM38
270 ;; 239 EF : TM39
271 ;; 240 F0 : TM40
272 ;; 241 F1 : TM41
273 ;; 242 F2 : TM42
274 ;; 243 F3 : TM43
275 ;; 244 F4 : TM44
276 ;; 245 F5 : TM45
277 ;; 246 F6 : TM46
278 ;; 247 F7 : TM47
279 ;; 248 F8 : TM48
280 ;; 249 F9 : TM49
281 ;; 250 FA : TM50
282 ;; 251 FB : TM51
283 ;; 252 FC : TM52
284 ;; 253 FD : TM53
285 ;; 254 FE : TM54
286 ;; 255 FF : TM55
289 (def move-code->move-name
290 {
291 0x01 :pound
292 0x02 :karate-chop
293 0x03 :doubleslap
294 0x04 :comet-punch
295 0x05 :mega-punch
296 0x06 :pay-day
297 0x07 :fire-punch
298 0x08 :ice-punch
299 0x09 :thunderpunch
300 0x0A :scratch
301 0x0B :vicegrip
302 0x0C :guillotine
303 0x0D :razor-wind
304 0x0E :swords-dance
305 0x0F :cut
306 0x10 :gust
307 0x11 :wing-attack
308 0x12 :whirlwind
309 0x13 :fly
310 0x14 :bind
311 0x15 :slam
312 0x16 :vine-whip
313 0x17 :stomp
314 0x18 :double-kick
315 0x19 :mega-kick
316 0x1A :jump-kick
317 0x1B :rolling-kick
318 0x1C :sand-attack
319 0x1D :headbutt
320 0x1E :horn-attack
321 0x1F :fury-attack
322 0x20 :horn-drill
323 0x21 :tackle
324 0x22 :body-slam
325 0x23 :wrap
326 0x24 :take-down
327 0x25 :thrash
328 0x26 :double-edge
329 0x27 :tail-whip
330 0x28 :poison-sting
331 0x29 :twinneedle
332 0x2A :pin-missle
333 0x2B :leer
334 0x2C :bite
335 0x2D :growl
336 0x2E :roar
337 0x2F :sing
338 0x30 :supersonic
339 0x31 :sonicboom
340 0x32 :disable
341 0x33 :acid
342 0x34 :ember
343 0x35 :flamethrower
344 0x36 :mist
345 0x37 :water-gun
346 0x38 :hydro-pump
347 0x39 :surf
348 0x3A :ice-beam
349 0x3B :blizzard
350 0x3C :psybeam
351 0x3D :bubblebeam
352 0x3E :aurora-beam
353 0x3F :hyper-beam
354 0x40 :peck
355 0x41 :drill-peck
356 0x42 :submission
357 0x43 :low-kick
358 0x44 :counter
359 0x45 :seismic-toss
360 0x46 :strength
361 0x47 :absorb
362 0x48 :mega-drain
363 0x49 :leech-seed
364 0x4A :growth
365 0x4B :razor-leaf
366 0x4C :solarbeam
367 0x4D :poisonpowder
368 0x4E :stun-spore
369 0x4F :sleep-powder
370 0x50 :petal-dance
371 0x51 :string-shot
372 0x52 :dragon-rage
373 0x53 :fire-spin
374 0x54 :thundershock
375 0x55 :thunderbolt
376 0x56 :thunder-wave
377 0x57 :thunder
378 0x58 :rock-throw
379 0x59 :earthquake
380 0x5A :fissure
381 0x5B :dig
382 0x5C :toxic
383 0x5D :confusion
384 0x5E :psychic
385 0x5F :hypnosis
386 0x60 :meditate
387 0x61 :agility
388 0x62 :quick-attack
389 0x63 :rage
390 0x64 :teleport
391 0x65 :night-shade
392 0x66 :mimic
393 0x67 :screech
394 0x68 :double-team
395 0x69 :recover
396 0x6A :harden
397 0x6B :minimize
398 0x6C :smokescreen
399 0x6D :confuse-ray
400 0x6E :withdraw
401 0x6F :defense-curl
402 0x70 :barrier
403 0x71 :light-screen
404 0x72 :haze
405 0x73 :reflect
406 0x74 :focus-energy
407 0x75 :bide
408 0x76 :metronome
409 0x77 :mirror-move
410 0x78 :selfdestruct
411 0x79 :egg-bomb
412 0x7A :lick
413 0x7B :smog
414 0x7C :sludge
415 0x7D :bone-club
416 0x7E :fire-blast
417 0x7F :waterfall
418 0x80 :clamp
419 0x81 :swift
420 0x82 :skull-bash
421 0x83 :spike-cannon
422 0x84 :constrict
423 0x85 :amnesia
424 0x86 :kinesis
425 0x87 :softboiled
426 0x88 :hi-jump-kick
427 0x89 :glare
428 0x8A :dream-eater
429 0x8B :poison-gas
430 0x8C :barrage
431 0x8D :leech-life
432 0x8E :lovely-kiss
433 0x8F :sky-attack
434 0x90 :transform
435 0x91 :bubble
436 0x92 :dizzy-punch
437 0x93 :spore
438 0x94 :flash
439 0x95 :psywave
440 0x96 :splash
441 0x97 :acid-armor
442 0x98 :crabhammer
443 0x99 :explosion
444 0x9A :fury-swipes
445 0x9B :bonemerang
446 0x9C :rest
447 0x9D :rock-slide
448 0x9E :hyper-fang
449 0x9F :sharpen
450 0xA0 :conversion
451 0xA1 :tri-attack
452 0xA2 :super-fang
453 0xA3 :slash
454 0xA4 :substitute
455 0xA5 :struggle})
457 (def move-name->move-code
458 (zipmap (vals move-code->move-name)
459 (keys move-code->move-name)))
461 (defn give-moves
462 ([^SaveState state pokemon-num moves]
463 (set-memory-range
464 state
465 (moves-codes-start pokemon-num)
466 (map #(move-name->move-code % %) moves)))
467 ([pokemon-num moves]
468 (give-moves @current-state pokemon-num moves))
469 ([moves]
470 (give-moves 0 moves)))
472 ;; Note regarding PP of moves -- both the current PP and the
473 ;; total PP are stored in the same value.
474 ;; they are bit-packed, with the first 2 bits containing the
475 ;; number of pp-ups that have been applied, and the next
476 ;; six bits containing the current pp of the move.
477 ;; thus, a move can have up to 63 current pp and up to
478 ;; three pp-ups applied.
481 (def pokemon-1-pp-start 0xD187)
483 (defn moves-pp-start [pokemon-num]
484 (assert (<= 0 pokemon-num 5))
485 (+ pokemon-1-pp-start (* pokemon-num pokemon-record-width)))
487 (defn read-pp
488 ([^SaveState state pokemon-num move-num]
489 (assert (<= 0 move-num 3))
490 (assert (<= 0 pokemon-num 5))
491 (let [pp-raw
492 (aget (memory state)
493 (+ (moves-pp-start pokemon-num)
494 move-num))
495 pp-up
496 (bit-shift-right
497 (bit-and
498 pp-raw
499 (Integer/parseInt "11000000" 2)) 6)
500 current-pp
501 (bit-and
502 pp-raw
503 (Integer/parseInt "00111111" 2))]
504 [pp-up current-pp]))
505 ([pokemon-num move-num]
506 (read-pp @current-state pokemon-num move-num)))
508 (defn give-pp
509 ([^SaveState state pokemon-num move-num pp-ups current-pp]
510 (assert (<= 0 move-num 3))
511 (assert (<= 0 pokemon-num 5))
512 (assert (<= 0 pp-ups 3))
513 (assert (<= 0 current-pp 63))
515 (set-memory
516 state
517 (+ (moves-pp-start pokemon-num)
518 move-num)
519 (+
520 (bit-shift-left pp-ups 6)
521 (bit-and (Integer/parseInt
522 "00111111" 2)
523 current-pp))))
524 ([pokemon-num move-num pp-ups current-pp]
525 (set-pp @current-state
526 pokemon-num move-num pp-ups current-pp)))