view clojure/com/aurellem/gb/moves.clj @ 205:28d35c9e3ab6

default type list complete.
author Robert McIntyre <rlm@mit.edu>
date Fri, 23 Mar 2012 04:25:17 -0500
parents 5055ec9de278
children 912496041f98
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 30
328 :headbutt 15
329 :hi-jump-kick 20
330 :horn-attack 25
331 :horn-drill 5
332 :hydro-pump 5
333 :hyper-beam 5
334 :hyper-fang 15
335 :hypnosis 20
336 :ice-beam 10
337 :ice-punch 15
338 :jump-kick 25
339 :karate-chop 25
340 :kinesis 15
341 :leech-life 15
342 :leech-seed 10
343 :leer 30
344 :lick 30
345 :light-screen 30
346 :lovely-kiss 10
347 :low-kick 20
348 :meditate 40
349 :mega-drain 10
350 :mega-kick 5
351 :mega-punch 20
352 :metronome 10
353 :mimic 10
354 :minimize 20
355 :mirror-move 20
356 :mist 30
357 :night-shade 15
358 :pay-day 20
359 :peck 35
360 :petal-dance 20
361 :pin-missle 20
362 :poison-gas 40
363 :poison-sting 35
364 :poisonpowder 35
365 :pound 35
366 :psybeam 20
367 :psychic 10
368 :psywave 15
369 :quick-attack 30
370 :rage 20
371 :razor-leaf 25
372 :razor-wind 10
373 :recover 20
374 :reflect 20
375 :rest 10
376 :roar 20
377 :rock-slide 10
378 :rock-throw 15
379 :rolling-kick 15
380 :sand-attack 15
381 :scratch 30
382 :screech 40
383 :seismic-toss 20
384 :selfdestruct 5
385 :sharpen 30
386 :sing 15
387 :skull-bash 15
388 :sky-attack 5
389 :slam 20
390 :slash 20
391 :sleep-powder 15
392 :sludge 20
393 :smog 20
394 :smokescreen 20
395 :softboiled 10
396 :solarbeam 10
397 :sonicboom 20
398 :spike-cannon 15
399 :splash 40
400 :spore 15
401 :stomp 20
402 :strength 15
403 :string-shot 40
404 :struggle 1
405 :stun-spore 30
406 :submission 25
407 :substitute 10
408 :super-fang 10
409 :supersonic 20
410 :surf 15
411 :swift 20
412 :swords-dance 30
413 :tackle 35
414 :tail-whip 30
415 :take-down 20
416 :teleport 20
417 :thrash 20
418 :thunder 10
419 :thunder-wave 20
420 :thunderbolt 15
421 :thunderpunch 15
422 :thundershock 30
423 :toxic 10
424 :transform 10
425 :tri-attack 10
426 :twinneedle 20
427 :vicegrip 30
428 :vine-whip 10
429 :water-gun 25
430 :waterfall 15
431 :whirlwind 20
432 :wing-attack 35
433 :withdraw 40
434 :wrap 20})
436 (defn max-pp [name pp-ups]
437 (int (* (+ 1 (* (/ 1 5) pp-ups))
438 (move-name->move-pp name))))